New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pico-lambda

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pico-lambda - npm Package Compare versions

Comparing version 1.0.1 to 1.0.3

2

package.json
{
"name": "pico-lambda",
"version": "1.0.1",
"version": "1.0.3",
"description": "native functional js",

@@ -5,0 +5,0 @@ "main": "dist/pico-lambda.js",

@@ -37,7 +37,8 @@ <h1 align="center">pico-lambda</h1>

- **Pico:** weighs less than 460 bytes gzipped.
- **Useful:** takes most native JavaScript array methods and makes them immutable, curried, and composable.
- **Familiar:** same names just curried and composable [JavaScript Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)..
- **Useful:** takes most native JavaScript array methods and makes them *immutable*, *curried*, and *composable*.
- **Familiar:** same names just curried and composable [JavaScript Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).
- **Degrades Gracefully:** a small set of these functions are not available in every browser. When not available in the browser it will not be available in Pico Lambda.
> Pico-lambda was made for the ES2015 Javascript Runtime. It has no dependencies.
> Pico-lambda was made for the ES2015 Javascript Runtime. It has __no dependencies__.
* * *

@@ -44,0 +45,0 @@

@@ -27,2 +27,2 @@

if (typeof window !== 'undefined') window.PicoLambda = lambda;
else module.exports = lambda;
if (module) module.exports = lambda;

@@ -1,6 +0,2 @@

const { describe, it, expect, PicoLambda } = init();
const { compose, concat, copyWithin, entries, every, fill, filter, find,
findIndex, includes, indexOf, join, keys, lastIndexOf, map, pipe,
pop, push, reduce, reduceRight, reverse, shift, slice, splice, some,
sort, toLocaleString: tls, toString, unshift } = PicoLambda;
const { describe, it, expect, PicoLambda: PL } = init();

@@ -30,6 +26,6 @@ function init () {

describe('api: concat', () => {
if (!concat) return;
if (!PL.concat) return;
it('should add array of items to end of array', () => {
const arrayOne = [1, 2, 3];
const addTwo = concat([4, 5]);
const addTwo = PL.concat([4, 5]);
const result = (addTwo(arrayOne));

@@ -41,3 +37,3 @@ expect(result).toEqual([1, 2, 3, 4, 5]);

const arrayOne = [3, 2];
const addOne = concat(1);
const addOne = PL.concat(1);
const result = (addOne(arrayOne));

@@ -49,3 +45,3 @@ expect(result).toEqual([3, 2, 1]);

const arrayOne = [3, 2];
const addOne = concat(1);
const addOne = PL.concat(1);
(addOne(arrayOne));

@@ -57,6 +53,6 @@ expect(arrayOne).toEqual([3, 2]);

describe('api: copyWithin', () => {
if (!copyWithin) return;
if (!PL.copyWithin) return;
it('should overwrite from target to end of array with selected elements', () => {
var arr = [1, 2, 3, 4, 5];
const result = copyWithin(3, 1)(arr);
const result = PL.copyWithin(3, 1)(arr);
expect(result).toEqual([1, 2, 3, 2, 3]);

@@ -66,3 +62,3 @@ });

var arr = [1, 2, 3, 4, 5];
const result = copyWithin(3, 1, 2)(arr);
const result = PL.copyWithin(3, 1, 2)(arr);
expect(result).toEqual([1, 2, 3, 2, 5]);

@@ -72,3 +68,3 @@ });

var arr = [1, 2, 3, 4, 5];
copyWithin(3, 1, 2)(arr);
PL.copyWithin(3, 1, 2)(arr);
expect(arr).toEqual([1, 2, 3, 4, 5]);

@@ -79,6 +75,6 @@ });

describe('api: entries', () => {
if (!entries) return;
if (!PL.entries) return;
it('should return an interator that contains key values pair of given array', () => {
const arr = [1, 2, 3, 4, 5];
const iterator = entries(arr);
const iterator = PL.entries(arr);
expect(iterator.next()).toEqual({ value: [0, 1], done: false });

@@ -88,3 +84,3 @@ });

const arr = [1, 2, 3, 4, 5];
const iterator = entries(arr);
const iterator = PL.entries(arr);
iterator.next();

@@ -97,6 +93,6 @@ iterator.next();

describe('api: every', () => {
if (!every) return;
if (!PL.every) return;
it('should return false if any items do not pass predicate', () => {
const arr = [1, 2, 3, 4, 5];
const areAllAreLessThanFour = every(x => x < 4);
const areAllAreLessThanFour = PL.every(x => x < 4);
const result = (areAllAreLessThanFour(arr));

@@ -108,3 +104,3 @@ expect(result).toEqual(false);

const arr = [1, 2, 3];
const areAllAreLessThanFour = every(x => x < 4);
const areAllAreLessThanFour = PL.every(x => x < 4);
const result = (areAllAreLessThanFour(arr));

@@ -116,3 +112,3 @@ expect(result).toEqual(true);

const arr = [1, 2, 3];
const areAllAreLessThanFour = every(x => x < 4);
const areAllAreLessThanFour = PL.every(x => x < 4);
(areAllAreLessThanFour(arr));

@@ -124,6 +120,6 @@ expect(arr).toEqual([1, 2, 3]);

describe('api: fill', () => {
if (!fill) return;
if (!PL.fill) return;
it('should overwrite each element of an array with supplied param', () => {
var arr = [1, 2, 3, 4, 5];
const result = fill(1)(arr);
const result = PL.fill(1)(arr);
expect(result).toEqual([1, 1, 1, 1, 1]);

@@ -133,3 +129,3 @@ });

var arr = [1, 2, 3, 4, 5];
const result = fill(1, 2, 4)(arr);
const result = PL.fill(1, 2, 4)(arr);
expect(result).toEqual([1, 2, 1, 1, 5]);

@@ -139,3 +135,3 @@ });

var arr = [1, 2, 3, 4, 5];
fill(1)(arr);
PL.fill(1)(arr);
expect(arr).toEqual([1, 2, 3, 4, 5]);

@@ -146,6 +142,6 @@ });

describe('api: filter', () => {
if (!filter) return;
if (!PL.filter) return;
it('should return items that pass the predicate', () => {
const arr = [1, 2, 3, 4, 5];
const numsUnderThree = filter(x => x < 3);
const numsUnderThree = PL.filter(x => x < 3);
const result = (numsUnderThree(arr));

@@ -156,3 +152,3 @@ expect(result).toEqual([1, 2]);

const arr = [1, 2, 3, 4, 5];
const numsUnderThree = filter(x => x < 3);
const numsUnderThree = PL.filter(x => x < 3);
(numsUnderThree(arr));

@@ -164,6 +160,6 @@ expect(arr).toEqual([1, 2, 3, 4, 5]);

describe('api: find', () => {
if (!find) return;
if (!PL.find) return;
it('should return first item that passes the predicate', () => {
const arr = [1, 2, 3, 4, 5];
const isThree = find(x => x === 3);
const isThree = PL.find(x => x === 3);
const result = (isThree(arr));

@@ -174,3 +170,3 @@ expect(result).toEqual(3);

const arr = [1, 2, 3, 4, 5];
const isThree = find(x => x === 8);
const isThree = PL.find(x => x === 8);
const result = (isThree(arr));

@@ -181,3 +177,3 @@ expect(result).toEqual(undefined);

const arr = [1, 2, 3, 4, 5];
const isThree = find(x => x === 3);
const isThree = PL.find(x => x === 3);
(isThree(arr));

@@ -189,6 +185,6 @@ expect(arr).toEqual([1, 2, 3, 4, 5]);

describe('api: findIndex', () => {
if (!findIndex) return;
if (!PL.findIndex) return;
it('should return index of first item that passes the predicate', () => {
const arr = [1, 2, 3, 4, 5];
const gtThree = findIndex(x => x > 3);
const gtThree = PL.findIndex(x => x > 3);
const result = gtThree(arr);

@@ -200,3 +196,3 @@ expect(result).toEqual(3);

const arr = [1, 2, 3, 4, 5];
const gtThree = findIndex(x => x > 80);
const gtThree = PL.findIndex(x => x > 80);
const result = gtThree(arr);

@@ -207,3 +203,3 @@ expect(result).toEqual(-1);

const arr = [1, 2, 3, 4, 5];
const gtThree = findIndex(x => x > 80);
const gtThree = PL.findIndex(x => x > 80);
gtThree(arr);

@@ -215,6 +211,6 @@ expect(arr).toEqual([1, 2, 3, 4, 5]);

describe('api: includes', () => {
if (!includes) return;
if (!PL.includes) return;
it('should return true when an item is found in array', () => {
const arr = [1, 2, 3, 4, 5];
const isThree = includes(3);
const isThree = PL.includes(3);
const result = isThree(arr);

@@ -226,3 +222,3 @@ expect(result).toEqual(true);

const arr = [1, 2, 3, 4, 5];
const isThree = includes(8);
const isThree = PL.includes(8);
const result = isThree(arr);

@@ -233,3 +229,3 @@ expect(result).toEqual(false);

const arr = [1, 2, 3, 4, 5];
const isThree = includes(8);
const isThree = PL.includes(8);
isThree(arr);

@@ -241,6 +237,6 @@ expect(arr).toEqual([1, 2, 3, 4, 5]);

describe('api: indexOf', () => {
if (!indexOf) return;
if (!PL.indexOf) return;
it('should return the indexOf item', () => {
const arr = [1, 2, 3, 4, 5];
const result = indexOf(3)(arr);
const result = PL.indexOf(3)(arr);
expect(result).toEqual(2);

@@ -250,3 +246,3 @@ });

const arr = [1, 2, 3, 4, 5, 3];
const result = indexOf(3, 3)(arr);
const result = PL.indexOf(3, 3)(arr);
expect(result).toEqual(5);

@@ -256,3 +252,3 @@ });

const arr = [1, 2, 3, 4, 5];
indexOf(3)(arr);
PL.indexOf(3)(arr);
expect(arr).toEqual([1, 2, 3, 4, 5]);

@@ -263,6 +259,6 @@ });

describe('api: join', () => {
if (!join) return;
if (!PL.join) return;
it('should return a string with each item separated with character passed in', () => {
var arr = [1, 2, 3, 4, 5];
const separateByDash = join('-');
const separateByDash = PL.join('-');
const result = separateByDash(arr);

@@ -273,3 +269,3 @@ expect(result).toEqual('1-2-3-4-5');

var arr = [1, 2, 3, 4, 5];
const separateByDash = join('-');
const separateByDash = PL.join('-');
separateByDash(arr);

@@ -281,6 +277,6 @@ expect(arr).toEqual([1, 2, 3, 4, 5]);

describe('api: keys', () => {
if (!keys) return;
if (!PL.keys) return;
it('should return an iterator of keys of given array', () => {
const arr = [1, 2, 3, 4, 5];
const iterator = keys(arr);
const iterator = PL.keys(arr);
expect(iterator.next()).toEqual({ value: 0, done: false });

@@ -290,3 +286,3 @@ });

const arr = [1, 2, 3, 4, 5];
const iterator = keys(arr);
const iterator = PL.keys(arr);
iterator.next();

@@ -299,6 +295,6 @@ iterator.next();

describe('api: lastIndexOf', () => {
if (!lastIndexOf) return;
if (!PL.lastIndexOf) return;
it('should find the index of the last occurrence of an element', () => {
var arr = [1, 2, 3, 1];
const result = lastIndexOf(1)(arr);
const result = PL.lastIndexOf(1)(arr);
expect(result).toEqual(3);

@@ -308,3 +304,3 @@ });

var arr = [1, 2, 3, 1];
const result = lastIndexOf(1, -2)(arr);
const result = PL.lastIndexOf(1, -2)(arr);
expect(result).toEqual(0);

@@ -314,3 +310,3 @@ });

var arr = [1, 2, 3, 1];
lastIndexOf(1)(arr);
PL.lastIndexOf(1)(arr);
expect(arr).toEqual([1, 2, 3, 1]);

@@ -321,5 +317,5 @@ });

describe('api: map', () => {
if (!map) return;
if (!PL.map) return;
it('applies function to items in array', () => {
const double = map(x => x * 2);
const double = PL.map(x => x * 2);
const result = double([1, 2, 3]);

@@ -330,3 +326,3 @@ expect(result).toEqual([2, 4, 6]);

var arr = [1, 2, 3];
const double = map(x => x * 2);
const double = PL.map(x => x * 2);
double(arr);

@@ -338,5 +334,5 @@ expect(arr).toEqual([1, 2, 3]);

describe('api: reduce', () => {
if (!reduce) return;
if (!PL.reduce) return;
it('applies function to each item and accums results from left to right', () => {
const sum = reduce((acc, val) => acc + val, 99);
const sum = PL.reduce((acc, val) => acc + val, 99);
const total = sum([2, 3, 4]);

@@ -347,3 +343,3 @@ expect(total).toEqual(108);

var arr = [2, 3, 4];
const sum = reduce((acc, val) => acc + val, 99);
const sum = PL.reduce((acc, val) => acc + val, 99);
sum(arr);

@@ -355,5 +351,5 @@ expect(arr).toEqual([2, 3, 4]);

describe('api: reduce right', () => {
if (!reduceRight) return;
if (!PL.reduceRight) return;
it('applies function to each item and accums results from right to left', () => {
const sum = reduceRight((acc, val) => acc - val, 99);
const sum = PL.reduceRight((acc, val) => acc - val, 99);
const total = sum([2, 3, 4]);

@@ -364,3 +360,3 @@ expect(total).toEqual(90);

var arr = [2, 3, 4];
const sum = reduceRight((acc, val) => acc - val, 99);
const sum = PL.reduceRight((acc, val) => acc - val, 99);
sum(arr);

@@ -372,5 +368,5 @@ expect(arr).toEqual([2, 3, 4]);

describe('api: slice', () => {
if (!slice) return;
if (!PL.slice) return;
it('returns new but sliced array', () => {
const removeFirst = slice(1);
const removeFirst = PL.slice(1);
const result = removeFirst([2, 3, 4]);

@@ -381,3 +377,3 @@ expect(result).toEqual([3, 4]);

var arr = [2, 3, 4];
const removeFirst = slice(1);
const removeFirst = PL.slice(1);
removeFirst(arr);

@@ -389,6 +385,6 @@ expect(arr).toEqual([2, 3, 4]);

describe('api: some', () => {
if (!some) return;
if (!PL.some) return;
it('should return true if at least one items passes predicate', () => {
const arr = [1, 2, 3, 4, 5];
const areAllAreLessThanFour = some(x => x < 4);
const areAllAreLessThanFour = PL.some(x => x < 4);
const result = areAllAreLessThanFour(arr);

@@ -399,3 +395,3 @@ expect(result).toEqual(true);

const arr = [1, 2, 3, 4, 5];
const areAllAreLessThanFour = some(x => x < 4);
const areAllAreLessThanFour = PL.some(x => x < 4);
(areAllAreLessThanFour(arr));

@@ -407,6 +403,6 @@ expect(arr).toEqual([1, 2, 3, 4, 5]);

describe('api: reverse', () => {
if (!reverse) return;
if (!PL.reverse) return;
it('should return array reversed', () => {
const arr = [1, 2, 3, 4, 5];
const result = reverse(arr);
const result = PL.reverse(arr);
expect(result).toEqual([5, 4, 3, 2, 1]);

@@ -416,3 +412,3 @@ });

const arr = [1, 2, 3, 4, 5];
reverse(arr);
PL.reverse(arr);
expect(arr).toEqual([1, 2, 3, 4, 5]);

@@ -423,6 +419,6 @@ });

describe('api: toString', () => {
if (!toString) return;
if (!PL.toString) return;
it('should return string representation of array', () => {
const arr = [1, 2, 3, 4, 5];
const result = toString(arr);
const result = PL.toString(arr);
expect(result).toEqual('1,2,3,4,5');

@@ -432,3 +428,3 @@ });

const arr = [1, 2, 3, 4, 5];
toString(arr);
PL.toString(arr);
expect(arr).toEqual([1, 2, 3, 4, 5]);

@@ -439,7 +435,7 @@ });

describe('api: toLocaleString', () => {
if (!tls) return;
if (!PL.toLocaleString) return;
it('should match standard array toLocaleString output', () => {
var testDate = new Date();
const arr = ['not changing', 1234567890.12, testDate];
const result = tls()(arr);
const result = PL.toLocaleString()(arr);
expect(result).toEqual(arr.toLocaleString());

@@ -449,3 +445,3 @@ });

var prices = ['¥7', 500, 8123, 12];
const result = tls('ja-JP', { style: 'currency', currency: 'JPY' })(prices);
const result = PL.toLocaleString('ja-JP', { style: 'currency', currency: 'JPY' })(prices);
expect(result).toEqual(prices.toLocaleString('ja-JP', { style: 'currency', currency: 'JPY' }));

@@ -456,3 +452,3 @@ });

const arr = ['not changing', 1234567890.12, testDate];
tls()(arr);
PL.toLocaleString()(arr);
expect(arr).toEqual(['not changing', 1234567890.12, testDate]);

@@ -463,6 +459,6 @@ });

describe('api: splice', () => {
if (!splice) return;
if (!PL.splice) return;
it('Should remove requested elements', () => {
const arr = [1, 2, 3, 4, 5];
const result = splice(2)(arr);
const result = PL.splice(2)(arr);
expect(result).toEqual([1, 2]);

@@ -472,3 +468,3 @@ });

const arr = [1, 2, 3, 4, 5];
const result = splice(1, 2)(arr);
const result = PL.splice(1, 2)(arr);
expect(result).toEqual([1, 4, 5]);

@@ -478,3 +474,3 @@ });

const arr = [1, 2, 3, 4, 5];
const result = splice(1, 3, 20, 21)(arr);
const result = PL.splice(1, 3, 20, 21)(arr);
expect(result).toEqual([1, 20, 21, 5]);

@@ -484,3 +480,3 @@ });

const arr = [1, 2, 3, 4, 5];
splice(2)(arr);
PL.splice(2)(arr);
expect(arr).toEqual([1, 2, 3, 4, 5]);

@@ -491,6 +487,6 @@ });

describe('api: push', () => {
if (!push) return;
if (!PL.push) return;
it('should add element to end of array', () => {
const arr = [1, 2, 3, 4, 5];
const result = push(6)(arr);
const result = PL.push(6)(arr);
expect(result).toEqual([1, 2, 3, 4, 5, 6]);

@@ -500,3 +496,3 @@ });

const arr = [1, 2, 3, 4, 5];
push(6)(arr);
PL.push(6)(arr);
expect(arr).toEqual([1, 2, 3, 4, 5]);

@@ -507,6 +503,6 @@ });

describe('api: pop', () => {
if (!pop) return;
if (!PL.pop) return;
it('should remove last element from array', () => {
const arr = [1, 2, 3, 4, 5];
const result = pop(arr);
const result = PL.pop(arr);
expect(result).toEqual([1, 2, 3, 4]);

@@ -516,3 +512,3 @@ });

const arr = [1, 2, 3, 4, 5];
pop(arr);
PL.pop(arr);
expect(arr).toEqual([1, 2, 3, 4, 5]);

@@ -523,6 +519,6 @@ });

describe('api: shift', () => {
if (!shift) return;
if (!PL.shift) return;
it('should remove first element from array', () => {
const arr = [1, 2, 3, 4, 5];
const result = shift(arr);
const result = PL.shift(arr);
expect(result).toEqual([2, 3, 4, 5]);

@@ -532,3 +528,3 @@ });

const arr = [1, 2, 3, 4, 5];
shift(arr);
PL.shift(arr);
expect(arr).toEqual([1, 2, 3, 4, 5]);

@@ -539,5 +535,5 @@ });

describe('api: unshift', () => {
if (!unshift) return;
if (!PL.unshift) return;
it('should add single item to front of array', () => {
const addOne = unshift(1);
const addOne = PL.unshift(1);
const result = addOne([2, 3]);

@@ -548,3 +544,3 @@ expect(result).toEqual([1, 2, 3]);

var arr = [2, 3];
const addOne = unshift(1);
const addOne = PL.unshift(1);
addOne(arr);

@@ -556,7 +552,7 @@ expect(arr).toEqual([2, 3]);

describe('api: sort', () => {
if (!sort) return;
if (!PL.sort) return;
it('should sort array based on comparator', () => {
var arr = [20, 1, 3, 4, 2];
const numComp = (a, b) => (a < b) ? -1 : (a === b) ? 0 : 1;
const sortBy = sort(numComp);
const sortBy = PL.sort(numComp);
const result = sortBy(arr);

@@ -568,3 +564,3 @@ expect(result).toEqual([1, 2, 3, 4, 20]);

const numComp = (a, b) => (a < b) ? -1 : (a === b) ? 0 : 1;
const sortBy = sort(numComp);
const sortBy = PL.sort(numComp);
sortBy(arr);

@@ -581,24 +577,24 @@ expect(arr).toEqual([20, 1, 3, 4, 2]);

it('should compose multiple functions and run them from right to left', () => {
compose(
map(x => x + 1),
PL.compose(
PL.map(x => x + 1),
is([3]),
map(x => x + 1),
PL.map(x => x + 1),
is([2]),
map(x => x + 1),
PL.map(x => x + 1),
is([1]),
map(x => x + 1)
PL.map(x => x + 1)
)([0]);
});
it('compose ( reduce <- map <- filter <- concat <- cons )', () => {
compose(
PL.compose(
is(42),
reduce((acc, val) => val + acc),
PL.reduce((acc, val) => val + acc),
is([12, 14, 16]),
map(x => x * 2),
PL.map(x => x * 2),
is([6, 7, 8]),
filter(x => x > 5),
PL.filter(x => x > 5),
is([0, 1, 2, 3, 4, 5, 6, 7, 8]),
concat([6, 7, 8]),
PL.concat([6, 7, 8]),
is([0, 1, 2, 3, 4, 5]),
unshift(0),
PL.unshift(0),
is([1, 2, 3, 4, 5])

@@ -609,7 +605,7 @@ )([1, 2, 3, 4, 5]);

var arr = [0];
compose(
map(x => x + 1),
map(x => x + 1),
map(x => x + 1),
map(x => x + 1)
PL.compose(
PL.map(x => x + 1),
PL.map(x => x + 1),
PL.map(x => x + 1),
PL.map(x => x + 1)
)(arr);

@@ -626,24 +622,24 @@ expect(arr).toEqual([0]);

it('should pipe multiple functions and run them from left to right', () => {
pipe(
map(x => x + 1),
PL.pipe(
PL.map(x => x + 1),
is([1]),
map(x => x + 1),
PL.map(x => x + 1),
is([2]),
map(x => x + 1),
PL.map(x => x + 1),
is([3]),
map(x => x + 1)
PL.map(x => x + 1)
)([0]);
});
it('pipe ( cons -> concat -> filter -> map -> reduce )', () => {
pipe(
PL.pipe(
is([1, 2, 3, 4, 5]),
unshift(0),
PL.unshift(0),
is([0, 1, 2, 3, 4, 5]),
concat([6, 7, 8]),
PL.concat([6, 7, 8]),
is([0, 1, 2, 3, 4, 5, 6, 7, 8]),
filter(x => x > 5),
PL.filter(x => x > 5),
is([6, 7, 8]),
map(x => x * 2),
PL.map(x => x * 2),
is([12, 14, 16]),
reduce((acc, val) => val + acc),
PL.reduce((acc, val) => val + acc),
is(42)

@@ -654,7 +650,7 @@ )([1, 2, 3, 4, 5]);

var arr = [0];
pipe(
map(x => x + 1),
map(x => x + 1),
map(x => x + 1),
map(x => x + 1)
PL.pipe(
PL.map(x => x + 1),
PL.map(x => x + 1),
PL.map(x => x + 1),
PL.map(x => x + 1)
)(arr);

@@ -661,0 +657,0 @@ expect(arr).toEqual([0]);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc