• Stars
    star
    262
  • Rank 153,107 (Top 4 %)
  • Language
    TypeScript
  • License
    Other
  • Created over 8 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An extremely small, intuitive and fast functional utility library for JavaScript

pareto.js

An extremely small, intuitive and fast functional utility library for JavaScript

  • Only 14 core functions
  • Written in TypeScript
  • Encourages immutability
  • Only pure functions (no side-effects)
  • Smaller than lodash

build downloads npm

Example

import { flatten, tail } from 'paretojs'

flatten([1, 2, [3, 4], 5]) // [1, 2, 3, 4, 5]
tail([1, 2, 3]) // [2, 3]

Installation

To install the stable version:

npm install --save paretojs

This assumes that you’re using npm with a module bundler like Webpack

How

ES2015 or TypeScript:

import _ from 'paretojs'

or

import { chunk, debounce } from 'paretojs'

CommonJS:

var _ = require('paretojs');

or

var chunk = require('paretojs').chunk;
var debounce = require('paretojs').debounce;

UMD:

<script src="https://unpkg.com/paretojs/dist/paretojs.min.js"></script>

API

chunk

Returns the chunk of an array based on an integer n

import { chunk } from 'paretojs';

chunk([1,2,3,4,5,6,7], 3); // [ [1,2,3], [4,5,6], [7] ]

compose

Gets a composed function

import { compose } from 'paretojs';

const toUpperCase = x => x.toUpperCase();
const exclaim = x => x + '!!!';

const angry = compose(toUpperCase, exclaim);

angry('stop'); // 'STOP!!!

curry

Gets a curried function

import { curry } from 'paretojs';

const add = (x, y) => x + y;

curry(add, 1, 2); // 3
curry(add)(1)(2); // 3
curry(add)(1, 2); // 3
curry(add, 1)(2); // 3

debounce

Creates and returns a new debounced version of the passed function which will postpone its execution until after wait milliseconds have elapsed since the last time it was invoked.

import { debounce } from 'paretojs';

let a = 1;
const fn = () => a = 42;

const debounce = debounce(fn, 500);
debounce();

console.log(a); // 1 before 500ms

setTimeout(() => {
  console.log(a); // 42 after 500ms
}, 600)

deepCopy

Creates a deep copy of an object

import { deepCopy } from 'paretojs';

const object = {
  a: 1,
  b: 2,
  c: {
    d: 3,
  },
};

deepCopy(object); // { a: 1, b: 2, c: { d: 3} }

flatMap

Generates a flattened array by iterating through a collection and applying a function to each element

import { flatMap } from 'paretojs';

const inc = n => n + 1;
flatMap([1, 2, 3], inc)); // [2, 3, 4]

const dup = n => [n, n];
flatMap([1, 2, 3], dup)); // [1, 1, 2, 2, 3, 3]

const sq = n => n ** 2;
flatMap([1, 2, 3], sq)) // [1, 4, 9]

flatten

Flattens (recursively) an array

import { flatten } from 'paretojs';

flatten([1, [2, 3], 4]); // [1, 2, 3, 4]

get

Gets the value of an object property based on a string path provided. If the property is not found, the defaultValues is returned

import { get } from 'paretojs';

get({ a: 1 }, "a")); // 1
get({ a: 1 }, "b", "default")); // "default"
get({ a: { b: 2 } }, "a")); // { b: 2 }
get({ a: { b: 2 } }, "a.b")); // 2
get({ a: { b: 2 } }, "a.c")); // undefined

matches

Checks if an objects matches with some properties

import { matches } from 'paretojs';

const object1 = { a: 1, b: 2 };

matches(object1, { a: 1 }); // true
matches(object1, { a: 1, b: 2 }); // true
matches(object1, { a: 3 }); // false

memoize

Creates a function that memoizes (caches) the result

import { memoize } from 'paretojs';

let count = 0;

const square = x => {
  count = count + 1;
  return x * x;
};

const memoSquare = memoize(square);

count; // 0
memoSquare(10); // 100
memoSquare(10); // 100
memoSquare(10); // 100
count; // 1

pipe

Creates and returns a new function that performs a left-to-right function composition.

import { pipe } from 'paretojs';

const increment = x => x + 1;
const decrement = x => x - 1;

const piped = pipe(increment, increment, decrement);
piped(0); // 1

prop

Gets the property of an object

import { prop } from 'paretojs';

const object = {
  label: 'custom label',
};

prop('label', object); // custom label

sort

Sorts a collection based on a property

import { sort } from 'paretojs';

const collection = [
  {
    id: 2,
  },
  {
    id: 1,
  },
];

sort(collection, 'id'); // [{ id: 1 }, { id: 2 }]

tail

Gets all, except the first element of an array.

import { tail } from 'paretojs';

tail([1, 2, 3]); // [2, 3]

Misc

If you want to add a new function, please open an issue and explain why.

Docs

More Repositories

1

canarinho

Utilitários Android para padrões Brasileiros
Java
178
star
2

qa-studyguide

175
star
3

front-end-guide

151
star
4

kappuccino

A kotlin library to simplify how to do espresso tests on Android.
Kotlin
111
star
5

android-studyguide

74
star
6

requestmatcher

A simple and powerful way for making programatic assertions in your fake API
Java
44
star
7

recrutamento-fe

Página do teste para o recrutamento de novos Front-Ends da Concrete Solutions
34
star
8

sunomono

A simple gem to generate all files needed in a project that will support Cucumber, Calabash Android and Calabash IOS and Appium Android and IOS.
Ruby
32
star
9

ng-security

A security module for AngularJS.
JavaScript
31
star
10

ios-recruiting-brazil

Desafio iOS da Concrete
30
star
11

yosef-android

An Android implementation of the Yosef protocol for dynamic views from the Backend
Kotlin
25
star
12

desafio-java

25
star
13

desafio-android

22
star
14

qa-automation-samples

Repository with examples of automation tools used by Concrete QAs
Java
22
star
15

magneton

A simple gem to generate all files needed in a project that will support Cucumber, SitePrism, Capybara and Selenium.
Ruby
17
star
16

qa-recruiting-brazil

Repositório com o desafio do Processo Seletivo para QA na Concrete
12
star
17

yosef-ios

yosef-ios
Swift
11
star
18

concrete_project_template

Concrete Project Template
Kotlin
9
star
19

tecla-sap

JavaScript
8
star
20

java-studyguide

7
star
21

java-recruiting-hsa

Java Recruiting Code Challenge for HSA
6
star
22

treinamentos-android

Conjunto de treinamentos Android
Java
4
star
23

cesta-basica

JavaScript
4
star
24

cs-dotnet-training

Estudo sobre .NET Core
C#
4
star
25

mock-api

Java
4
star
26

concrete_android_community

Reune referências técnicas de Android com análises, comparações entre bibliotecas, padrões de projetos e recomendações técnicas.
2
star
27

api-coupons-hsa

Coupons API for HSA Code Challenges
JavaScript
2
star
28

modern-js-guide

The Modern JavaScript Guide
2
star
29

ComposeKmmMoviesApp

Kotlin
2
star
30

frontend-recruiting-hsa

2
star
31

ios-recruiting-hsa

2
star
32

qa-recruiting-hsa

1
star
33

api-categories-hsa

Categories API for HSA Code Challenges
JavaScript
1
star
34

cs-links-api

Slack integrations for slash-command
JavaScript
1
star
35

desafio-node-espanol

Desafio de Node.js en castellano.
1
star
36

external-ios-recruiting-brazil

1
star
37

gotic

Go Terminal Interface Commander
Go
1
star
38

android-recruiting-hsa

Android Recruiting Code Challenge for HSA
1
star