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

storable-functions

v0.6.3

Published

Storable and executable functions

Downloads

56

Readme

Storable functions

GitHub npm npm

Storable and executable functions using array based simple syntax and functional programming.

Getting Started

Installation

  npm install storable-functions

Run tests

  npm run-script test

Example usage

Basic sample

  const { resolve } = require('storable-functions')

  const operation = [ '+', 3, 4 ] // (3 + 4)

  console.log(resolve(operation))
  // output: 7

Nested sample

  const operation = [ 'mod', ['+', 3, 7], 3 ] // (3 + 7) % 3
  console.log(resolve(operation))
  // output: 1

Higher order sample

  const operation = [
    'map', // map function
    'num', // argument variable name
    [ '+', 3, [ 'arg', 'num' ] ], // lambda
    ['array', 1, 2, 3] // data
  ]

  /* In js:
    [1, 2, 3].map(num => num + 3)
  */

  console.log(resolve(operation))

  // output: [4, 5, 6]

Operations

Math module

| Operation | Token | Params | Sample | Output | |:--------------------|:-----------:|:------------------------------|:------------------------------|:--------| | Sum | + | x: Number, y: Number | ["+", 3, 4] | 7 | | Subtraction | - | x: Number, y: Number | ["-", 9, 4] | 5 | | Multiplication | * | x: Number, y: Number | ["*", 2, 7] | 14 | | Division | / | x: Number, y: Number | ["/", 6, 3] | 2 | | Module | mod | x: Number, y: Number | ["mod", 4, 3] | 1 | | Absolute value | abs | x: Number | ["abs", -4] | 4 | | Floor | floor | x: Number | ["floor", 7.2] | 7 | | Ceil | ceil | x: Number | ["ceil", 7.2] | 8 | | Trunc | trunc | x: Number | ["trunc", 7.2] | 7 | | Round | round | x: Number | ["round", 7.9] | 8 | | Square root | sqrt | x: Number | ["sqrt", 4] | 2 | | Cubic root | cbrt | x: Number | ["cbrt", 8] | 2 | | Arithmetic mean | avg | f: Function<Number[]> | ["avg", ["array", 4, 6, 5]] | 5 | | Power | ^ | x: Number, y: Number | ["^", 2, 2] | 4 | | Hypotenuse | hypot | x: Number, y: Number | ["hypot", 1, 2, 2] | 3 | | Maximum | max | f: Function<Number[]> | ["max", ["array", 2, 3, 4]] | 4 | | Minimum | min | f: Function<Number[]> | ["min", ["array", 2, 3, 4]] | 2 |

Logic module

| Operation | Token | Params | Sample | Output | |:--------------------|:-----------:|:------------------------------|:------------------------------------------------------|:--------| | And | and | x: Boolean, y: Boolean | ["and", true, false] | false | | Or | or | x: Boolean, y: Boolean | ["or", true, false] | true | | Not | not | x: Boolean | ["not", true] | false | | Equals | == | x: any, y: any | ["==", 1, 1] | true | | Conditional 1 | if | f1: Function, x: any | ["if", ["==", 1, 1], 4] | 4 | | Conditional 2 | elseif | f1: Function, x: any | ["if", ["==", 1, 2], 4, "elseif", ["==", 1, 1], 5] | 5 | | Conditional 3 | else | x: any | ["if", ["==", 1, 2], 4, "else", 7] | 7 |

Higher order functions

| Operation | Token | Params | Sample | Output | |:--------------------|:-----------:|:------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:------------| | Map | map | argName: string, f: Function, l: Function<[]> | ["map", "num", ["+", ["arg", "num"], 1], ["array", 1, 2, 3]] | [2, 3, 4] | | Foldl | foldl | argName: string, accumulatorName: string, f: Function, l: Function<[]> | ["foldl", "num", 3, "acc", ["^", ["arg", "acc"], ["arg", "num"]], ["array", 1, 2, 3]] | 19683 | | Foldr | foldr | argName: string, accumulatorName: string, f: Function, l: Function<[]> | ["foldr", "num", 3, "acc", ["^", ["arg", "acc"], ["arg", "num"]], ["array", 1, 2, 3]] | 6561 | | Filter | filter | argName: string, f: Function, l: Function<[]> | ["filter", "num", ["==", ["arg", "num"], 0], ["array", 0, 1, 2]] | [0] | | Find | find | argName: string, f: Function, l: Function<[]> | ["find", "num", ["==", ["arg", "num"], 1], ["array", 0, 1, 2]] | 1 | | Every | every | argName: string, f: Function, l: Function<[]> | ["every", "num", ["==", ["arg", "num"], 0], ["array", 0, 0, 0]] | true | | Some | some | argName: string, f: Function, l: Function<[]> | ["some", "num", ["==", ["arg", "num"], 1], ["array", 0, 1, 2]] | true | | Sort | sort | argName1: string, argName2: string, f: Function, l: Function<[]> | ["sort", "num1", "num2", ["-", ["arg", "num2"], ["arg", "num1"]], ["array", 3, 2, 1]] | [1, 2, 3] |

Contributors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details.