split-retain

Split a string and preserve the delimiters.

split-retain

Split a string and preserve the delimiters.

Install

Node.js
npm install split-retain --save

var splitRetain = require('split-retain');

Browser
Include the full or minified version on your webpage from browser/, then use splitRetain(...).

<script src="path/to/split-retain.min.js">

Examples

splitRetain('home/jack/images/photo12.jpeg', '/')
// ['home/', 'jack/', 'images/', 'photo12.jpeg']

splitRetain('home/jack/images/photo12.jpeg', '/', { leadingSeparator: true })
// ['home', '/jack', '/images', '/photo12.jpeg']

...

Documentation

splitRetain(string, separator[, options])

Arguments

argumenttypedesription
stringStringstring to split
separatorString
———
RegExp
single character
———
must have grouping parentheses and global flag, e.g. /(\d+)/g
[options = {}]Object-
[options.leadingSeparator = false]Booleanif true, the separator will be placed at the beginning of the split tokens

Results

propertytypedescription
@returnString[]array of split tokens
@throwsErroron incorrect argument types

Tests

npm test

Coverage

npm run cover

TODO

  • create 'publish steps'
  • replace browserify with UMD?
  • more examples in Examples
  • changelog
  • lint
  • ...

License

MIT

Repository

https://github.com/ghornich/split-retain


上一篇:sort-paths
下一篇:高性能javascript--算法和流程控制

相关推荐

官方社区

扫码加入 JavaScript 社区