Lasso
An interface for editing strings
Methods
.between
lasso;// -> { start : 9 end : 17 length : 7 value : 'between' }
lasso;// -> { start : 18 end : 25 length : 16 value : 'between' }
.camelCase
lasso;// -> letsJavascriptCaseThisThing
.capitalCase
lasso;// -> Let's CapitalCase This Thing
.differentWords
lasso;// -> ['c', 'f']
.distance
Calculates the Levenshtein distance between two words.
Based on this implementation by Andrei Mackenzie
lasso;// -> 4
.ellipsis
lasso.ellipsis(String, Limit)
Adds '...' at the end of a string if it exceeds the length of the second argument
lasso;// -> This...
.fuzzy
Returns an object of character positions in a fuzzy search.
var match = lasso; // -> [{"index":0,"length":1,"match":"t"},{"index":8,"length":1,"match":"b"},{"index":14,"length":1,"match":"s"}]
Fuzzy search properties
.distance
is the distance between the first and last match.closest
is theindex
of the closest match.farthest
is theindex
of the farthest match.difference
is the difference between theclosest
andfarthest
match
var match = lasso; // match.distance -> 14 // match.closest -> 6 // match.farthest -> 7 // match.difference -> 1
.group
lasso.group(Number)
Groups numbers together using a comma
lasso;// -> 1,000.49
.indexesOf
lasso;// -> [{ index : 3, length : 1, match : 'e'}, { index : 5, length : 1, match : 'e'}, { ... }]
Also works with a regular expression
lasso;
Match Type
Works a bit like a regular expression match in that in returns the string split up by character group types, alpha with alpha, numbers with numbers, punctuation with punctuation, etc.
var match = lasso; // -> ['test', '10', '.', 'scss'];
.sameWords
lasso;// -> ['a']
.splice
lasso;// -> sINSERTtring
.template
lasso;// -> Use Rope to template a string
You can also reference indexes:
lasso;// -> indexed values
.toChar
lasso;// -> R lasso;// -> Rope
.toCharCode
lasso;// -> [115] lasso;// -> [82, 111, 112, 101]
.toCurrency
lasso;// -> $1,000.49
You can use a custom prefix, by including as the first argument
lasso;// -> ¢1,000.49
.toPercentage
lasso;// -> 10%
Trim End
var match = lasso;// -> 'Love'
Trim Start
var match = lasso; // -> 'Love'
Trim Start Until
var match = lasso; // -> 'this'
var match = lasso; // -> 'this'
Chain methods together
value;// -> WSPLICEhat is Rope?
Including the module with Node JS (CommonJS)
var lasso = ;