Strman是无任何依赖的string操作库,前后端通用。
安装:
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
说明
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')); });