Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

bjorn

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bjorn

Björn is a JavaScript native array pattern matcher that uses predicates to find sequences within sequences. It gives you practical and no-bloat no-bullshit pattern matching over arrays.

latest
npmnpm
Version
0.0.23
Version published
Maintainers
1
Created
Source

Björn Pattern Matching

Björn is a JavaScript native array pattern matcher that uses predicates to find sequences within sequences. It gives you practical and no-bloat no-bullshit pattern matching over arrays.

Installation

npm install bjorn

Usage

const bjorn = require("bjorn");

Examples

Björn finds arrays within arrays:

const bjorn = require("bjorn")

const p0 = x => x === 0;
const p1 = x => x === 1;
const p2 = x => x === 2;

const seq = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

bjorn(seq)(
    [ p0, p1, p2, (p0, tail) => console.log(p0, tail)]
);
// 0, [3, 4, 5, 6, 7, 8, 9]

Björn can find them with or without seeking:

const one = x => x === 1;
const two = x => x === 2;

// default (start at input 0)
const onetwo = bjorn([0, 0, 0, 0, 1, 2, 3, 4])(
    [ one, two (a, b, tail) => [a, b]]
);
// undefined

// seek:true means read input until a match is found
const onetwo = bjorn([0, 0, 0, 0, 1, 2, 3, 4], { seek:true })(
    [ one, two (a, b, tail) => [a, b]]
);
// [1, 2]

FAQs

Package last updated on 12 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts