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

mellotron

v0.2.6

Published

Synthetic string orchestra. Curated list of string manipulation curried functions

Downloads

7

Readme

mellotron 0.2.6

Synthetic string orchestra. Curated list of string manipulation curried functions

  yarn add mellotron
  npm install mellotron

Methods

capitalize concat contains deburr endsWith format fromQuery fromURL isString isURL join leftPad length match pad replace reverse rightPad slugify split startsWith test toLower toQuery toString toUpper toURL trim trimLeft trimRight

capitalize([string=''])

Capitalize the first letter of a string. From lodash/capitalize

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | string='' | string | The string to convert. | Optional |

Examples
capitalize('united states');
// => 'United states'
Returns
  • string Returns the capitalized string.

concat([string='', string=''])

Concatenate the given strings. From ramda/concat

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | string='' | string | The first string to add. | Optional | | string='' | string | The second string to add. | Optional |

Examples
concat('ABC', 'DEF');
// => 'ABCDEF'

const prefix = concat('cyber');
prefix('space');
// => 'cyberspace'
Returns
  • string Returns the result of concatenating the given strings.

contains(a, list)

Inserts the separator string between each element and concatenating all the elements into a single string. From ramda/contains

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | a | string | The item to compare against. |   | | list | string | The string to consider |   |

Examples
contains('á', 'Zárate')
// => true

const taco = contains('salsa');
taco('Un taco sin salsa no es taco');
// => true
Returns
  • boolean Returns true if an equivalent item is in list, false otherwise.

deburr([string=''])

Deburrs string by converting letters to basic Latin letters and removing combining diacritical marks. From lodash/deburr

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | string='' | string | The string to deburr. | Optional |

Examples
deburr('déjà vu');
// => 'deja vu'
Returns
  • string Returns the deburred string.

endsWith(target, string)

Checks if string ends with the given target string. From lodash/endsWith

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | target | string | The string to search for. |   | | string | string | The string to inspect. |   |

Examples
endsWith('c', 'abc');
// => true

const endsWithR = endsWith('r');
endsWithR('bar');
// => true
Returns
  • boolean Returns true if string ends with target, else false.

format(template, values)

Values are interpolated on a template string.

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | template | string | The `string` with placeholders. |   | | values | Array.<*> Object | Values to be interpolated |   |

Examples
// Allows creating templates:
const readMessages = format('{0}, you have {1} unread message{2}')
readMessages(['Holly', 2, 's'])
// => 'Holly, you have 2 unread messages'

// Unmatched placeholders produce no output:
readMessages(['Steve', 1])
// => 'Steve, you have 1 unread message'

// Supports property access via dot notation
const bobby = { first: 'Bobby', last: 'Fischer' };
const garry = { first: 'Garry', last: 'Kasparov' };
format('{0.first} {0.last} vs. {1.first} {1.last}', [bobby, garry])
// => 'Bobby Fischer vs. Garry Kasparov'

// Supports property access via object property
const jamesBond = { firstname: 'James', lastname: 'Bond' };
format('The name is {lastname}. {firstname} {lastname}.', jamesBond)
// => 'The name is Bond. James Bond.'
Returns
  • string Returns the result of replacing each {…} placeholder in the template string with its corresponding replacement.

fromQuery(str[, sep='&', eq='=', options])

Parse a query string into an object. From querystring/parse

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | str | string | The URL query string to parse. |   | | sep='&' | string | The substring to delimit key and value pairs. | Optional | | eq='=' | string | The substring to delimit keys and values. | Optional | | options | Object | | Optional |

Examples
fromQuery('foo=1&foo=2&foo=3');
// => { foo: ['1', '2', '3' ] }

fromQuery('foo:1|foo:2|foo:3', '|', ':');
// => { foo: ['1', '2', '3' ] }
Returns
  • Object Returns the parsed URL query string (str) into a collection of key and value pairs.

fromURL(urlString[, parseQueryString=false, slashesDenoteHost=false])

Parse a query string into an object. Leading ? or # are ignored, so you can pass location.search or location.hash directly. From url/parse

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | urlString | string | The URL string to parse. |   | | parseQueryString=false | boolean | The query property will be set to an object returned by the querystring module's parse() method if `true`. | Optional | | slashesDenoteHost=false | boolean | The first token after the literal string // and preceding the next / will be interpreted as the host if `true`. | Optional |

Examples
fromURL('https://www.dgmlive.com/kingcrimson/?album=discipline#track-1');
// =>
// {
//   protocol: 'https:',
//   slashes: true,
//   auth: null,
//   host: 'www.dgmlive.com',
//   port: null,
//   hostname: 'www.dgmlive.com',
//   hash: '#track-1',
//   search: '?album=discipline',
//   query: 'album=discipline',
//   pathname: '/kingcrimson/',
//   path: '/kingcrimson/?album=discipline',
//   href: 'https://www.dgmlive.com/kingcrimson/?album=discipline#track-1'
// }
Returns
  • Object Returns the parsed URL into a collection of key and value pairs.

isString(val)

See if an object is an instance of the String constructor. From ramda/is

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | val | string | The value to test. |   |

Examples
isString('s');
// => true

isString(new String(''));
// => true
Returns
  • boolean Returns if the value is a String.

isURL(string)

Parse a query string into an object. Leading ? or # are ignored, so you can pass location.search or location.hash directly. From url/parse

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | string | string | The URL string to validate. |   |

Examples
isURL('http://symbolics.com');
// => true

isURL('http://')
// => false

isURL('bbn.com')
// => false
Returns
  • Object Returns true if string is a URL, false otherwise.

join(separator, xs)

Inserts the separator string between each element and concatenating all the elements into a single string. From ramda/join

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | separator | string | The string used to separate the elements. |   | | xs | string | The elements to join into a string. |   |

Examples
join(' ', ['a', 2, 3.4]);
// => 'a 2 3.4'

const piper = join('|');
piper(['Pied', 'Piper', 'of', 'Hamelin']);
// => 'Pied|Piper|of|Hamelin'
Returns
  • string Returns the string made by concatenating xs with separator.

leftPad(length, string)

Pads string on the left side if it's shorter than length. Padding characters are truncated if they exceed length. From lodash/padStart

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | length | number | The padding length. |   | | string | string | The string to pad. |   |

Examples
leftPad(6, 'abc');
// => '   abc'
Returns
  • string Returns the padded string.

length(s)

Count visual length of javascript string. From charcount

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | s | string | The string to count. |   |

Examples
length('🐒🐒🐒🐒🐒🐒🐒🐒🐒🐒🐒🐒');
// => 12
Returns
  • number Returns length of the string.

match(rx, str)

Tests a regular expression against a string. From ramda/match

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | rx | string | A regular expression or a substring to match. |   | | str | string | The string to match against. |   |

Examples
match(/([a-z]a)/g, 'bananas');
// => ['ba', 'na', 'na']
Returns
  • Array The list of matches or empty array.

pad(length, string)

Pads string on the left and right sides if it's shorter than length. Padding characters are truncated if they can't be evenly divided by length. From lodash/pad

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | length | number | The padding length. |   | | string | string | The string to pad. |   |

Examples
pad(8, 'abc');
// => '  abc   '
Returns
  • string Returns the padded string.

replace(regex, replacement, str)

Inserts the separator string between each element and concatenating all the elements into a single string. From ramda/replace

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | regex | string | A regular expression or a substring to match. |   | | replacement | string | The string to replace the matches with. |   | | str | string | The String to do the search and replacement in. |   |

Examples
replace(/foo/g, 'bar', 'foo foo foo');
// => 'bar bar bar'

const censor = replace('the night', 'some time');
censor("Let's spend the night together")
// => "Let's spend some time together"
Returns
  • string Returns the resulted string.

reverse(list)

Reverse a string. From ramda/reverse

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | list | string | The string to reverse. |   |

Examples
reverse('stressed');
// => 'desserts'
Returns
  • string Returns a new string with the characters in reverse order.

rightPad(length, string)

Pads string on the right side if it's shorter than length. Padding characters are truncated if they exceed length. From lodash/padEnd

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | length | number | The padding length. |   | | string | string | The string to pad. |   |

Examples
rightPad(6, 'abc');
// => 'abc   '
Returns
  • string Returns the padded string.

slugify([string=''])

Converts string to kebab case. From lodash/kebabCase

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | string='' | string | The string to convert. | Optional |

Examples
slugify('This, That and the Other! An Outré Collection');
// => 'this-that-and-the-other-an-outre-collection'
Returns
  • string Returns the kebab cased string.

split(sep, str)

Splits a string into an array of strings based on the given separator. From ramda/split

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | sep | string | The pattern. |   | | str | string | The string to separate into an array. |   |

Examples
const path = split('/');
path('/usr/local/bin/node');
// => ['', 'usr', 'local', 'bin', 'node']
Returns
  • Array Returns the resulting array.

startsWith(target, string)

Checks if string starts with the given target string. From lodash/startsWith

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | target | string | The string to search for. |   | | string | string | The string to inspect. |   |

Examples
startsWith('a', 'abc');
// => true

const startsWithM = startsWith('M');
startsWithM('Mellotron');
// => true
Returns
  • boolean Returns true if string starts with target, else false.

test(pattern, str)

Determines whether a given string matches a given regular expression. From ramda/test

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | pattern | string | A regular expression or a substring to match. |   | | str | string | The string to match against. |   |

Examples
test(/^x/, 'xyz');
// => true

test(/^y/, 'xyz');
// => false
Returns
  • boolean The result of the test.

toLower(str)

Convert to lower case. From ramda/toLower

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | str | string | The string to lower case. |   |

Examples
toLower('XYZ');
// => 'xyz'
Returns
  • string Returns the lower case version of str.

toQuery(str[, sep='&', eq='=', options])

Stringify an object into a query string, sorting the keys. From querystring/stringify

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | str | string | The URL query string to parse. |   | | sep='&' | string | The substring to delimit key and value pairs. | Optional | | eq='=' | string | The substring to delimit keys and values. | Optional | | options | Object | | Optional |

Examples
toQuery({ foo: 'bar', baz: ['qux', 'quux'], corge: '' });
// => 'foo=bar&baz=qux&baz=quux&corge='

toQuery({ foo: 'bar', baz: 'qux' }, '|', ':');
// => foo:bar|baz:qux'
Returns
  • Object Returns the parsed URL query string (str) into a collection of key and value pairs.

toString(val)

Convert to string. From ramda/toString

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | val | string | The value to convert. |   |

Examples
toString(42);
// => '42'

toString([1, 2, 3]);
//=> '[1, 2, 3]'

toString({ foo: 1, bar: 2, baz: 3 });
//=> '{"bar": 2, "baz": 3, "foo": 1}'
Returns
  • string Returns the string representation of the given value

toUpper(str)

Convert to upper case. From ramda/toUpper

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | str | string | The string to upper case. |   |

Examples
toUpper('abc');
// => 'ABC'
Returns
  • string Returns the upper case version of str.

toURL(urlObject)

Convert an url object to URL. From url/format

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | urlObject | Object string | A URL object (as returned by url.parse() or constructed otherwise). If a string, it is converted to an object by passing it to url.parse(). |   |

Examples
toURL({
 protocol: 'https',
 host: 'www.dgmlive.com',
 hash: '#track-1',
 query: { album: 'discipline' },
 pathname: '/kingcrimson'
})
// => "https://www.dgmlive.com/kingcrimson?album=discipline#track-1"
Returns
  • string Returns the resulted URL.

trim(str)

Removes (strips) whitespace from both ends of the string. From ramda/trim

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | str | string | The string to trim. |   |

Examples
trim('   xyz  ');
// => 'xyz'
Returns
  • string Returns the trimmed version of str.

trimLeft([string=''])

Removes leading whitespace or specified characters from string. From lodash/trimStart

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | string='' | string | The string to trim. | Optional |

Examples
trimStart('  abc  ');
// => 'abc  '
Returns
  • string Returns the trimmed string.

trimRight([string=''])

Removes trailing whitespace or specified characters from string. From lodash/trimEnd

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | string='' | string | The string to trim. | Optional |

Examples
trimRight('  abc  ');
// => '  abc'
Returns
  • string Returns the trimmed string.