开源Nodejs项目推荐:无任何依赖的string操作库
strman是无任何依赖的string操作库,前后端通用
A Javascript string manipulation library without npm dependences.
安装
npm install strman --save
或者
bower install strman
用法
With ES6/import
import {slugify} from 'strman';
let title = "A Javascript string manipulation library.";
let result = slugify(title);
// result => "a-javascript-string-manipulation-library"
With require
var slugify = require('strman').slugify;
let title = "A Javascript string manipulation library.";
let result = slugify(title);
// result => "a-javascript-string-manipulation-library"
With Browser
<script src="./bower_components/strman/dist/strman.js"></script>
var result = _s.isString('strman');
// result => true
Also available for AMD
API
- [x] append
- [x] appendArray
- [x] at
- [x] between
- [x] chars
- [x] collapseWhitespace
- [x] contains
- [x] containsAll
- [x] containsAny
- [x] countSubstr
- [x] endsWith
- [x] ensureLeft
- [x] ensureRight
- [x] first
- [x] indexOf
- [x] insert
- [x] isLowerCase
- [x] isString
- [x] isUpperCase
- [x] last
- [x] lastIndexOf
- [x] leftPad
- [x] leftTrim
- [x] length
- [x] prepend
- [x] prependArray
- [x] removeLeft
- [x] removeNonChars
- [x] removeNonWords
- [x] removeRight
- [x] removeSpaces
- [x] repeat
- [x] replace
- [x] reverse
- [x] rightPad
- [x] rightTrim
- [x] safeTruncate
- [x] shuffle
- [x] slice
- [x] slugify
- [x] split
- [x] startsWith
- [x] substr
- [x] surround
- [x] toCamelCase
- [x] toDecamelize
- [x] toKebabCase
- [x] toLowerCase
- [x] toSnakeCase
- [x] toStudlyCaps
- [x] toUpperCase
- [x] trim
- [x] truncate
说明
npm依赖分2种,常规依赖和dev依赖。
strman没有任何常规依赖,也就是它自己说的:“without npm dependences”,但它是es 6语法,借助babel开发的,这是开发阶段使用的依赖
看一下它的package.json
"main": "dist/strman.js",
dist是压缩后的目录,也就是说它的模块主文件是压缩后的。
根目录里有一个gulpfile.babel.js用于压缩混淆,这就很明显了
gulp.task('browserify', () => {
browserify({
entries: './src/strman.js',
transform: [babelify, es6ify, deglobalify],
// Generate a UMD bundle for the supplied export name.
// This bundle works with other module systems and sets the name
// given as a window global if no module system is found.
standalone: '_s',
// Enable source maps that allow you to debug your files
// separately.
debug: true
})
.bundle()
.pipe(source('strman.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest('dist'))
.pipe(gulp.dest('public'));
});
总结
目前看是基于mocha和chai的测试,基本ok,集成了travis-ci,但无测试覆盖率,无benchmark,性能如何还不好说
从开源到今天(4月24日),才12天,已经754个star,还算是不错的了,想参与的可以去贡献一下。另外要说的是它是学习es6的非常好的范例,推荐。
全文完
欢迎关注我的公众号【node全栈】
如果想参与评论,请点击原文链接,进入国内最专业的cnode论坛
strman是一个无依赖的string操作库,api非常丰富,适用于前端和Node.js。从开源到今天(4月24日),才12天,已经754个star,还算是不错的了,想参与的可以去贡献一下。另外它是学习es6的非常好的范例
mk