helpda
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

helpda

simple typescript utility library

Build Status npm module

getting started

$ npm install helpda

or

$ yarn add helpda

Example Usage

import { sum, map, reduce, sumArr } from 'helpda'

map([1, 2, 3], (x) => x + 1) //[2,3,4]
reduce(sum, 0, [1, 2, 3]) // 6
sumArr([2, 4, 6]) // 12

what function should i use?

Type Action Function
Array change every value map
compute based on custom function and output the final value reduce
flatten return a one-dimensional array, remove nesting flatten
Object change every value map
Functions memoize memoize
revers function args flip
Logic
Math sum two numbers sum
subtract two numbers subtract
multiple two numbers multiple
divide two numbers divide
increment number inc
decrement number dec
negate number negate
get random number between two args randomN
sum all number in array sumArr

API

  • Array

map

Map each element of array using a passed callback function.

import { map } from 'helpda'

const array = [1, 2, 3];
const mutiple = x => x * 2;

map(array, mutiple) //[2, 4, 6]

reduce

Reduce compute based on custom function and output the final value.

import { reduce } from 'helpda'

const array = [1, 2, 3];
const sum = (a, b) => a + b

reduce(sum, 0, array) // 6

flatten

flatten return a new one-level array from nested array

import { flatten } from 'helpda'

const array = [1, 2, 3, [4, 5, [6]]];

flatten(array)) // [1, 2, 3, 4, 5, 6]
  • Object

  • Functions

flip

return a new function with two reversed args

import { flip } from 'helpda'

const divide = (a, b) = a / b)
const flipped = flip((a, b) => a / b);

divide(12, 3) // 4
flipped(12, 3) // 0.25
  • Logic

  • Math

sum

sum two numbers

import { sum } from 'helpda'

sum(2, 2) // 4

subtract

subtract second arg from first

import { subtract } from 'helpda'

subtract(4, 2) // 2

multiple

multiple two numbers

import { multiple } from 'helpda'

multiple(2, 3) // 6

divide

divide two numbers

import { divide } from 'helpda'

divide(12, 3) // 4

inc

increment number

import { inc } from 'helpda'

inc(13) // 14

dec

decrement number

import { dec } from 'helpda'

dec(13) // 12

negate

negate number

import { dec } from 'helpda'

negate(13) // -13

sumArr

sum all number in an array of numbers

import { sumArr } from 'helpda'

const array = [1, 2, 3, 4, 5];

sumArr(array) // 15

randomN

get random number

import { randomN } from 'helpda'

const min = 0;
const max = 100;

randomN(min, max) // 12..85..3..?

Package Sidebar

Install

npm i helpda

Weekly Downloads

1

Version

1.0.7

License

MIT

Unpacked Size

9.71 kB

Total Files

25

Last publish

Collaborators

  • canmeepo