UNPKG

@bitty/pipe

Version:

A pipe function to perform function composition in LTR (Left To Right) direction.

72 lines 4.45 kB
{ "name": "@bitty/pipe", "version": "0.3.0", "description": "A pipe function to perform function composition in LTR (Left To Right) direction.", "sideEffects": false, "cdn": "./dist/pipe.umd.js", "main": "./dist/pipe.js", "types": "./types/pipe.d.ts", "unpkg": "./dist/pipe.umd.js", "module": "./dist/pipe.esm.js", "jsdelivr": "./dist/pipe.umd.js", "umd:main": "./dist/pipe.umd.js", "exports": { ".": [ { "import": "./dist/pipe.mjs", "require": "./dist/pipe.js", "default": "./dist/pipe.js" }, "./dist/pipe.js" ] }, "files": [ "dist/", "types/" ], "keywords": [ "pipe", "compose", "composition", "flow", "pipeline", "fp", "functional programming", "chain", "function", "functional", "serial" ], "repository": { "type": "git", "url": "git+https://github.com/VitorLuizC/bitty.git", "directory": "packages/pipe" }, "author": { "url": "https://vitorluizc.github.io/", "name": "Vitor Luiz Cavalcanti", "email": "vitorluizc@outlook.com" }, "bugs": { "url": "https://github.com/VitorLuizC/bitty/issues" }, "homepage": "https://github.com/VitorLuizC/bitty/tree/master/packages/pipe", "license": "MIT", "devDependencies": { "ava": "^4.0.1", "prettier": "^2.5.1", "rollup": "^2.63.0", "rollup-plugin-terser": "^7.0.2", "typescript": "^4.5.4" }, "scripts": { "test": "pnpm run test:code-style && pnpm run test:unit", "test:transpile": "tsc --project ./tsconfig.test.json", "test:unit": "pnpm run test:transpile && ava", "test:code-style": "prettier --check \"./{src,test}/**/*.ts\"", "build": "pnpm run build:transpile && pnpm run build:bundle", "build:transpile": "tsc --project ./tsconfig.build.json", "build:bundle": "rollup --config rollup.config.js" }, "readme": "# `@bitty/pipe`\n\n[![Bundle minified size](https://badgen.net/bundlephobia/min/@bitty/pipe)](https://bundlephobia.com/result?p=@bitty/pipe)\n[![Bundle minified and gzipped size](https://badgen.net/bundlephobia/minzip/@bitty/pipe)](https://bundlephobia.com/result?p=@bitty/pipe)\n\nA pipe function to perform function composition in LTR (Left-To-Right) direction.\n\n- 📦 Distributions in ESM, CommonJS, UMD and UMD _minified_ formats.\n\n- ⚡ Lightweight:\n - Weighs less than 0.3KB (min + gzip).\n - 3x smaller than `ramda.pipe`.\n - Tree-shakeable.\n - Side-effects free.\n\n- 🔋 Bateries included:\n - No dependencies.\n - Its not based on newer browser's APIs or es2015+ features.\n\n- 🏷 Safe:\n - JSDocs and type declarations for IDEs and editor's autocomplete/intellisense.\n - Made with TypeScript as strict as possible.\n - Unit tests with AVA.\n\n## Installation\n\nThis library is published in the NPM registry and can be installed using any compatible package manager.\n\n```sh\nnpm install @bitty/pipe --save\n\n# For Yarn, use the command below.\nyarn add @bitty/pipe\n```\n\n### Installation from CDN\n\nThis module has a UMD bundle available through JSDelivr and Unpkg CDNs.\n\n```html\n<!-- For UNPKG use the code below. -->\n<script src=\"https://unpkg.com/@bitty/pipe\"></script>\n\n<!-- For JSDelivr use the code below. -->\n<script src=\"https://cdn.jsdelivr.net/npm/@bitty/pipe\"></script>\n\n<script>\n // UMD module is exposed through the \"pipe\" global function.\n console.log(pipe);\n //=> \"[Function: pipe]\"\n</script>\n```\n\n## Getting Started\n\nImport `pipe` from package and just compose your functions with it.\n\n```ts\nimport pipe from '@bitty/pipe';\n\nconst resolveToNumber = pipe(\n (value: unknown) => typeof value === 'number' ? value : parseFloat(value),\n (value: number) => Number.isNaN(value) ? 0 : value,\n);\n\nresolveToNumber('12389');\n//=> 12389\n```\n\nThe first pipe argument is an arity N function, so you can receive more than one argument in the composition.\n\n```ts\nimport pipe from '@bitty/pipe';\n\nconst fromTextToWords = (text: string, wordsToIgnore: string[] = []) =>\n text\n .trim()\n .split(/\\s+/)\n .filter((word) => !wordsToIgnore.includes(word));\n\nconst formatToInitials = pipe(\n fromTextToWords,\n (words) => words.map((word) => word.charAt(0)),\n (initials) => initials.join('').toUpperCase(),\n);\n\nformatToInitials('abraão william de santana ', ['de']);\n//=> \"AWS\"\n```\n\n## License\n\nReleased under [MIT License](./LICENSE).\n" }