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

strangler

v2.0.1

Published

A set of string utilities for parsing and assembly

Downloads

3,783

Readme

strangler.js

NPM version npm Travis

It's a string wrangler, and not nearly as dangerous as it sounds. A set of string utilities which expand those in string-tools with additional features. ES module native

Usage

Often I do string parsing and I like some convenience functions to help out.

you can either retain an instance and use it that way:

import * as stringTool from 'strangler';
// or: const stringTool = require('strangler');
stringTool.contains(string, substring);

or you can just attach to the prototype (this can be OK in an app, but is a bad idea in a library):

require('string-tools').proto();
string.contains(substring);

proto()

assign these utilities to String.prototype and throw caution to the wind...

Kind: static property of strangler

.contains(str, candidate) ⇒ boolean

Tests whether the string contains a particular substring or set of substrings

Kind: static method of strangler

| Param | Type | Description | | --- | --- | --- | | input | string | input string to test | | candidate | string or Array | the substring to test |

Example

'elongated'.contains('gate'); //returns true;
'elongated'.contains(['long', 'gate']); //returns true;
'elongated'.contains(['wall']); //returns false;

.beginsWith(str, candidate) ⇒ boolean

Tests whether the string begins with a particular substring

Kind: static method of strangler

| Param | Type | Description | | --- | --- | --- | | input | string | input string to test | | candidate | string | the substring to test |

Example

'max'.beginsWith('m'); //return true;

.endsWith(str, candidate) ⇒ boolean

Tests whether the string ends with a particular substring

Kind: static method of strangler

| Param | Type | Description | | --- | --- | --- | | input | string | input string to test | | candidate | string | the substring to test |

Example

'max'.endsWith('x'); //return true;

.splitHonoringQuotes(str, [delimiter], [escape], [quotes], [terminator]) ⇒ Array

like String.split(), but it will honor the opening and closing of quotes, so a delimiter inside a quote won't blow it up.

Kind: static method of strangler

| Param | Type | Default | Description | | --- | --- | --- | --- | | input | string | | input string to split | | delimiter | string | ',' | the pattern to split on | | escape | char | | the character to use as an escape value | | quotes | Array | ["'", '""'] | the quotes to respect | | terminator | char | | the character to split groups |

Example

'a, b, c="r, u, d", d'.splitHonoringQuotes(',');

returns

['a', ' b', ' c="r, u, d"', ' d']

.decompose(str, [delimit], [quotes]) ⇒ Array

like String.split(), but it will honor the opening and closing of quotes, so a delimiter inside a quote won't blow it up, rather than using a fixed delimiter, you can provide a RegExp to split on. Not as fast as splitHonoringQuotes, but much more flexible.

Kind: static method of strangler

| Param | Type | Default | Description | | --- | --- | --- | --- | | input | string | | input string to split | | delimiter | RegExp | ',' | the pattern to split on | | quotes | Array | ["'", '""'] | the quotes to respect |

.multiLineAppend(str, appendStr, [joinStr]) ⇒ string

returns the two strings which are appended together in a line by line fashion.

Kind: static method of strangler

| Param | Type | Default | Description | | --- | --- | --- | --- | | str | string | | multiline string prefix | | appendStr | string | | multiline string suffix | | joinStr | string | | the chars to stick between them |

Example

var firsts = 'this \
attaches \
the ';
var seconds = 'one \
to \
other'
firsts.multiLineAppend(seconds);

returns

'this one\
attaches to\
the other'

strangler.StreamDecomposer

.StreamDecomposer([options]) ⇒ Class

This class allows you to parse a large string as and to generate events during parse to prevent storing the results in memory. It is an EventEmitter and will generate token events for each token it finds and if options.terminator is set it will generate cell and row events.

Kind: constructor of strangler.StreamDecomposer

| Param | Type | Default | Description | | --- | --- | --- | --- | | options.delimiter | char | | the character to split individual pieces of data on | | options.terminator | char | | the character to split groups of data on | | options.escape | char | | the character to escape on | | options.quotes | Array | | list of characters to quote with |

.StreamDecomposer.writable ⇒ stream.Writable

Generate a writable stream to pipe a readable stream into in order to parse.

Kind: method of strangler

returns stream.Writable

Testing

just run

mocha

Enjoy,

-Abbey Hawk Sparrow