{"_id":"@burzomir/unionize","_rev":"3-b34ebc5fe3988b970688978bd55fa3b1","name":"@burzomir/unionize","dist-tags":{"latest":"2.2.1"},"versions":{"2.1.2":{"name":"@burzomir/unionize","version":"2.1.2","description":"Boilerplate-free functional sum types in TypeScript","repository":{"type":"git","url":"git+https://github.com/burzomir/unionize.git"},"author":{"name":"Tom Crockett","email":"pelotom@gmail.com"},"license":"MIT","main":"lib/index.js","types":"./lib/index.d.ts","scripts":{"build":"tsc --pretty","format":"node scripts/format.js","postinstall":"postinstall-build  lib","test":"jest --no-cache --verbose --coverage","test:watch":"jest --watch"},"devDependencies":{"@types/jest":"^21.1.8","coveralls":"^3.0.0","jest":"^21.2.1","prettier":"^1.11.1","ts-jest":"^21.2.4","typescript":"^2.8.1"},"jest":{"verbose":false,"testRegex":".*/*.spec.ts$","moduleFileExtensions":["js","ts"],"transform":{"\\.ts$":"<rootDir>/node_modules/ts-jest/preprocessor"},"mapCoverage":true,"testEnvironment":"node"},"dependencies":{"postinstall-build":"^5.0.1"},"gitHead":"0841a753bf13316d48eb66430ca8ccb317254409","bugs":{"url":"https://github.com/burzomir/unionize/issues"},"homepage":"https://github.com/burzomir/unionize#readme","_id":"@burzomir/unionize@2.1.2","_npmVersion":"5.6.0","_nodeVersion":"8.11.1","_npmUser":{"name":"burzomir","email":"burzomirdev@gmail.com"},"dist":{"integrity":"sha512-uIH5z7RJTaPd28v9RxZf4fiSHKYcWof/avqimGwpkbVZKIW9MUs3zEdgwvMfkEbdJxBuPaIxBJ6WBT5z9HsBqw==","shasum":"39800b73c5467bc4645f080a4d7ba656ff1c4eea","tarball":"https://registry.npmjs.org/@burzomir/unionize/-/unionize-2.1.2.tgz","fileCount":17,"unpackedSize":137855,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbQgc2CRA9TVsSAnZWagAAuaUP/2j5clrfCDj6Xd9xIePy\n3muuCT6ToS3/Dpybh/gPu5oM8Fo8W2UwwFqiXeVMmoAMOioj6KWGXMm1VRlx\nb9LYBPO/ghs8aydX8xfgWGNHBmGs41n/BTpQmLDhTi80uwHQAxtnRyAV7Ul1\njUKEDRHYCYuX0N7i1aasq9FqDYlOpzw4BRFPdaqsLlb5E92G0g6Z6VIAwG71\nKGgq+jD8o7ka4bY+TnywMcw04OTwgEC7EV87Zv8EI0kqbugwNHu9eFNCHui1\n3jJXwehsUnlOMN+qrBiwxSDHux28tzNR46+BY6YkK2Assf7UF7p1z3p+aBA+\ntPhVFuKBhk3uuCBGYk1EXWfkLdsInsdW5Vllcdc2CpnqYgmPfUWI+j3QVH5S\nQJh5NPlvyt8xFxDE9RW+EF+fbcyn5bNAPjiA+dOALqOTl115bY4M7oEiXmoW\nHwIKJ5VxPmZHsFThHlchFNXCkUXQ/PJVB5GkXrqi3SxXXaUYJmG5mG0Mf6yJ\n8c21w5fONgpHzqRXuKi3UTD0IQb+XqV2C6bjzY9DMytrD1JEm+XCUIyL2AMM\nTtbgYp3Hi/pJ1F7PA0koXPehIoqCtZvhRxWNLZs8VLudAsDQbovaJU2xCJHh\ngCGDyuBp2r9i5PMG9xFHNXN4wt7ndFhZNXmD9zoIxHRIam1TvWqp5H82LB7/\nvSrT\r\n=j8vY\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGUW5SOvvmVFHgAlefp9dAf0RaY+/xzPs/muuniz2wU7AiEAz3i5iEQQw34ayEyfOQSap9sIciOyxNmbL7azPqBdW7M="}]},"maintainers":[{"name":"burzomir","email":"burzomirdev@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/unionize_2.1.2_1531053878473_0.8741831755960976"},"_hasShrinkwrap":false},"2.2.0":{"name":"@burzomir/unionize","version":"2.2.0","description":"Boilerplate-free functional sum types in TypeScript","repository":{"type":"git","url":"git+https://github.com/burzomir/unionize.git"},"author":{"name":"Tom Crockett","email":"pelotom@gmail.com"},"license":"MIT","main":"lib/index.js","types":"./lib/index.d.ts","scripts":{"build":"tsc --pretty","format":"node scripts/format.js","postinstall":"postinstall-build  lib","test":"jest --no-cache --verbose --coverage","test:watch":"jest --watch"},"devDependencies":{"@types/jest":"^21.1.8","coveralls":"^3.0.0","jest":"^21.2.1","prettier":"^1.11.1","ts-jest":"^21.2.4","typescript":"^2.8.1"},"jest":{"verbose":false,"testRegex":".*/*.spec.ts$","moduleFileExtensions":["js","ts"],"transform":{"\\.ts$":"<rootDir>/node_modules/ts-jest/preprocessor"},"mapCoverage":true,"testEnvironment":"node"},"dependencies":{"postinstall-build":"^5.0.1"},"gitHead":"a84de99744b87b9a2d03e427918e8174f99d2373","bugs":{"url":"https://github.com/burzomir/unionize/issues"},"homepage":"https://github.com/burzomir/unionize#readme","_id":"@burzomir/unionize@2.2.0","_npmVersion":"5.6.0","_nodeVersion":"8.11.1","_npmUser":{"name":"burzomir","email":"burzomirdev@gmail.com"},"dist":{"integrity":"sha512-L7kG3U5zCST9XyDs9+ofQDnJ/0mAIVbBMq2xccIsj4//LmLym/VF2271swf50EPy90u2rP5FIOZ73OrXP0WXuw==","shasum":"698c12b0a5ddf03e9beed8dbb911ea12f9afda3e","tarball":"https://registry.npmjs.org/@burzomir/unionize/-/unionize-2.2.0.tgz","fileCount":17,"unpackedSize":137855,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbQgiXCRA9TVsSAnZWagAA5j8P/15EigBxDwLvcqzDkXin\nwkT6VA3hjtRzg56tx0W8B5b44coYJsUxvM5xMZ1zDkg+zof8ee/XMUcQk5KA\n0OouJGnskmEw7pMBW4MbCtQTGVzA6VF/s+amLBJSJuHJ2fXIMkPo/P0+8xmp\nPT9tsPy2VHOB1LlO+HXiWCAYcR+vjDUBUXZetoGA7VsWgcIwMMqzzunho/r7\nTwgTXZrs0jakS+SOph1v1/58dcmiCv17GWednXSqhboUpApCHUI5MlGrhc+K\nWua2kOuKew2eNJfzZnq9KQ5MFYOVfQvDhjQ1pRptXsUZFxyiABYWv8SfTQca\nlK+YmiuCHRc+vF8SyJwrnVk2on5Q9hUOXFoi/4CSPIv+bqm5h5Q7B4MXoihs\nePsAvlmYc2oUR00szkl+HNpS8wMFoDScBWibXhW8yjJQXdDrfznM0qVf7e0f\nku0Sl0sZA4kVPpG22SYpajBonIA/2MZuQepZVL/ORntDNfOWziQATItX0qKe\nZETJvT8bvV2+VdDr3Q2y5timiZWmW722L4uCI8DLbsWBgiBYsWvpefMpB3zo\naRBgl+0zU8Kegf0SwS9E74UXFiSRXOdnOvbj0AtjUuFgpJbAr/EF/3E/z/XV\nf7+UUqEXJcpC9/gD9lQgmsirHGNWZLSc6jaKLH5Mj7u3h7ChE7emnNUWnpg+\n5I80\r\n=Gt6m\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDays4NZU2+HJ7DyBK6kIns44ifmnV3Cs83d+abzLxEEgIhAIqi6Vi4FriueadbuaWdLXs7TIMjs7Y6/+z48f3RLFi0"}]},"maintainers":[{"name":"burzomir","email":"burzomirdev@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/unionize_2.2.0_1531054231677_0.5495405683495547"},"_hasShrinkwrap":false},"2.2.1":{"name":"@burzomir/unionize","version":"2.2.1","description":"Boilerplate-free functional sum types in TypeScript","repository":{"type":"git","url":"git+https://github.com/burzomir/unionize.git"},"author":{"name":"Tom Crockett","email":"pelotom@gmail.com"},"license":"MIT","main":"lib/index.js","types":"./lib/index.d.ts","scripts":{"build":"tsc --pretty","format":"node scripts/format.js","test":"jest --no-cache --verbose --coverage","test:watch":"jest --watch"},"devDependencies":{"@types/jest":"^21.1.8","coveralls":"^3.0.0","jest":"^21.2.1","prettier":"^1.11.1","ts-jest":"^21.2.4","typescript":"^2.8.1"},"jest":{"verbose":false,"testRegex":".*/*.spec.ts$","moduleFileExtensions":["js","ts"],"transform":{"\\.ts$":"<rootDir>/node_modules/ts-jest/preprocessor"},"mapCoverage":true,"testEnvironment":"node"},"dependencies":{},"gitHead":"8f2ce16eaad20b585426e68abc828d7829c35c6b","bugs":{"url":"https://github.com/burzomir/unionize/issues"},"homepage":"https://github.com/burzomir/unionize#readme","_id":"@burzomir/unionize@2.2.1","_npmVersion":"5.6.0","_nodeVersion":"8.11.1","_npmUser":{"name":"burzomir","email":"burzomirdev@gmail.com"},"dist":{"integrity":"sha512-8zVoRPU4g0OdPxxY0uJL+RezUj8iVQriPrvL2PWMprwHBe8hsK3GQbkNfiDVR+J02b0x5GoE6pjxGTCC98l1zg==","shasum":"17b0fc86c0eea028d87760a7b0aa6f09e4eff4cb","tarball":"https://registry.npmjs.org/@burzomir/unionize/-/unionize-2.2.1.tgz","fileCount":17,"unpackedSize":137590,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbQgo2CRA9TVsSAnZWagAAUsIP/3kkDqlMtS+jfIPQiSXm\ntaUn2dozR7HX3f2B3wwhLMP8TGCmOLmfy1mB6SwYEj9mxGK4A9SZXYYwbT/W\nmK+q/eKt/64+BtCMLYOeunG+/agBMIXwncNsFiDw3XmEp+PxS6195SZLR70m\nc4JnQfJxc4F2uW9wVCcuMGBXQ1gI1wwQCAPG9Rk+aa0snpgGBR7MXHkuq1qM\npFS7U1KyyedYvZzVfscI8U/j0/bz2ZGblLsjrqtXDL89ET8VKSQNGKBM2icV\ntYdvQt69M9yUCOfzUNEIvvJK4YvZhnwhlqd0rjrWFIY1tdSKQe8WMuoUnehj\nQ4fULa1pJy8PuIJSLwzTsNZ/zkvppLLpRyQa91ePAXyAXJduX4z7hJlXxtXO\no8tcUgDMsenMiN/AHj9d9vsjIBBVbnBhvsf8IElJGMbWZDK0FPLDmhRJAy4t\nwy8ZRaEE6NAYAYjr41SjoieuBN7YWAq0tyfoY00CIQ8/A46bvGzdwRtH/J4I\ngHwE4UxqOiZ8pDDH9kOe15x1Npdkqlz9rs1FZsP7eMmbHIgPgxFrcZ9YaS+t\nESugOBXUIT/dx62nMqhDmRDhd8cPx7NIMPcRfBVZ/IE88SKgBYGi4A/p0vbt\nVnIRRf9cQUzh4qsYpycSQf9fqQnB2zCi3UujoWvWoU30uz/U2vW8D9aYKENY\n7gng\r\n=yFve\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCfMzgj8E42qC46TdK1Mn8ggUCdw4usv++wUz8RYnAE8QIhAKcLkMv1Cyu1ItrZB6Rowkb2VD00BdWPVXiQqfzZwa46"}]},"maintainers":[{"name":"burzomir","email":"burzomirdev@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/unionize_2.2.1_1531054646847_0.10565673643530027"},"_hasShrinkwrap":false}},"time":{"created":"2018-07-08T12:44:38.236Z","2.1.2":"2018-07-08T12:44:38.577Z","modified":"2022-04-04T21:08:11.778Z","2.2.0":"2018-07-08T12:50:31.769Z","2.2.1":"2018-07-08T12:57:26.950Z"},"maintainers":[{"name":"burzomir","email":"burzomirdev@gmail.com"}],"description":"Boilerplate-free functional sum types in TypeScript","homepage":"https://github.com/burzomir/unionize#readme","repository":{"type":"git","url":"git+https://github.com/burzomir/unionize.git"},"author":{"name":"Tom Crockett","email":"pelotom@gmail.com"},"bugs":{"url":"https://github.com/burzomir/unionize/issues"},"license":"MIT","readme":"# Unionize [![Build Status](https://travis-ci.org/pelotom/unionize.svg?branch=master)](https://travis-ci.org/pelotom/unionize) [![Coverage Status](https://coveralls.io/repos/github/pelotom/unionize/badge.svg?branch=master)](https://coveralls.io/github/pelotom/unionize?branch=master)\r\n\r\nDefine unions via records for great good!\r\n\r\n## Installation\r\n\r\n```\r\nyarn add unionize\r\n```\r\n\r\n## Example\r\n\r\nProvide `unionize` with a mapping of tags to value types:\r\n```ts\r\nimport { unionize, ofType } from 'unionize'\r\n\r\nconst Actions = unionize({\r\n  ADD_TODO: ofType<{ id: string; text: string }>(),\r\n  SET_VISIBILITY_FILTER: ofType<'SHOW_ALL' | 'SHOW_ACTIVE' | 'SHOW_COMPLETED'>(),\r\n  TOGGLE_TODO: ofType<{ id: string }>(),\r\n  CLEAR_TODOS: {}, // For \"empty\" types, just use {}\r\n},\r\n  // optionally override tag and/or value property names\r\n  {\r\n    tag:'type',\r\n    value:'payload',\r\n  }\r\n);\r\n```\r\n\r\nExtract the inferred tagged union:\r\n```ts\r\ntype Action = UnionOf<typeof Actions>;\r\n```\r\n\r\nThe inferred type is\r\n```ts\r\ntype Action =\r\n  | { type: ADD_TODO; payload: { id: string; text: string } }\r\n  | { type: SET_VISIBILITY_FILTER; payload: 'SHOW_ALL' | 'SHOW_ACTIVE' | 'SHOW_COMPLETED' }\r\n  | { type: TOGGLE_TODO; payload: { id: string } }\r\n  | { type: CLEAR_TODOS; payload: {} };\r\n```\r\n\r\nHaving done that, you now have at your disposal:\r\n\r\n#### Element factories\r\n\r\n```ts\r\nstore.dispatch(Actions.ADD_TODO({ id: 'c819bbc1', text: 'Take out the trash' }));\r\nstore.dispatch(Actions.SET_VISIBILITY_FILTER('SHOW_COMPLETED'));\r\nstore.dispatch(Actions.CLEAR_TODOS()); // no argument required if value type is {}\r\n```\r\n\r\n#### Match expressions\r\n\r\n```ts\r\nconst todosReducer = (state: Todo[] = [], action: Action) =>\r\n  Actions.match(action, {\r\n    // handle cases as pure functions instead of switch statements\r\n    ADD_TODO: ({ id, text }) => [...state, { id, text, completed: false }],\r\n    TOGGLE_TODO: ({ id }) =>\r\n      state.map(todo => todo.id === id\r\n        ? { ...todo, completed: !todo.completed }\r\n        : todo\r\n      ),\r\n    // handles the rest; if not provided, cases must be exhaustive \r\n    default: a => state // a === action. Useful for curried version\r\n  });\r\n```\r\n\r\n`action` can be omitted; in that case the result of match is a function:\r\n\r\n```ts\r\nconst getIdFromAction = Actions.match({\r\n  ADD_TODO: ({ id}) => id,\r\n  TOGGLE_TODO: ({ id }) => id,\r\n  default: a => { throw new Error(`Action type ${a.type} does not have an associated id`); },\r\n});\r\n\r\nconst action = Actions.ADD_TODO({ id: 'c819bbc1', text: 'Take out the trash' });\r\nconst id = getIdFromAction(action); // id === 'c819bbc1'\r\n```\r\n\r\n#### Type guards\r\n\r\n```ts\r\nconst epic = (action$: Observable<Action>) => action$\r\n  .filter(Actions.is.ADD_TODO)\r\n  // The appropriately narrowed type of the resulting observable is inferred...\r\n  .mergeMap(({ payload }) => console.log(payload.text));\r\n```\r\n\r\n#### Type casts\r\n\r\n```ts\r\nconst { id, text } = Actions.as.ADD_TODO(someAction); // throws if someAction is not an ADD_TODO\r\n```\r\n\r\n#### Transform expressions\r\n\r\n`transform` is a shorthand alternative to `match` for when you are converting from the union type to itself, and only want to handle a subset of the cases, leaving the rest unchanged:\r\n\r\n```ts\r\nconst Light = unionize({ On: ofType<{ percentage: number }>(), Off: {} });\r\n\r\nconst turnOn = Light.transform({ Off: () => Light.On({ percentage: 100 }) });\r\nconst dim = Light.transform({ On: prev => Light.On({ percentage: prev.percentage / 2 }) });\r\n\r\nconst off = Light.Off();\r\nconst dimmed = dim(off); //didn't match. so dimmed === off\r\nconst on = turnOn(off);\r\n\r\n// can accept an object right away\r\nconst toggled = Light.transform(on, {\r\n  On: () => Light.Off(),\r\n  Off: () => Light.On({ percentage: 50 }),\r\n});\r\n```\r\n\r\n#### Breaking changes from 1.0.1\r\n**config object**\r\n\r\nNow `unionize` accepts an optional config object instead of two additional arguments.\r\n\r\n```ts\r\n// before\r\nunionize({...}, 'myTag', 'myPayloadProp');\r\nunionize({...}, 'myTag');\r\n\r\n// after\r\nunionize({...}, { tag:'myTag', value:'myPayloadProp' });\r\nunionize({...}, { tag:'myTag' });\r\nunionize({...}, { value:'myPayloadProp' }); // <-- previously not possible\r\n```\r\n\r\n**`match`**\r\n\r\nWhereas previously `match` was always curried, now it can alternatively accept the object to match as a first argument. Additionally, the default case is now expressed as just another property in the cases object.\r\n\r\n```ts\r\n// before\r\nLight.match({\r\n  On: () => 'is on'\r\n}, () => 'is off'\r\n)(light);\r\n\r\n// after\r\nLight.match({\r\n  On: () => 'is on',\r\n  default: () =>'is off'\r\n})(light);\r\nLight.match(light, {\r\n  On: () => 'is on',\r\n  default: () => 'is off',\r\n});\r\n```\r\n","readmeFilename":"README.md"}