Giter Club home page Giter Club logo

litus's Introduction

Logo

Litus

Commonly used utilities for JS and TS
Report Bug

Litus provides strongly-typed utils for:

  • Arrays: chunk, from, group, ...
  • Functions: apply, curry, unapply, ...
  • Math: mean, median, mod, ...
  • Object: copy, entries, merge, ...
  • Time: convert, format, setDayTime, ...

Installation

Using npm

npm i litus

Using yarn

yarn add litus

Usage

Import all utils

For ES6+ or Typescript

import * as ls from "litus";

For CommonJS

var ls = require("litus");

Import what you need only

import type { Literal, TimeFormat } from "litus";
import { arr, math, obj, Time } from "litus";

Contributing

Feel free to open an issue or fork this repo and create a pull request. Don't forget to give the project a star!

License

This package released under the MIT License.

litus's People

Contributors

estidlore avatar

Stargazers

 avatar

Watchers

 avatar

litus's Issues

Add math calculation

Description

Add a math util that computes an operation between quantities (scalar or vector)

Motivation

Calculate a given operation for any quantity (scalar or vector) combination.

Proposed Solution

Function math.calc that receives an opFn with n-sized number input and output number, and n quantities. It returns a quantity as follows:

  • If scalars only, return the calculation for the given scalars
  • All vectors should have the same length
  • If scalars and vectors, return a vector where each value is the calculation between the value v[i] of each input vector and each scalar

Additional Information

  • Use conditional return type to keep strict-typing.

Add function curry HOF

Description

Add function util that allows to a given function to receive arguments partially.

Motivation

Reuse specialized versions of functions and avoid duplication of params

Proposed Solution

Function func.curry that receives function fn and arity that is the params length. It returns a function that when receive all the params, it applies them to fn. Otherwise, curries a new function that applies the concatenation of the received params with the remaining ones.

Additional Information

Use infer to finely tune the resulting types

Split the utils each in its own file

Description

Each util function should be in its own file

Motivation

Some utils depends on others. An util "1" in file "A" can depend on an util "2" in file "B" and an util "3" in "B" depend on an util "4" in "A". Then, it could lead to dependency cycles between files "A" and "B".

Proposed Solution

Each util have its own file such as arr.chunk under arr/chunk.ts and export them in their original file index.ts

Additional Information

The imports must change too, to import directly instead of from their original index.ts.

Add object equal

Description

Add an object util to deeply compare if the given variables are equal

Motivation

Compare if two different objects have the same values

Proposed Solution

Function obj.equal that receives two or more variables and return their deep equal comparison

Add array sort

Description

Add array util that sorts elements by custom mapping to a sortable (number or string).

Motivation

Sort almost any array given a custom mapping function.

Proposed Solution

Function arr.sort that receives an arr and a mapFn that receives a single element and returns either a number or a string.

Additional Information

  • mapFn should return either number or string only (not number | string).
  • Avoid localCompare for it depends on user's location.

Add array union

Description

Add an array util to get the union set of given arrays

Motivation

Get all elements in given arrays without duplicates

Proposed Solution

Function arr.unique that receives some arrays and returns a Set of the concatenated elements of the arrays.

Add funcion apply & unapply HOFs

Description

Add function utils that converts a function from receiving args to arg tuple and viceversa.
Example: from (arg1: number, arg2: boolean, ..., argn: string) to ([number, boolean, ..., string])

Motivation

Use array as input for functions with several args and viceversa.

Proposed Solution

Functions func.apply for "spread to array" and func.unapply for "array to spread"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.