Common Utilities
  • Introduction πŸ‘‹
  • Getting Started
    • Installation πŸ“₯
    • Usage πŸ”§
  • Utilities
    • Packages πŸ“¦
      • Debounce πŸ“
      • Filter-array🧹
      • Merge-objectsπŸ‘―β€β™‚οΈ
      • String-interpolation🧡
      • Kebab-to-camel-string 🍒🐫
      • Trim-whitespace ⬜️
      • Wait-until-defined ⌚️
      • Compose πŸš‚
      • Repeat πŸ”
      • Pipe β›“
      • Trace πŸ‘€
    • Glossary πŸ“’
  • General
    • Comparision βš–οΈ
    • Cites πŸ™
Powered by GitBook
On this page
  • Compose πŸš‚
  • Head πŸ‘€
  • Repeat πŸ–‹
  • Filter-Array 🧹
  • Is-Object πŸŽ›
  • Merge-ObjectsπŸ‘―β€β™‚οΈ
  • Kebab-to-camel-string 🍒🐫
  • Trim-whitespace βœ‚οΈ
  • Wait-until-defined ⌚️
  • Debounce πŸ“
  • Common Utilities 🧰

Was this helpful?

  1. Utilities

Glossary πŸ“’

PreviousTrace πŸ‘€NextComparision βš–οΈ

Last updated 4 years ago

Was this helpful?

Below are sectioned descriptions and code usages of each implemented Common Utility. Read more about each common utility within each package's README!

Compose πŸš‚

is a common function that take the output from one function and automatically patches it to the input of the next function until it spits out the final value.

Compose is useful for computing a series of functions in a composed fashion improving code readability and testability.

Usage

const result = compose(add1, subtract3, multipleBy5)
// result(3) // 5 (3 + 1 - 3 * 5)

Head πŸ‘€

is a common function for return the value of the first item in an Array.

Usage

head([0, 1, 2, 3, 4]) // 01

Pipe β›“

is a common function that take the output from one function and automatically patches it to the input of the next function until it spits out the final value in the opposite order of Compose.

Like compose, Pipe is useful for computing a series of functions in a composed fashion improving code readability and testability but in the opposite order of Compose.

Usage

const result = pipe(add1, subtract2, multipleBy3)
// result(3) // 8 (3 * 3 - 2 + 1)

Repeat πŸ–‹

Repeat is useful for declaritively performing a while loop, making it more testable.

Usage

const add1 = (val) => val + 1
repeat(100)(add1)(0) // 100

Filter-Array 🧹

Filter is useful for ensuring an array is exact.

Usage

filterArray(['test', 'test', 'foo', 'bar', 'biz']) // ['test', 'foo', 'bar', 'biz'])

Is-Object πŸŽ›

Is object is useful for determining that an object is an object and not an array.

Usage

isArray

isArray(['test', 'test']) // true
isArray({ foo: 'test' }) // false

isOfObjectType

isOfObjectType(['test', 'test']) // true
isOfObjectType({ foo: 'test' }) // true
isOfObjectType(9) // false
isOfObjectType('string') // false
isOfObjectType(null) // false
isOfObjectType(undefined) // false

isObject

isObject(['test', 'test']) // false
isObject({ foo: 'test' }) // true

Merge-ObjectsπŸ‘―β€β™‚οΈ

Merge Objects is useful for merging objects with nested object and/or array properties.

Usage

mergeObjects({ foo: 'bar' }, { baz: 'biz' }) // { foo: 'bar', baz: 'biz' }

String-interpolation 🧡

String Interpolation is useful for adding dynamic data to strings.

Usage

stringInterpolation('This string has #{dynamicData}', [{ dynamicData: 'a knot in it' }])
// => 'This string has a knot in i

Kebab-to-camel-string 🍒🐫

Kebab to Camel String is useful for switching objects from kebab case to camel case which is more usable in JavaScript.

Usage

// string
kebabToCamelString('test-thing')
// testThing

// object
kebabToCamelStringsInObject({ 'test-thing': 'foo' })
// { testThing: 'foo' }

Trim-whitespace βœ‚οΈ

Trim-whitespace is useful for removing extra spaces from inputed strings.

Usage

trimWhitespace('    This is some  really crazy.     string.   ')
// This is some really crazy. string.

Wait-until-defined ⌚️

Wait-until-defined is useful for waiting until some data type is defined.

Usage

setTimeout(() => (window.Test = 'yay'), 2000)
const hasWindowTest = () => window.Test === 'test'
const test = async () => {
  const check = await waitUntilDefined(hasWindowTest, 50, 3000)
  return check
}
// true

Debounce πŸ“

Debounce is useful for ensuring that a function invocation doesn't happen too frequently.

Usage

let result = 1
const add1 = (val) => {
  result = val + 1
}
debounce(add1, 1000)(1) // returns 2, after 1 second

Common Utilities 🧰

No cruft. No bloat. No dependencies.

Simple, typed, functional, documented, and tested javascript utility functions.

is a common function composed of function arguments which recursively invoke a callback function based on iterations returning a final value.

is a common function a common function that removes deplicate items from an array.

is a common function for knowings whether data is of Object type. This function comes with isArray and isOfObjectTypes helper methods.

is a common function for merging two objects deeply.

is a common function for interpolating variables in strings.

is a common function for returning a kebab string as a camel string.

is a common function for returning a string with trimmed text.

is a common function for waiting until data is defined via a callback which returns a boolean.

is a common function that waits a set amount of time before invoking a callback.

View other on Github.

Compose
Head
Pipe
Repeat
Filter Array
IsObject
Merge Objects
String Interpolation
Kebab to Camel String
Trim Whitespace
Wait-until-defined
Debounce
common utilities