Socket
Socket
Sign inDemoInstall

mellotron

Package Overview
Dependencies
7
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mellotron

Synthetic string orchestra. Curated list of string manipulation curried functions


Version published
Weekly downloads
26
increased by550%
Maintainers
1
Install size
5.64 MB
Created
Weekly downloads
 

Readme

Source

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
NameTypeDescription
string=''stringThe 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
NameTypeDescription
string=''stringThe first string to add.Optional
string=''stringThe 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
NameTypeDescription
astringThe item to compare against. 
liststringThe 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
NameTypeDescription
string=''stringThe 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
NameTypeDescription
targetstringThe string to search for. 
stringstringThe 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
NameTypeDescription
templatestringThe `string` with placeholders. 
valuesArray.<*> ObjectValues 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
NameTypeDescription
strstringThe URL query string to parse. 
sep='&'stringThe substring to delimit key and value pairs.Optional
eq='='stringThe substring to delimit keys and values.Optional
optionsObjectOptional
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
NameTypeDescription
urlStringstringThe URL string to parse. 
parseQueryString=falsebooleanThe query property will be set to an object returned by the querystring module's parse() method if `true`.Optional
slashesDenoteHost=falsebooleanThe 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
NameTypeDescription
valstringThe 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
NameTypeDescription
stringstringThe 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
NameTypeDescription
separatorstringThe string used to separate the elements. 
xsstringThe 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
NameTypeDescription
lengthnumberThe padding length. 
stringstringThe 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
NameTypeDescription
sstringThe 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
NameTypeDescription
rxstringA regular expression or a substring to match. 
strstringThe 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
NameTypeDescription
lengthnumberThe padding length. 
stringstringThe 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
NameTypeDescription
regexstringA regular expression or a substring to match. 
replacementstringThe string to replace the matches with. 
strstringThe 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
NameTypeDescription
liststringThe 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
NameTypeDescription
lengthnumberThe padding length. 
stringstringThe 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
NameTypeDescription
string=''stringThe 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
NameTypeDescription
sepstringThe pattern. 
strstringThe 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
NameTypeDescription
targetstringThe string to search for. 
stringstringThe 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
NameTypeDescription
patternstringA regular expression or a substring to match. 
strstringThe 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
NameTypeDescription
strstringThe 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
NameTypeDescription
strstringThe URL query string to parse. 
sep='&'stringThe substring to delimit key and value pairs.Optional
eq='='stringThe substring to delimit keys and values.Optional
optionsObjectOptional
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
NameTypeDescription
valstringThe 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
NameTypeDescription
strstringThe 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
NameTypeDescription
urlObjectObject stringA 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
NameTypeDescription
strstringThe 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
NameTypeDescription
string=''stringThe 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
NameTypeDescription
string=''stringThe string to trim.Optional
Examples
trimRight('  abc  ');
// => '  abc'
Returns
  • string Returns the trimmed string.

Keywords

FAQs

Last updated on 24 Jan 2018

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc