{"_id":"@anilanar/fp-ts-routing","_rev":"1-58582510eb79d047524852e07b67307c","name":"@anilanar/fp-ts-routing","dist-tags":{"latest":"0.5.3"},"versions":{"0.5.3":{"name":"@anilanar/fp-ts-routing","version":"0.5.3","description":"A type-safe routing library for TypeScript","main":"lib/index.js","module":"es6/index.js","typings":"lib/index.d.ts","sideEffects":false,"scripts":{"lint":"tslint -p .","jest":"jest --ci","jest-coverage":"jest --ci --coverage","prettier":"prettier --no-semi --single-quote --print-width 120 --parser typescript --list-different \"{src,test}/**/*.ts\"","fix-prettier":"prettier --no-semi --single-quote --print-width 120 --parser typescript --write \"{src,test}/**/*.ts\"","test":"npm run prettier && npm run lint && npm run dtslint && npm run jest && npm run docs","clean":"rm -rf lib/* es6/*","prebuild":"npm run clean","build":"tsc -p ./tsconfig.build.json && tsc -p ./tsconfig.build-es6.json","prepublish":"npm run build","dtslint":"dtslint dtslint","docs":"docs-ts","mocha":"mocha -r ts-node/register test/*.ts","postbuild":"import-path-rewrite"},"repository":{"type":"git","url":"git+https://github.com/gcanti/fp-ts-routing.git"},"author":{"name":"Giulio Canti","email":"giulio.canti@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/gcanti/fp-ts-routing/issues"},"homepage":"https://github.com/gcanti/fp-ts-routing","peerDependencies":{"fp-ts":"^2.0.1","io-ts":"^2.0.0"},"devDependencies":{"@types/jest":"^22.2.2","@types/node":"^12.6.8","docs-ts":"^0.3.4","dtslint":"github:gcanti/dtslint","fp-ts":"^2.0.1","import-path-rewrite":"github:gcanti/import-path-rewrite","io-ts":"^2.0.0","jest":"^24.8.0","mocha":"^6.1.4","prettier":"^1.19.1","ts-jest":"^24.0.2","ts-node":"3.3.0","tslint":"^5.9.1","tslint-config-standard":"^7.0.0","typescript":"^3.5.2"},"tags":["typescript","functional-programming","routing","applicative"],"keywords":["typescript","functional-programming","routing","applicative"],"_id":"@anilanar/fp-ts-routing@0.5.3","_nodeVersion":"12.16.2","_npmVersion":"6.14.4","dist":{"integrity":"sha512-OxAbVaxtpEgZzgGiujDX6sGZeDLqmPpO5sxwOEUzayHFWwAAEZgXP3HiFgOI+X5UEW8FyWk6MjR3C9lb9d/TtA==","shasum":"ba7cd282686a5ad531387db7522f62cdebb6e7c4","tarball":"https://registry.npmjs.org/@anilanar/fp-ts-routing/-/fp-ts-routing-0.5.3.tgz","fileCount":8,"unpackedSize":46218,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJe2o65CRA9TVsSAnZWagAAULwP/jzSKFiE7k0AknkDw9Fk\nNkAA8WVUUwd+YUoewJbO7ukuMzFPEf8xRZysv6qMqbY35se2D0whXn2GjhVZ\nDSqsLgRoGIWQdD5KhpOtPgRO9i5ai6MHEpJ0Z2shBEVXXkcHau0vAikIzTWv\nGXcavTBp0I/mowXyY5qaaVnC6Vzm10+X57MeFdbun5hqHFgRDMFh47KxSkUu\nhaxLbk/uGb72bIavpU3X19WHfTF9NhDkNqDQgXWXU7MaFQJJYuJMx72n9lmn\nnjXu9k54YAbWWdZg+yTyxYhaxj88KhRTa3k6kt+FMTGfFF/LmE8Fw7KgZMan\nmFsDcEvQUXdCKWnJiZ4Wq3062lj3eBqyH+yc9fy/Wf/LHmkj2RfCzgZBnZBM\nF8g2sblcRcVJKyrje8y04TtZWC0GZIYWh4+vswkev8UdXD2t2pcNUrgxKI9L\nFvT1hoONDHfWb/pgKo/TZeYYWNXlcII3NtwimlNTgge5/3cTJfPumx+1i6st\nP8k8TBEvYGaNbkAbxfu1rwGVPLsgHpvpkhYIVdhjN+4ONITBv+uaM3Mi2scs\nCDXpuVFWXFC9a54/VKxI+tSYauVHbO/mBAEqMPBIRNnxKijVJIaAcspXFWhm\nxYXqX2Jdym3siftX0YNJG3iNycWZCeuDLCNLHssqP+nK0aFQqoNm7k0ZCFfK\n5S1Z\r\n=wGhJ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD5vwITsGnzaQQ8gxeH81Uf8S/aHeWvdogyJmWbzzihFwIgB6+uwbSc/9yzdYr5IY4NTXU740IoekgeMnvN58n5y/0="}]},"maintainers":[{"name":"anilanar","email":"anilanar@hotmail.com"}],"_npmUser":{"name":"anilanar","email":"anilanar@hotmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fp-ts-routing_0.5.3_1591381688617_0.5965040837640405"},"_hasShrinkwrap":false}},"time":{"created":"2020-06-05T18:28:08.569Z","0.5.3":"2020-06-05T18:28:08.734Z","modified":"2022-04-04T14:10:58.633Z"},"maintainers":[{"name":"anilanar","email":"anilanar@hotmail.com"}],"description":"A type-safe routing library for TypeScript","homepage":"https://github.com/gcanti/fp-ts-routing","keywords":["typescript","functional-programming","routing","applicative"],"repository":{"type":"git","url":"git+https://github.com/gcanti/fp-ts-routing.git"},"author":{"name":"Giulio Canti","email":"giulio.canti@gmail.com"},"bugs":{"url":"https://github.com/gcanti/fp-ts-routing/issues"},"license":"MIT","readme":"# Installation\n\nTo install the stable version:\n\n```sh\nnpm i fp-ts-routing\n```\n\n# TypeScript compatibility\n\nThe stable version is tested against TypeScript 3.5.2 but should run with 3.2.2+ too.\n\n# Usage\n\n```ts\n//\n// locations\n//\n\ninterface Home {\n  readonly _tag: 'Home'\n}\n\ninterface User {\n  readonly _tag: 'User'\n  readonly id: number\n}\n\ninterface Invoice {\n  readonly _tag: 'Invoice'\n  readonly userId: number\n  readonly invoiceId: number\n}\n\ninterface NotFound {\n  readonly _tag: 'NotFound'\n}\n\ntype Location = Home | User | Invoice | NotFound\n\nconst home: Location = { _tag: 'Home' }\n\nconst user = (id: number): Location => ({ _tag: 'User', id })\n\nconst invoice = (userId: number, invoiceId: number): Location => ({ _tag: 'Invoice', userId, invoiceId })\n\nconst notFound: Location = { _tag: 'NotFound' }\n\n// matches\nconst defaults = end\nconst homeMatch = lit('home').then(end)\nconst userIdMatch = lit('users').then(int('userId'))\nconst userMatch = userIdMatch.then(end)\nconst invoiceMatch = userIdMatch\n  .then(lit('invoice'))\n  .then(int('invoiceId'))\n  .then(end)\n\n// router\nconst router = zero<Location>()\n  .alt(defaults.parser.map(() => home))\n  .alt(homeMatch.parser.map(() => home))\n  .alt(userMatch.parser.map(({ userId }) => user(userId)))\n  .alt(invoiceMatch.parser.map(({ userId, invoiceId }) => invoice(userId, invoiceId)))\n\n// helper\nconst parseLocation = (s: string): Location => parse(router, Route.parse(s), notFound)\n\nimport * as assert from 'assert'\n\n//\n// parsers\n//\n\nassert.strictEqual(parseLocation('/'), home)\nassert.strictEqual(parseLocation('/home'), home)\nassert.deepEqual(parseLocation('/users/1'), user(1))\nassert.deepEqual(parseLocation('/users/1/invoice/2'), invoice(1, 2))\nassert.strictEqual(parseLocation('/foo'), notFound)\n\n//\n// formatters\n//\n\nassert.strictEqual(format(userMatch.formatter, { userId: 1 }), '/users/1')\nassert.strictEqual(format(invoiceMatch.formatter, { userId: 1, invoiceId: 2 }), '/users/1/invoice/2')\n```\n\n# Documentation\n\n- [API Reference](https://gcanti.github.io/fp-ts-routing)\n","readmeFilename":"README.md"}