1.0.13 • Published 6 years ago

cd2oolz v1.0.13

Weekly downloads
79
License
MIT
Repository
-
Last release
6 years ago

Cd2oolz (see-dee-too-ls)

Package of utility functions (mostly to avoid including lodash)

Debounce

restricts how ofter a function can run

  debounce(timeInMillis)(func)
  @debounce(timeInMillis)(func)

Example:

Class:

class X {
  @debounce(1000) // time in millis
  myFunc() {
    // this will run at most once a second
  }
}

Function:

const x = debounce(5000)(function() {
  console.log("hello")
})

Memoize

caches the result of a function so it doesnt have to rerun

/*
   * func: function to memoize
   * argSerializer: function which transforms arguments into a key for caching,
   *                defaults to json stringifing the arguments
   */
memoize(func, argSerializer)

Example:

const x = memoize(function(arg1) {
  console.log("run")
  return arg1 * 2
})
x(1) // will log
x(1) // wont log as result has been cached

Shuffle

this function will randomize the order of an array in place.

shuffle(arr)

Example:

shuffle([1, 2, 3, 4]) // => [3,2,4,1]

Round

rounds a number. \ This will throw an error if decimalPlaces is < 0

/*
  * number: number to round
  * decimalPlaces: places to round to. Defaults to 0
  */
round(number, decimalPlaces)

Example:

round(5.1) // => 5
round(5.1, 1) // => 5.1
round(5.11111, 2) // => 5.11
1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago