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

fundb

v0.0.2

Published

funktional programming database

Downloads

1

Readme

Fun(ctional)DB (FunDB)

Fun(ctional)DB is an experiment that follows the Unix philosophy (small & specific). As most database systems in existence are monolithic, both in size and mentailty, this experiments aims at taking the opposite approach. As such it is not a drop-in replacement for any db system in existence, rather a "new" option to be considered.

tl; dr FunDB is a micro functional programming library performing database functions such

  • querying / filtering
  • sorting
  • indexing
  • searching

or better also, a micro-database that is storage agnostic and client agnostic.

Overview

The point of FunDB is to extract state from the database as much as possible. You can manage writes to disk outside of FunDB (see an example in test.js) and only perform processing with FunDB.

You can use FunDB in two ways: plain functions or curried around a data collection (which means you do not need to inject your data in the db functions anymore).

FunDB plain functions

curry(fun, arg): the heart of FunDB is a simple curry function, which takes a function and the first argument of that function. Given a function f(a, b, c, d) you can call curry(f, 'hello') which returns a function equivalent to f('hello', b, c, d). Note that curry only curries one argument at a time (unlike the more advanced curry function in ramda)

query(filterFun, array): this effectively operating a filter on the array, and returning a filtered array.

reduce(reduceFun, array): again, operates a native reduce on the array, returns the reduced value.

index(sortFun, array): this function returns an object index, which contains a property ids which is an array of integers representing the order of the elements in array as sorted by the function sortFun. So if you have an array of objects, each object containing the property age, you could use a sort function like function (a, b) { return a.age > b.age; } (which sorts the array elements in ascending age order). Except, the originally array is untouched, while an object index is returned. This index object has the following properties:

  • ids: an array of integer representing the order of elements of the original array if they were to be sorted by sortFun
  • first(): gets the first element in the original array according to sortFun (i.e. the object with the lowest age value)
  • last(): get the last element (i.e. the oldest person in the array)
  • get(position): gets the element in the original array corresponding to that position in the index
  • insert(item, pos): inserts an element into the original array and updates the index of ids ids (NOTE: this is the only function with a side effect in that the original array is mutated).

searchSorted(array, index, item, compareFun): this function performs a binary search on array, utilising the index object index, on an item item utilising the (optional) comparison function compareFun. compareFun only needs to be there in case the concept of less or equal is not as obvious as comparing numbers or strings (i.e. you may want to compare the length of a string for some). compareFun takes two arguments a and b and compares them, returnning -1 if a is "less" than b, 0 if the search is a match (and the position in the array will be included in the object returned), and 1 if a is "greater" than b. The function returns an object with two properties: found to indicate the item was found and index which indicates the position at which the item was found or the position at which the item would be inserted if you were to insert it in the original array. You would use the index method insert(item, pos) to operate that.

and(array, filtersArray): this function queries the original array against all the filter functions contained in the array filtersArray. Returns an array containing elements that passed all filter tests. Each filter function needs to return a boolean value (true for pass, false for fail). An example usage would be fundb.and(array, [filterByAgeFunction, filterByLanguageFunction]).

or(array, filtersArray): like and but it performs an OR operation between filters and returns an array containing all elements that passed at least one of the filter function tests. Filter function criteria are identical to and.

curryFilter(filterFunction): takes a filter function and returns a curried query function which can then be called on an array to apply the filter. I.e. var byAge = function (obj) { return obj.age > 30; } and then call byAge(array) to obtain an array of elements that pass the test. This is a utility method, you could just as easily run fundb.curry(fundb.query, filterFunction).

Array-centric functions

FunDB.curry(array): this function returns an object with all the above functions as methods (it performs a curry on the array on all those functions and associates them to a single object), except you can skip referencing the data array. So for example after calling: var db = FunDB.curry(array); you can then do db.index(sortFun) or db.query(filterFun) etc.. In summary the object will have the following methods available:

  • db.query(filterFun)
  • db.index(sortFun)
  • db.search(index, item, compareFun)
  • db.or(filtersArray)
  • db.and(filtersArray)
  • db.reduce(reduceFun)