npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lasso-string

v5.4.1

Published

A function with methods to manipulate strings and get information about strings.

Downloads

121

Readme

Circle CI

Lasso

An interface for editing strings

Methods

.between

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'
      }

.camelCase

lasso.camelCase('Let\'s JavaScript case this thing');
// -> letsJavascriptCaseThisThing

.capitalCase

lasso.capitalCase('let\'s CapitalCase this thing');
// -> Let's CapitalCase This Thing

.differentWords

lasso.differentWords('a b c d', 'a d f b');
// -> ['c', 'f']

.distance

Calculates the Levenshtein distance between two words.

Based on this implementation by Andrei Mackenzie

lasso.distance('This distance', 'That distant');
// -> 4

.ellipsis

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...

.fuzzy

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"}]

Fuzzy search properties

  • .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

.group

lasso.group(Number)

Groups numbers together using a comma

lasso.group(1000.49);
// -> 1,000.49

.indexesOf

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/);

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.matchType('test10.scss');
  // -> ['test', '10', '.', 'scss'];

.sameWords

lasso.sameWords('a b c', 'a');
// -> ['a']

.splice

lasso.splice('string', 1, 0, 'INSERT');
// -> sINSERTtring

.template

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

.toChar

lasso.toCharCode(82);
// -> R

lasso.toCharCode([82, 111, 112, 101]);
// -> Rope

.toCharCode

lasso.toCharCode('s');
// -> [115]

lasso.toCharCode('Rope');
// -> [82, 111, 112, 101]

.toCurrency

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

.toPercentage

lasso.toPercentage(10);
// -> 10%

Trim End

var match = lasso.trimEnd('Love   ');
// -> 'Love'

Trim Start

  var match = lasso.trimStart('   Love');
  // -> 'Love'

Trim Start Until

  var match = lasso.trimStartUntil('Love this', 't');
  // -> 'this'
  var match = lasso.trimStartUntil('Love this', /t/);
  // -> 'this'

Chain methods together

lasso('What is %0?')
.template('Rope')
.splice(1, 0, 'SPLICE')
.value;
// -> WSPLICEhat is Rope?

Including the module with Node JS (CommonJS)

var lasso = require('lasso');