Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.
/ strrr Public archive

πŸ“œ Functional-ish string utilities, inspired by Laravel's Str helpers.

License

Notifications You must be signed in to change notification settings

tymondesigns/strrr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

37 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

strrr

Functional string utilities, inspired by Laravel's Str helpers. Because why not?

Travis npm

Installation

yarn add strrr

Usage

chainability built in. e.g.

import { str } from 'strrr';

str('lorem ipsum dolor sit amet')
  .title()
  .limit(10)
  .pipe(s => doSomething(s))
  .get();

// = 'Lorem Ipsu…'

Available Methods

limit

Limit a string to a given length with a suffix (ellipsis).

Method signature

limit(limit = 100, end = '…');

import { str } from 'strrr';

str('lorem ipsum dolor sit amet').limit(20).get();
// = 'Lorem ipsum dolor si…'

words

Limit the number of words in a string with a suffix (ellipsis).

Method signature

words(words = 100, end = '…');

import { str } from 'strrr';

str('lorem ipsum dolor sit amet').words(3).get();
// = 'Lorem ipsum dolor…'

random

Generate a "random" alpha-numeric string.

Method signature

random(length = 32)

import { random } from 'strrr';

random().get(); // = 'nKusDo5JIFrI1tJswwzpEyGLpvML1Mxp'
random(16).get(); // = 'Ky6zJuGnGyrnvw1y'

ascii

Transliterate a UTF-8 value to ASCII.

Method signature

ascii()

import { str } from 'strrr';

str('I β™₯ javascript').ascii().get() // = 'I love javascript'
str('@Γ°αΊ»-₀Ⴠف').ascii().get() // = 'atde-0ff'

slug

Generate a URL friendly "slug" from the string.

Method signature

slug(separator = '-')

import { str } from 'strrr';

str('FOO bar baz').slug().get() // = 'foo-bar-baz'
str('I β™₯ javascript').slug('_').get() // = 'i_love_javascript'

title

Convert the string to Title case.

Method signature

title()

import { str } from 'strrr';

str('lorem ipsum dolor sit amet').title().get();
// = 'Lorem Ipsum Dolor Sit Amet'

studly

Convert the string to Studly case. Also known as pascal case

Method signature

studly()

import { str } from 'strrr';

str('lorem_ipsum_dolor_sit_amet').studly().get();
// = 'LoremIpsumDolorSitAmet'

camel

Convert the string to camel case

Method signature

camel()

import { str } from 'strrr';

str('lorem_ipsum_dolor_sit_amet').camel().get();
// = 'loremIpsumDolorSitAmet'

snake

Convert the string to snake case

Method signature

snake(delimeter = '_')

import { str } from 'strrr';

str('LoremIpsumDolorSitAmet').snake().get();
// = 'lorem_ipsum_dolor_sit_amet'

kebab

Convert the string to kebab case - Which is similar to snake case but with dashes.

Method signature

kebab()

import { str } from 'strrr';

str('LoremIpsumDolorSitAmet').kebab().get();
// = 'lorem-ipsum-dolor-sit-amet'

ucfirst

Capitalize the first character in a string.

Method signature

ucfirst()

import { str } from 'strrr';

str('foo bar').ucfirst().get(); // = 'Foo bar'

lcfirst

lower case the first character in a string.

Method signature

lcfirst()

import { str } from 'strrr';

str('Lorem ipsum').lcfirst().get(); // = 'lorem ipsum'

contains

Determine if a given string contains a given string.

Method signature

contains(val, position = 0)

import { str } from 'strrr';

str('foobarbaz').contains('bar'); // = true
str('foobarbaz').contains('bob'); // = false

startsWith

Determine if a given string starts with a given string.

Method signature

startsWith(val, position = 0)

import { str } from 'strrr';

str('Lorem ipsum dolor sit amet').startsWith('Lorem') // = true
str('Lorem ipsum dolor sit amet').startsWith('ipsum') // = false

endsWith

Determine if a given string ends with a given string.

Method signature

endsWith(val, position = 0)

import { str } from 'strrr';

str('Lorem ipsum dolor sit amet').endsWith('amet'); // = true
str('Lorem ipsum dolor sit amet').endsWith('ipsum'); // = false

isLowerCase

Determine if the string is lowercase.

Method signature

isLowerCase()

import { str } from 'strrr';

str('lorem ipsum dolor sit amet').isLowerCase(); // = true
str('Lorem ipsum dolor sit amet').isLowerCase(); // = false

isUpperCase

Determine if the string is uppercase.

Method signature

isUpperCase()

import { str } from 'strrr';

str('LORUM').isUpperCase(); // = true
str('LoRuM').isUpperCase(); // = false

strip

Strip all whitespace from a string.

Method signature

strip()

import { str } from 'strrr';

str(' Lorem ipsum dolor sit amet  ').strip().get()
// = 'Loremipsumdolorsitamet'

About

πŸ“œ Functional-ish string utilities, inspired by Laravel's Str helpers.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published