{"id":15357163,"url":"https://github.com/chocolateboy/box","last_synced_at":"2025-07-31T02:39:59.667Z","repository":{"id":53191636,"uuid":"331463794","full_name":"chocolateboy/box","owner":"chocolateboy","description":"Put a value in a box","archived":false,"fork":false,"pushed_at":"2021-08-01T15:13:07.000Z","size":258,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-08T16:18:02.023Z","etag":null,"topics":["bind","box","chain","compose","container","functional","functor","iife","pipe","pipeline","point-free","pointfree","tacit"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chocolateboy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-20T23:51:44.000Z","updated_at":"2022-02-01T18:31:09.000Z","dependencies_parsed_at":"2022-08-20T22:40:51.721Z","dependency_job_id":null,"html_url":"https://github.com/chocolateboy/box","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/chocolateboy/box","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chocolateboy%2Fbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chocolateboy%2Fbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chocolateboy%2Fbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chocolateboy%2Fbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chocolateboy","download_url":"https://codeload.github.com/chocolateboy/box/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chocolateboy%2Fbox/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267978115,"owners_count":24175249,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bind","box","chain","compose","container","functional","functor","iife","pipe","pipeline","point-free","pointfree","tacit"],"created_at":"2024-10-01T12:33:37.822Z","updated_at":"2025-07-31T02:39:59.625Z","avatar_url":"https://github.com/chocolateboy.png","language":"JavaScript","readme":"# box\n\n[![Build Status](https://github.com/chocolateboy/box/workflows/test/badge.svg)](https://github.com/chocolateboy/box/actions?query=workflow%3Atest)\n[![NPM Version](https://img.shields.io/npm/v/@chocolatey/box.svg)](https://www.npmjs.org/package/@chocolatey/box)\n\n\u003c!-- TOC --\u003e\n\n- [NAME](#name)\n- [FEATURES](#features)\n- [INSTALLATION](#installation)\n- [SYNOPSIS](#synopsis)\n- [DESCRIPTION](#description)\n  - [Why?](#why)\n  - [Why not?](#why-not)\n- [EXPORTS](#exports)\n  - [default](#default)\n  - [Box\u0026lt;T\u0026gt;](#box-class)\n    - [Static Methods](#static-methods)\n      - [constructor](#constructor)\n      - [Box.of](#boxof)\n    - [Instance Methods](#instance-methods)\n      - [map](#map)\n      - [tap](#tap)\n      - [then](#then)\n      - [value](#value)\n- [DEVELOPMENT](#development)\n- [COMPATIBILITY](#compatibility)\n- [SEE ALSO](#see-also)\n- [VERSION](#version)\n- [AUTHOR](#author)\n- [COPYRIGHT AND LICENSE](#copyright-and-license)\n\n\u003c!-- TOC END --\u003e\n\n# NAME\n\nBox - put a value in a box\n\n# FEATURES\n\n- no dependencies\n- \u0026lt; 170 B minified + gzipped\n- fully typed (TypeScript)\n- CDN builds (UMD) - [jsDelivr][], [unpkg][]\n\n# INSTALLATION\n\n    $ npm install @chocolatey/box\n\n# SYNOPSIS\n\n```javascript\nimport $ from '@chocolatey/box'\n\n$(42)                    // Box\u003c42\u003e\n$(42).value()            // 42\n$(42).map(it =\u003e it + 1)  // Box\u003c43\u003e\n$(42).tap(console.log)   // Box\u003c42\u003e\n$(42).then(it =\u003e it + 1) // 43\n$(42, it =\u003e it + 1)      // 43\n\n// \"*.tar.gz\" -\u003e \"*.gz\"\nconst untar = name =\u003e $(name)\n    .map(it =\u003e it.split('.'))\n    .tap(it =\u003e it.splice(1, 1))\n    .then(it =\u003e it.join('.'))\n\nuntar('package.tar.gz') // \"package.gz\"\n```\n\n# DESCRIPTION\n\nBox puts a value in a container which exposes a handful of methods to\nfacilitate piping values through a series of functions.\n\nIt provides a lightweight implementation of the [box pattern][], which allows\nthe right-to-left flow of function composition to be expressed via the\nleft-to-right syntax of method chaining familiar from jQuery, Lodash, promises\netc.\n\n\u003c!-- TOC:ignore --\u003e\n## compose\n\n```javascript\nimport R from 'ramda'\n\nconst fn1 = value =\u003e baz(bar(foo(value)))\nconst fn2 = R.compose(baz, bar, foo)\n```\n\n\u003c!-- TOC:ignore --\u003e\n## box\n\n```javascript\nimport $ from '@chocolatey/box'\n\nconst fn = value =\u003e $(value).map(foo).map(bar).then(baz)\n```\n\n## Why?\n\nBecause:\n\n\u003e composition and dot chaining are the same, and dot chaining is more ergonomic\n\u003e in JavaScript\n\n— [Brian Lonsdorf](https://frontendmasters.com/courses/hardcore-js-v2/composition-is-dot-chaining/)\n\n## Why not?\n\nIf you're using Babel, pipelines can be written natively with features such as\nthe [pipeline operator][], [do expressions][] and [partial application][],\ne.g.:\n\n```javascript\nimport { tap } from 'lodash'\n\nconst untar = name =\u003e\n    name.split('.')\n        |\u003e tap(#, it =\u003e it.splice(1, 1))\n        |\u003e #.join('.')\n```\n\nIf you're already using Lodash/Underscore or similar, you can use their\nbuilt-in methods to implement pipelines, e.g.:\n\n```javascript\nimport _ from 'lodash'\n\nconst untar = name =\u003e\n    _(name)\n        .split('.')\n        .tap(it =\u003e it.splice(1, 1))\n        .join('.')\n```\n\n# EXPORTS\n\n## default\n\n- **Type**:\n  - `\u003cT, R\u003e(value: T, fn: (value: T) =\u003e R): R`\n  - `\u003cT\u003e(value: T): Box\u003cT\u003e`\n- **Aliases**: $, box\n\n```javascript\nimport $ from '@chocolatey/box'\n\n$(42)               // Box\u003c42\u003e\n$(42, it =\u003e it + 1) // 43\n```\n\nThe default export is a function which either takes a value and puts it in a\nbox (via [`Box.of`](#boxof)) or takes a value and a function and applies the\nfunction to the value.\n\nThe latter provides a convenient shorthand for passing an argument to an IIFE,\ne.g.:\n\n\u003c!-- TOC:ignore --\u003e\n### imperative\n\n```javascript\nconst counter = (function () {\n    let count = 0\n    return () =\u003e ++count\n})()\n\ncounter() // 1\ncounter() // 2\ncounter() // 3\n```\n\n\u003c!-- TOC:ignore --\u003e\n### IIFE\n\n```javascript\nconst counter = (function (count) { return () =\u003e ++count })(0)\n```\n\n\u003c!-- TOC:ignore --\u003e\n### Box\n\n```javascript\nconst counter = $(0, count =\u003e () =\u003e ++count)\n```\n\n\u003ca name=\"box-class\"\u003e\u003c/a\u003e\n## Box\u0026lt;T\u0026gt;\n\n### Static Methods\n\n#### constructor\n\n- **Type**: `new \u003cT\u003e(value: T) =\u003e Box\u003cT\u003e`\n\n```javascript\nimport { Box } from '@chocolatey/box'\n\nconst box = new Box(42) // Box\u003c42\u003e\n```\n\nCreates a new Box instance containing the supplied value.\n\n#### Box.of\n\n- **Type**: `\u003cT\u003e(value: T) =\u003e Box\u003cT\u003e`\n\n```javascript\nimport { Box } from '@chocolatey/box'\n\nconst box = Box.of(42)              // Box\u003c42\u003e\nconst boxes = [1, 2, 3].map(Box.of) // [Box\u003c1\u003e, Box\u003c2\u003e, Box\u003c3\u003e]\n```\n\nReturns a new [`Box`](#box-class) instance containing the supplied value.\n\nNote that `of` is a function which returns a Box instance rather than a method\nwhich returns an instance of its invocant, so the following are equivalent:\n\n```javascript\nclass MyBox extends Box {} // XXX missing `of` override\n\nconst array = [1, 2]\n\narray.map(it =\u003e Box.of(it))   // [Box\u003c1\u003e, Box\u003c2\u003e]\narray.map(it =\u003e MyBox.of(it)) // [Box\u003c1\u003e, Box\u003c2\u003e]\narray.map(Box.of)             // [Box\u003c1\u003e, Box\u003c2\u003e]\narray.map(MyBox.of)           // [Box\u003c1\u003e, Box\u003c2\u003e]\n```\n\n### Instance Methods\n\n#### map\n\n- **Type**: `\u003cU\u003e(fn: (value: T) =\u003e U): Box\u003cU\u003e`\n\n```javascript\nimport $ from '@chocolatey/box'\n\n$(42).map(it =\u003e it + 1) // Box\u003c43\u003e\n```\n\nApplies the supplied function to the value and returns a new box containing the\nresult.\n\n#### tap\n\n- **Type**: `(fn: (value: T) =\u003e void): this`\n\n```javascript\nimport $ from '@chocolatey/box'\n\n$(42).tap(console.log) // Box\u003c42\u003e\n```\n\nApplies the supplied function to the value and returns the original box (the\ninvocant). Useful to insert side effects, logging etc. into a pipeline without\nchanging the value.\n\n#### then\n\n- **Type**: `\u003cU\u003e(fn: (value: T) =\u003e U): U`\n\n```javascript\nimport $ from '@chocolatey/box'\n\n$(42).then(it =\u003e it + 1) // 43\n```\n\nReturns the result of applying the supplied function to the value.\n\n#### value\n\n- **Type**: `(fn?: (value: T) =\u003e void): T`\n\n```javascript\nimport $ from '@chocolatey/box'\n\n$(42).value()            // 42\n$(42).value(console.log) // 42\n```\n\nReturns the value. If an optional function is supplied, it is applied to the\nvalue before the value is returned. This is similar to [`tap`](#tap), except\nthe value is returned rather than the box.\n\n# DEVELOPMENT\n\n\u003cdetails\u003e\n\n\u003c!-- TOC:ignore --\u003e\n## NPM Scripts\n\nThe following NPM scripts are available:\n\n- build - compile the library for testing and save to the target directory\n- build:doc - generate the README's TOC (table of contents)\n- build:release - compile the library for release and save to the target directory\n- clean - remove the target directory and its contents\n- rebuild - clean the target directory and recompile the library\n- repl - launch a node REPL with the library loaded\n- test - recompile the library and run the test suite\n- test:run - run the test suite\n- typecheck - sanity check the library's type definitions\n\n\u003c/details\u003e\n\n# COMPATIBILITY\n\n- [Maintained Node.js versions](https://github.com/nodejs/Release#readme) and compatible browsers\n\n# SEE ALSO\n\n\u003c!-- TOC:ignore --\u003e\n## Libraries\n\n- [fcf](https://github.com/GianlucaGuarini/fcf) - a functional alternative to control-flow statements such as `if`, `switch` and `while`\n- [fp-ts](https://www.npmjs.com/package/fp-ts) - functional programming in TypeScript\n\n\u003c!-- TOC:ignore --\u003e\n## Videos\n\n- [Brian Lonsdorf - Create linear data flow with container style types (Box)](https://egghead.io/lessons/javascript-linear-data-flow-with-container-style-types-box)\n- [Brian Lonsdorf - Oh Composable World!](https://www.youtube.com/watch?v=SfWR3dKnFIo)\n\n# VERSION\n\n1.2.0\n\n# AUTHOR\n\n[chocolateboy](mailto:chocolate@cpan.org)\n\n# COPYRIGHT AND LICENSE\n\nCopyright © 2021 by chocolateboy.\n\nThis is free software; you can redistribute it and/or modify it under the terms\nof the [MIT license](https://opensource.org/licenses/MIT).\n\n[arrow functions]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions\n[box pattern]: https://mostly-adequate.gitbooks.io/mostly-adequate-guide/content/ch08.html\n[comma operator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator\n[do expressions]: https://github.com/tc39/proposal-do-expressions\n[jsDelivr]: https://cdn.jsdelivr.net/npm/@chocolatey/box@1.2.0/dist/index.umd.min.js\n[partial application]: https://github.com/tc39/proposal-partial-application\n[pipeline operator]: https://github.com/tc39/proposal-pipeline-operator\n[unpkg]: https://unpkg.com/@chocolatey/box@1.2.0/dist/index.umd.min.js\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchocolateboy%2Fbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchocolateboy%2Fbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchocolateboy%2Fbox/lists"}