{"_id":"@aliksend/fn","_rev":"2-ff27b9035df6e4189f0e2e121bb166ea","name":"@aliksend/fn","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@aliksend/fn","version":"1.0.0","keywords":["zod","runtime type check","validation","function"],"author":{"name":"Alik Send"},"license":"MIT","_id":"@aliksend/fn@1.0.0","maintainers":[{"name":"aliksend","email":"aliknoname@gmail.com"}],"homepage":"https://github.com/aliksend/node-packages#readme","bugs":{"url":"https://github.com/aliksend/node-packages/issues"},"dist":{"shasum":"7dca3fae05db34813ea0e5670661410389aa1dc0","tarball":"https://registry.npmjs.org/@aliksend/fn/-/fn-1.0.0.tgz","fileCount":59,"integrity":"sha512-Axrfc+vdkDgFjODOUrioxJkWy3BPIeMfqwl67YbFb0uhPkJqM68xhFJHU16pRZx3PAd260V+QIfIYqsl62e64A==","signatures":[{"sig":"MEQCID3QrEqXOabcCIpm1R+5NW29Nf9DYZ9BaOYaqop4CaxmAiA7V9KYtBeuFL+EpY+wlbUImByXi1pxTIttiiQZQvvONg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":85617},"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"lint":"npx @aliksend/linter --fix","test":"node --require ts-node/register --test ./src/*.test.ts","build":"rm -rf dist && tsc","prepublishOnly":"npm run build"},"_npmUser":{"name":"aliksend","email":"aliknoname@gmail.com"},"repository":{"url":"git+https://github.com/aliksend/node-packages.git","type":"git"},"_npmVersion":"9.8.1","description":"Functions with realtime type checking","directories":{},"_nodeVersion":"18.18.2","dependencies":{"zod":"^3.22.4"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"ts-node":"^10.9.2","typescript":"^5.3.3"},"_npmOperationalInternal":{"tmp":"tmp/fn_1.0.0_1707737380191_0.24387915186464393","host":"s3://npm-registry-packages"}},"1.0.1":{"name":"@aliksend/fn","version":"1.0.1","keywords":["zod","runtime type check","validation","function"],"author":{"name":"Alik Send"},"license":"MIT","_id":"@aliksend/fn@1.0.1","maintainers":[{"name":"aliksend","email":"aliknoname@gmail.com"}],"homepage":"https://github.com/aliksend/node-packages#readme","bugs":{"url":"https://github.com/aliksend/node-packages/issues"},"dist":{"shasum":"7f5a636894c6769c28a30ce5ae6d33c187ee70aa","tarball":"https://registry.npmjs.org/@aliksend/fn/-/fn-1.0.1.tgz","fileCount":59,"integrity":"sha512-st5T8sT9t5jexqxnujtzKtr+5xFLMpZSujIJij6ZM2Q6bIcFKaY8odycJK9kssYJSF1dSKFAac6I0Pp3b9AATw==","signatures":[{"sig":"MEUCIQDIGsyiBSWSmTNuafFNeze+q0nbB0q/jcVYXnINdZMHwAIgC7wYeqRkOqB5zY8GZkjOM3NDZ5rxsJb4yDAveu2LPSw=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":85991},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"18be42dcd2321ff5754d221a784795c9062e8598","scripts":{"lint":"npx @aliksend/linter --fix","test":"node --require ts-node/register --test ./src/*.test.ts","build":"rm -rf dist && tsc","prepublishOnly":"npm run build"},"_npmUser":{"name":"aliksend","email":"aliknoname@gmail.com"},"repository":{"url":"git+https://github.com/aliksend/node-packages.git","type":"git"},"_npmVersion":"9.8.1","description":"Functions with realtime type checking","directories":{},"_nodeVersion":"18.18.2","dependencies":{"zod":"^3.22.4"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"ts-node":"^10.9.2","typescript":"^5.3.3"},"_npmOperationalInternal":{"tmp":"tmp/fn_1.0.1_1707831062572_0.2197312417513253","host":"s3://npm-registry-packages"}},"1.0.2":{"name":"@aliksend/fn","version":"1.0.2","description":"Functions with realtime type checking","keywords":["zod","runtime type check","validation","function"],"repository":{"type":"git","url":"git+https://github.com/aliksend/node-packages.git"},"license":"MIT","author":{"name":"Alik Send"},"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"rm -rf dist && tsc","lint":"npx @aliksend/linter --fix","prepublishOnly":"npm run build","test":"node --require ts-node/register --test ./src/*.test.ts"},"dependencies":{"zod":"^3.22.4"},"devDependencies":{"ts-node":"^10.9.2","typescript":"^5.3.3"},"publishConfig":{"access":"public"},"_id":"@aliksend/fn@1.0.2","gitHead":"5aaf136564eee9897f7f623f0bcd74478798ed0e","bugs":{"url":"https://github.com/aliksend/node-packages/issues"},"homepage":"https://github.com/aliksend/node-packages#readme","_nodeVersion":"20.8.1","_npmVersion":"10.1.0","dist":{"integrity":"sha512-ayWL0kSk8D6XAsQzJ/0MndWgXkq5coGPeOB3E5dQjGyG3+lGa5JRFtDbRSbWYkwHpedWXIpU3PvwvCjQMEXVIA==","shasum":"4b6368607e8607f4d88f35c3d6739b97bb301b48","tarball":"https://registry.npmjs.org/@aliksend/fn/-/fn-1.0.2.tgz","fileCount":59,"unpackedSize":118560,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQClujC+eRWqFwM4kERjUSQch8fgN/8yu8w9KQj9NtCi1AIhAN3YuSAgMp19ajmhDCChvSqU2TNsJ3496J7zDLP/xSpz"}]},"_npmUser":{"name":"aliksend","email":"aliknoname@gmail.com"},"directories":{},"maintainers":[{"name":"aliksend","email":"aliknoname@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fn_1.0.2_1725047911101_0.9491912199774422"},"_hasShrinkwrap":false}},"time":{"created":"2024-02-12T11:29:40.073Z","modified":"2024-08-30T19:58:31.425Z","1.0.0":"2024-02-12T11:29:40.407Z","1.0.1":"2024-02-13T13:31:02.743Z","1.0.2":"2024-08-30T19:58:31.247Z"},"bugs":{"url":"https://github.com/aliksend/node-packages/issues"},"author":{"name":"Alik Send"},"license":"MIT","homepage":"https://github.com/aliksend/node-packages#readme","keywords":["zod","runtime type check","validation","function"],"repository":{"type":"git","url":"git+https://github.com/aliksend/node-packages.git"},"description":"Functions with realtime type checking","maintainers":[{"name":"aliksend","email":"aliknoname@gmail.com"}],"readme":"# fn\n\nThis module allows to make functions with typechecking\n\nExample:\n```typescript\nimport { z } from 'zod'\n\nconst typedParseInt = Fn.build({\n  request: z.string(),\n  response: z.number().int()\n}).init((req) => {\n  return parseInt(req)\n})\n\nconst parsed = await typedParseInt('123')\nconsole.log(parsed)\n\n// Output:\n// 123\n```\n\nIt also supports AsyncIterators\n\n```typescript\nimport { z } from 'zod'\n\nconst fn = Fn.build({\n  request: z.string(),\n  response: z.number().int(),\n  responseType: 'asynciterable',\n}).init((req) => {\n  const values = req.split(' ')\n  return {\n    [Symbol.asyncIterator]: () => ({\n      async next () {\n        if (values.length === 0) {\n          return { done: true, value: undefined as any } // https://github.com/microsoft/TypeScript/issues/38479\n        }\n        return { value: parseInt(values.shift()!) }\n      },\n    }),\n  }\n})\n\nfor await (const parsed of fn('123 465')) {\n  console.log(parsed)\n}\n\n// Output:\n// 123\n// 456\n```\n\nAnd middlewares like\n[lock](https://github.com/aliksend/typed-fn/blob/main/src/middlewares/lock.test.ts) (don't allow to call callback simultaneuosly),\n[cache](https://github.com/aliksend/typed-fn/blob/main/src/middlewares/cache.test.ts) and\n[expiration](https://github.com/aliksend/typed-fn/blob/main/src/middlewares/expiration.test.ts) (allows to set timeout for callback)\n","readmeFilename":"README.md"}