npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pbsl

v0.1.0

Published

Functional library for manipulation of pairs-based data structures with Sass-like API

Downloads

63

Readme

Pairs based structures library

Functional library for manipulation of pairs-based data structures with Sass-like API. Original ideas from SICP.

Library for study. Not for production projects.

About

The library contains 3 data structures and functions for working with them. Key features:

  • creation and manipulation occur using functions
  • objects are not used
  • structures are immutable

Functions for creating are called constructors. Functions for getting data are called selectors.

The library consists of the following structures:

  • pair
  • list
  • map

All structures based on pairs.

Pair

Pair is simple structure that consist of 2 any type elements. Pair may contain other pairs.

import { pair, fir, sec, toString } from 'pbsl/pair';

const myPair = pair(1, 2);
const nestedPair = pair('testou', myPair);

fir(myPair) // 1
sec(myPair) // 2

toString(myPair) // (1, 2)
toString(nestedPair) // (testou, (1, 2))

List

The list is an orderly sequence of any elements. By default, the list are typed by first item. Also you can specify the type manually.

import { pair } from 'pbsl/pair';
import { l, top, tail, toString, prepand } from 'pbsl/list';

const myList = l(2, 5, 6);
const pairInList = l<unknown>(pair(1, 0), 'item', 'end');

top(myList) // 2
tail(myList) // l(5, 6)
prepand(myList, 0) // (0, 2, 5, 6)
toString(myList) // (2, 5, 6)
toString(pairInList) // ((1, 0), item, end)

Under the hood, list is a nested pairs where second element of last pair is a null. Empty list also is null.

l(2, 5, 6) // pair(2, pair(5, pair(6, null)))

Manipulation

For working with the lists are available some functions with Sass-like API:

  • append
  • index
  • join
  • length
  • nth
  • setNth

And main functions for working with sequences with js Array-like API:

  • map
  • filter
  • reduce
  • find
  • findIndex

Map

Map is a list of pairs in the 'key-value' format. The map is created based on array with a tuples with 2 elements: key and value. Typed like a list with ability to specify a types.

import { mkMap, get, set } from 'pbsl/map';
import { toString } from 'pbsl/list';

const myMap = mkMap([['name', 'mister'], ['age', '54']]);
const codes = mkMap([[200, 'ok'], [403, 'forbidden'], [404, 'not found']]);

toString(myMap) // ((name, mister), (age, 54))
get(myMap, 'name') // 'mister'
toString(set(myMap, 'race', 'human')) // ((race, human), (name, mister), (age, 54))

For working with maps also used Sass-like API. The following functions are available:

  • get
  • set
  • has
  • remove
  • merge
  • keys
  • values

Installation

npm i -D pbsl

License

MIT