1.0.7 • Published 5 years ago

helpda v1.0.7

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

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?

TypeActionFunction
Arraychange every valuemap
compute based on custom function and output the final valuereduce
flatten return a one-dimensional array, remove nestingflatten
Objectchange every valuemap
Functionsmemoizememoize
revers function argsflip
Logic
Mathsum two numberssum
subtract two numberssubtract
multiple two numbersmultiple
divide two numbersdivide
increment numberinc
decrement numberdec
negate numbernegate
get random number between two argsrandomN
sum all number in arraysumArr

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..?
1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago