@add1ed/std-lib

0.6.1 • Public • Published

@add1ed/std-lib

A collection of useful functions, including minimised version of lodash and axios.

tl;dr

Use lodash functions:

const _ = require("@add1ed/std-lib");

const list = ["olives", "anchovies", "capers"];
const isVowel = x => "aeiou".includes(x);
const result = 
  _.pipe(
    _.filter(x => isVowel(x[0])),
    _.map(x => x.toUpperCase()),
    _.drop(1),
    _.first
  )(list);
console.log(result); // prints "ANCHOVIES"

Use axios:

const { axios } = require("@add1ed/std-lib");
axios.get("https://www.bbc.com/robots.txt")
  .then(resp => console.log(resp.data));

Use the LRU cache:

const { cache } = require("@add1ed/std-lib");

async function single() {
  let hits = 0;
  const fn = (id) => ({ id, hit: ++hits });
  const wrap = cache(x => x.id, fn);
  await wrap(3);
  await wrap(3);
  console.log(await wrap(1));
}

single(); // prints { id: 1, hit: 2 }

async function array() {
  let hits = 0;
  const inc = (id) => ({ id, hit: ++hits });
  const fn = xs => xs.map(inc);

  const wrap = cache(x => x.id, xs => xs.map(inc), { array: true });
  await wrap([4, 3]);
  await wrap([2, 4]);
  await wrap([2]);
  console.log(await wrap([2]));
}

array(); // prints [ { id: 2, hit: 3 } ]

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.6.10latest

Version History

VersionDownloads (Last 7 Days)Published
0.6.10
0.6.01
0.5.10
0.5.00
0.4.346
0.4.20
0.4.10
0.4.00
0.3.00
0.2.046
0.1.00

Package Sidebar

Install

npm i @add1ed/std-lib

Weekly Downloads

55

Version

0.6.1

License

ISC

Unpacked Size

151 kB

Total Files

13

Last publish

Collaborators

  • add1ed