tings

tings

A collection of small utilities and complementary Lodash add-ons.


Install

npm i tings
# or
yarn add tings

isCamelCase

Determines if input is a camelCase string.

Requires lodash

example

import isCamelCase from 'tings/isCamelCase'

isCamelCase('camelCase') // true
isCamelCase('NOTCamelCase') // false

isCompactCase

Determines if input is a compactcase (no whitespaces) string.

example

import isCompactCase from 'tings/isCompactCase'

isCompactCase('thisiscompact') // true
isCompactCase('this is not compact') // false

isLowerCase

Determines if input is a string containing no UPPERcase characters.

example

import isLowerCase from 'tings/isLowerCase'

isLowerCase('this is lower') // true
isLowerCase('This is not LOWER') // false

isOccupied

Similar to the opposite of Lodash's isEmpty this will return true if a value is more than the minimum for its type. The main differences being:

  • All numbers except 0 are occupied.
  • All BigInts except BigInt(0) are occupied.
  • Only true is occupied, not both booleans.
  • All Symbols are occupied.

Requires lodash

example

import isOccupied from 'tings/isOccupied'

isOccupied('') // false
isOccupied(0) // false
isOccupied(BigInt(0)) // false
isOccupied([]) // false
isOccupied({}) // false
isOccupied(false) // false
isOccupied(null) // false
isOccupied(undefined) // false
isOccupied(new Map([])) // false

isOccupied(1) // true
isOccupied(true) // true
isOccupied('a') // true
isOccupied({ key: 'value' }) // true

isPascalCase

Determines if input is a PascalCase string.

Requires lodash

example

import isPascalCase from 'tings/isPascalCase'

isPascalCase('ThisIsPascal') // true
isPascalCase('notPascal') // false

isTitleCase

Determines if input is a Tile Case string.

Requires lodash

example

import isTitleCase from 'tings/isTitleCase'

isTitleCase('this is text') // false
isTitleCase('Small Words are not Capitalised') // true

isUniq

Determines if an array only contains unique items. Will return true for any input that's not an array.

example

import isUniq from 'tings/isUniq'

isUniq([1, 2, 3]) // true
isUniq([1, 1, 2]) // false
isUniq('not array') // true

isVacant

Similar to Lodash's isEmpty this will return true if a value is considered the minimum for its type. The main differences being:

  • Only 0 is vacant, not all numbers.
  • Only BigInt(0) is vacant, not all BigInts.
  • Only false is vacant, not both booleans.
  • Symbols are not vacant.

Requires lodash

example

import isVacant from 'tings/isVacant'

isVacant('') // true
isVacant(0) // true
isVacant(BigInt(0)) // true
isVacant([]) // true
isVacant({}) // true
isVacant(false) // true
isVacant(null) // true
isVacant(undefined) // true
isVacant(new Map([])) // true

isVacant(1) // false
isVacant(true) // false
isVacant('a') // false
isVacant({ key: 'value' }) // false

sleep

Pauses the current function.

example

import sleep from 'tings/sleep'

await sleep(2000) // sleeps for 2 seconds

toCompactCase

Removes all whitespace characters from a string.

example

import toCompactCase from 'tings/toCompactCase'

toCompactCase('this is text') // thisistext
toCompactCase('someTEXT') // someTEXT

toLetters

Removes all non-alphabetical characters from a string.

example

import toLetters from 'tings/toLetters'

toLetters('this is text') // thisistext
toLetters('123-Text!!!') // Text

toNumberAlways

Will return the given input as a number, if it cannot be converted, it will return 0.

example

import toNumberAlways from 'tings/toNumberAlways'

toNumberAlways('this is text') // 0
toNumberAlways('3') // 3
toNumberAlways(0.4) // 0.4
toNumberAlways(new Set([])) // 0

toOrdinal

Converts a number to its ordinal string form, if possible, else returns 0th.

  • 1 -> 1st
  • 4.2 -> 4.2th
  • notANumber -> 0th

example

import toOrdinal from 'tings/toOrdinal'

toOrdinal('this is text') // 0th
toOrdinal('3') // 3rd
toOrdinal('11') // 11th

toPascalCase

Converts input to PascalCase string.

Requires lodash

example

import toPascalCase from 'tings/toPascalCase'

toPascalCase('this is text') // ThisIsText
toPascalCase('someTEXT') // SomeText

toTitleCase

Keep small words in lowercase, otherwise make the first letter uppercase.

Requires lodash

example

import toTitleCase from 'tings/toTitleCase'

toTitleCase('this is text') // This is Text
toTitleCase('smallWordsAreNotCapitalised') // Small Words are not Capitalised