
Security News
npm ‘is’ Package Hijacked in Expanding Supply Chain Attack
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
lasso-string
Advanced tools
A function with methods to manipulate strings and get information about strings.
lasso.between('(', ')', 'This) is (between)');
// -> {
start : 9,
end : 17,
length : 7,
value : 'between'
}
lasso.between(/[a-z]+\(/, ')', 'This) is function(between)');
// -> {
start : 18,
end : 25,
length : 16,
value : 'between'
}
lasso.camelCase('Let\'s JavaScript case this thing');
// -> letsJavascriptCaseThisThing
lasso.capitalCase('let\'s CapitalCase this thing');
// -> Let's CapitalCase This Thing
lasso.differentWords('a b c d', 'a d f b');
// -> ['c', 'f']
Calculates the Levenshtein distance between two words.
Based on this implementation by Andrei Mackenzie
lasso.distance('This distance', 'That distant');
// -> 4
lasso.ellipsis(String, Limit)
Adds '...' at the end of a string if it exceeds the length of the second argument
lasso.ellipsis('This distance', 5);
// -> This...
Returns an object of character positions in a fuzzy search.
var match = lasso.fuzzy('this is being searched', 'tbs');
// -> [{"index":0,"length":1,"match":"t"},{"index":8,"length":1,"match":"b"},{"index":14,"length":1,"match":"s"}]
.distance
is the distance between the first and last match.closest
is the index
of the closest match.farthest
is the index
of the farthest match.difference
is the difference between the closest
and farthest
match var match = lasso.fuzzy('this is being searched', 'tbs');
// match.distance -> 14
// match.closest -> 6
// match.farthest -> 7
// match.difference -> 1
lasso.group(Number)
Groups numbers together using a comma
lasso.group(1000.49);
// -> 1,000.49
lasso.indexesOf('Check out where the indexes of \'e\' are', 'e');
// -> [{ index : 3, length : 1, match : 'e'}, { index : 5, length : 1, match : 'e'}, { ... }]
Also works with a regular expression
lasso.indexesOf('Check out where the indexes of \'e\' are', /e/);
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.matchType('test10.scss');
// -> ['test', '10', '.', 'scss'];
lasso.sameWords('a b c', 'a');
// -> ['a']
lasso.splice('string', 1, 0, 'INSERT');
// -> sINSERTtring
lasso.template('Use %s to template a string', 'Rope');
// -> Use Rope to template a string
You can also reference indexes:
lasso.template('indexed %0', 'values');
// -> indexed values
lasso.toCharCode(82);
// -> R
lasso.toCharCode([82, 111, 112, 101]);
// -> Rope
lasso.toCharCode('s');
// -> [115]
lasso.toCharCode('Rope');
// -> [82, 111, 112, 101]
lasso.toCurrency(1000.49);
// -> $1,000.49
You can use a custom prefix, by including as the first argument
lasso.toCurrency('¢', 1000.49);
// -> ¢1,000.49
lasso.toPercentage(10);
// -> 10%
var match = lasso.trimEnd('Love ');
// -> 'Love'
var match = lasso.trimStart(' Love');
// -> 'Love'
var match = lasso.trimStartUntil('Love this', 't');
// -> 'this'
var match = lasso.trimStartUntil('Love this', /t/);
// -> 'this'
lasso('What is %0?')
.template('Rope')
.splice(1, 0, 'SPLICE')
.value;
// -> WSPLICEhat is Rope?
var lasso = require('lasso');
FAQs
A function with methods to manipulate strings and get information about strings.
The npm package lasso-string receives a total of 11 weekly downloads. As such, lasso-string popularity was classified as not popular.
We found that lasso-string demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
Security News
A critical flaw in the popular npm form-data package could allow HTTP parameter pollution, affecting millions of projects until patched versions are adopted.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.