0.0.46 • Published 4 years ago
string-saw v0.0.46
string-saw 
provides an easy way to string together match/replacement operations in an error-free manner
install
npm install string-saw
or
bower install string-saw
or head over to cdnjs
methods
- match (Array/String/Function/Saw) -> Saw
- matchAll (RegExp) -> Array/Object
- replace (Array/RegExp/String match, String/Function replacement) -> Saw
- remove (String/RegExp match) -> Saw
- map (Function func) -> Saw
- item (Integer index) -> Saw
- itemFromRight (Integer offset) -> Saw
- first () -> Saw
- last () -> Saw
- trim () -> Saw
- uniq () -> Saw
- join (String separator/Function separator) -> Saw
- each (Function func) -> Saw
- find(String/RegExp/Function match) -> Saw
- filter(String/RegExp/Function match) -> Saw
- filterNot(String/RegExp/Function match) -> Saw
- reduce (Function func) -> Saw
- slice (Integer start, Integer end) -> Saw
- split (String/RegExp match) -> Saw
- transform (Function context) -> Saw
- upperCase () -> Saw
- lowerCase () -> Saw
- prepend (String) -> Saw
- append (String) -> Saw
- capitalize () -> Saw
- reverse () -> Saw
- sort (Function func) -> Saw
- length () -> Integer
- has (String/RegExp match/Function match) -> Boolean
- startsWith(String/String) -> Boolean
- endsWith(String/String) -> Boolean
- toString () -> String
- toArray (returns an array) -> Array
- toNumber () -> Integer (0 if no match)
- toInt () -> Integer (can return NaN)
- toFloat () -> Float
- toBoolean () -> Boolean
- toObject () -> Object
- indexOf (String/RegExp/Function match) -> Integer
- indexesOf (String/RegExp/Function match) -> Integer
examples
var saw = require('string-saw');
saw('one two three four five six hello 323423 hello')
.remove(/\d+/g, 'hello')
.split(' ')
.slice(3,4)
.toString(); // returns "four"
saw('1 2 3')
.match(/\d+$/)
.toNumber(); // returns the number 3
saw('1 2 3')
.split(' ')
.last()
.toNumber(); // returns the number 3
saw('joe:56, bob:57')
.matchAll(/(?<name>(\S+)):(?<age>(\d+))/g)
/* returns
[
{name: 'joe', age: '56'},
{name: 'bob', age: '57'}
]
*/
saw('joe:56, bob:57')
.matchAll(/(\S+):(\d+)/g)
/* returns
[
['joe', '56'],
['bob', '57']
]
*/
saw('1 2 3 4 5')
.split(' ')
.itemFromRight(2)
.toNumber(); // returns the number 3
saw([' one ', ' two ', ' three '])
.trim()
.join(',')
.toString(); // returns "one,two,three"
saw('John. Smith.')
.match(/\S+/g)
.remove('.')
.toObject('first', 'last'); // returns {first: "John", last: "Smith"}
0.0.46
4 years ago
0.0.45
4 years ago
0.0.44
5 years ago
0.0.43
5 years ago
0.0.42
6 years ago
0.0.41
6 years ago
0.0.40
6 years ago
0.0.39
6 years ago
0.0.38
6 years ago
0.0.37
6 years ago
0.0.36
6 years ago
0.0.35
7 years ago
0.0.34
7 years ago
0.0.33
7 years ago
0.0.32
7 years ago
0.0.30
7 years ago
0.0.29
8 years ago
0.0.28
8 years ago
0.0.27
8 years ago
0.0.26
9 years ago
0.0.25
9 years ago
0.0.24
9 years ago
0.0.23
9 years ago
0.0.22
9 years ago
0.0.21
9 years ago
0.0.20
9 years ago
0.0.19
9 years ago
0.0.18
9 years ago
0.0.17
9 years ago
0.0.16
9 years ago
0.0.15
10 years ago
0.0.14
10 years ago
0.0.13
10 years ago
0.0.12
10 years ago
0.0.11
10 years ago
0.0.10
10 years ago
0.0.9
10 years ago
0.0.8
10 years ago
0.0.7
10 years ago
0.0.6
10 years ago
0.0.4
10 years ago
0.0.3
10 years ago
0.0.2
10 years ago
0.0.1
11 years ago
0.0.0
11 years ago