A library for declarative programming with higher order functions


000.3.14 years ago4 years agoMinified + gzip package size for @bingo347/fn in KB



A library for declarative programming with higher order functions


npm i -S @bingo347/fn


yarn add @bingo347/fn

Usage example

wrap DOMReady wait to Promise

import makeSubscriber from '@bingo347/fn/make/subscriber';
import extractField from '@bingo347/fn/mappers/extractField';
import chain from '@bingo347/fn/mappers/chain';
import equal from '@bingo347/fn/logic/equal';
import or from '@bingo347/fn/logic/or';

const subscribe = makeSubscriber('addEventListener', 'removeEventListener');
const isDocumentReady = chain(
    or(equal('complete'), equal('interactive'))

function domReady(doc = document) {
    return (isDocumentReady(doc)
        ? Promise.resolve()
        : new Promise(resolve => {
            const doResolve = () => resolvers.forEach(resolver => resolver());
            const resolvers = [
                subscribe(doc, 'DOMContentLoaded', doResolve),
                subscribe(doc.defaultView, 'load', doResolve),

domReady().then(() => {
    //current document is ready
domReady(iframe.contentDocument).then(() => {
    //iframe document is ready

Two module systems support

All library functions are provided in two variants:

  • ES6 modules with .mjs extension, for use with module bundler (webpack) or use in node.js with --experimental-modules flag or with esm
  • commonJS modules with .js extension, for use in node.js without any helpers

ES5 support

All library functions are provided in ES6 (ES2015) compatible code.
It don't transpiled, but you can use webpack with babel for transpile it for old browsers

// webpack.config.js
module.exports = {
    module: {
        rules: [
                test: /\.m?js$/,
                include: modulePath => {
                    if(modulePath.includes('node_modules/@bingo347/fn')) {
                        // transpile this library
                        return true;
                    if(modulePath.includes('node_modules')) {
                        // don't transpile other libraries
                        return false;
                    // transpile your code
                    return true;
                use: [{
                    loader: 'babel-loader',
                    options: {
                        presets: [['env', {modules: false}]]
            // your other webpack module.rules
    // your other webpack options


See on the github



If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.