{"_id":"@aminnairi/decode","_rev":"1-16efd3e5cf29e922cd81294ca417ce08","name":"@aminnairi/decode","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"author":{"name":"Amin NAIRI","url":"https://github.com/aminnairi/"},"bugs":{"url":"https://github.com/aminnairi/node-decode/issues"},"description":"Check that your data meet your expectations.","homepage":"https://github.com/aminnairi/node-decode","keywords":["decode","data","expectations","check","schema"],"license":"GPL-3.0-or-later","main":"release/decode.js","name":"@aminnairi/decode","version":"0.1.0","scripts":{"test":"mocha tests/**/*.spec.mjs","build":"rollup --config rollup.config.js"},"devDependencies":{"chai":"4.3.4","mocha":"8.3.2","rollup":"2.42.4","rollup-plugin-terser":"7.0.2"},"gitHead":"915753490b579588420d3fdee02cb50803afa37c","_id":"@aminnairi/decode@0.1.0","_nodeVersion":"15.0.0","_npmVersion":"7.0.2","dist":{"integrity":"sha512-9iX7cp/t7mN9PaiKQMvVgqG9Lq38VrehccvzKV0BZ8NFvcHN/nHBPm1p8DkLcyhbtsFTvbjeA7tUpHWxYuQfjw==","shasum":"9b963b58efecdecf3f1cecd3bce1380cb634a650","tarball":"https://registry.npmjs.org/@aminnairi/decode/-/decode-0.1.0.tgz","fileCount":5,"unpackedSize":40139,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgXI7xCRA9TVsSAnZWagAA0tcP/3eJL8Z1+9tZ5vNP3lIi\nwhUXWxoFmdkvTxS1mAVzZBq9P1e8SCHsAI2Akt5TtogPA3JJmdNsISngXQ9n\ndNihyeUG33BJWG2zVLM7SymncVva5FJKJjyXsw5CI/N2sF00R38t9JKlGaDT\nD73n84yml3JkV0aX/8p5qPhzKdtVdUQE2IFacVSKvYxIghuC2GVw7Wp196uj\nbBupMjJEkmtAKEV2MIlFHR3fZS2hePJvkIG8HnkgtdTji2ZR7oACw2ZC4y1H\nC/onZearwbOPPeB8Vilw9XjLs29h6YkvxPVwu8c7fcg1van9N7JOmX2A2DH6\n4eTJzBaFLq4s5zNeFtzRXIgZfV0rdlAWNWcyaCUCmUgtIvlqqcDfSAYNImb2\nlU+U5c2OxzY/b35t4ZBTUel7qb6wuYtLO/40d+Vdij9qea5gl4uOa8XlHb0o\n87kI6OqDwR4Ab6CSLv/qH4/wS3m5Q59mrhK0IUPuHPp/wB0bm2oVlwfKR8X9\nfNIayO86AzFeeiO4fajQLPP8e8WpmqbV6XL08QmVCRltty/tcsEpLR2s+sJx\nuf5Er7MQFp7tlcrzywEQzvq9lj5YATeCCmiqlNgwudksH/L3oocMjpyN8A4R\niGR39luZV37AyOf+GnAamz0vFAKvcvzwCkRzXP3RF9cFm4WK/b4j3/1KnNmd\niqFC\r\n=R5iP\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDHelJCGHi6zg5pjHLJLoH8O7GZC3AwsBsXRk/ZR37hDQIgLWYzq2iEhkCliuLp1dzgirfFlcH4PZKHmSIg5e6rmZw="}]},"_npmUser":{"name":"aminnairi","email":"nairi.amin@gmail.com"},"directories":{},"maintainers":[{"name":"aminnairi","email":"nairi.amin@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/decode_0.1.0_1616678641438_0.882332264008066"},"_hasShrinkwrap":false}},"time":{"created":"2021-03-25T13:24:01.372Z","0.1.0":"2021-03-25T13:24:01.554Z","modified":"2022-04-04T13:49:18.244Z"},"maintainers":[{"name":"aminnairi","email":"nairi.amin@gmail.com"}],"description":"Check that your data meet your expectations.","homepage":"https://github.com/aminnairi/node-decode","keywords":["decode","data","expectations","check","schema"],"author":{"name":"Amin NAIRI","url":"https://github.com/aminnairi/"},"bugs":{"url":"https://github.com/aminnairi/node-decode/issues"},"license":"GPL-3.0-or-later","readme":"# node-decode\n\nCheck that your data meet your expectations.\n\n[![Test](https://github.com/aminnairi/node-decode/actions/workflows/test.yaml/badge.svg?branch=latest)](https://github.com/aminnairi/node-decode/actions/workflows/test.yaml) [![Publish](https://github.com/aminnairi/node-decode/actions/workflows/publish.yaml/badge.svg)](https://github.com/aminnairi/node-decode/actions/workflows/publish.yaml)\n\n## Requirements\n\n- Node\n\n## Usage\n\n### Simple\n\n```console\n$ npm install @aminnairi/decode\n$ touch index.mjs\n```\n\n```javascript\nimport {decode} from \"@aminnairi/decode\";\n\nconst schema    = \"string\";\nconst goodData  = \"Hello world\";\nconst badData   = 123;\n\nconsole.log(decode(schema, goodData));\nconsole.log(decode(schema, badData));\n```\n\n```console\n$ node index.mjs\ntrue\nfalse\n```\n\n### Array\n\n```console\n$ npm install @aminnairi/decode\n$ touch index.mjs\n```\n\n```javascript\nimport {decode} from \"@aminnairi/decode\";\n\nconst schema    = [\"string\"];\nconst goodData  = [\"Hello\", \"world\"];\nconst badData   = [\"Hello\", 123];\n\nconsole.log(decode(schema, goodData));\nconsole.log(decode(schema, badData));\n```\n\n```console\n$ node index.mjs\ntrue\nfalse\n```\n\n### Object\n\n```console\n$ npm install @aminnairi/decode\n$ touch index.mjs\n```\n\n```javascript\nimport {decode} from \"@aminnairi/decode\";\n\nconst schema    = {user: \"string\", age: \"number\"};\nconst goodData  = {user: \"john\", age: 42};\nconst badData   = {user: \"jane\", age: \"24\"};\n\nconsole.log(decode(schema, goodData));\nconsole.log(decode(schema, badData));\n```\n\n```console\n$ node index.mjs\ntrue\nfalse\n```\n\n### Object (loose)\n\n```console\n$ npm install @aminnairi/decode\n$ touch index.mjs\n```\n\n```javascript\nimport {decode} from \"@aminnairi/decode\";\n\nconst schema    = {user: \"string\", age: \"number\"};\nconst goodData  = {user: \"john\", age: 42, isAdmin: false};\nconst badData   = {user: \"jane\", age: \"24\", isAdmin: false};\n\nconsole.log(decode(schema, goodData));\nconsole.log(decode(schema, badData));\n```\n\n```console\n$ node index.mjs\ntrue\nfalse\n```\n\n### Array of objects\n\n```console\n$ npm install @aminnairi/decode\n$ touch index.mjs\n```\n\n```javascript\nimport {decode} from \"@aminnairi/decode\";\n\nconst schema    = [{user: \"string\", age: \"number\"}];\nconst goodData  = [{user: \"john\", age: 42}, {user: \"jane\", age: 24}];\nconst badData   = [{user: \"john\", age: \"42\"}, {user: \"jane\", age: 24}];\n\nconsole.log(decode(schema, goodData));\nconsole.log(decode(schema, badData));\n```\n\n```console\n$ node index.mjs\ntrue\nfalse\n```\n\n## Example\n\n```console\n$ npm install node-fetch @aminnairi/decode\n$ touch index.mjs\n```\n\n```javascript\nimport fetch from \"node-fetch\";\nimport {decode} from \"@aminnairi/decode\";\n\nconst usersSchema = [{\n  id: \"number\",\n  name: \"string\",\n  username: \"string\",\n  email: \"string\",\n  address: {\n    street: \"string\",\n    suite: \"string\",\n    city: \"string\",\n    zipcode: \"string\",\n    geo: {\n      lat: \"string\",\n      lng: \"string\"\n    }\n  },\n  phone: \"string\",\n  website: \"string\",\n  company: {\n    name: \"string\",\n    catchPhrase: \"string\",\n    bs: \"string\"\n  }\n}];\n\nfetch(\"https://jsonplaceholder.typicode.com/users/\").then(response => {\n  return response.json();\n}).then(users => {\n  if (!decode(usersSchema, users)) {\n    throw new Error(\"Bad response from the server (has the API changed?)\");\n  }\n  console.log(\"Do something with the users.\");\n}).catch(({message}) => {\n  console.error(message);\n});\n```\n\n```console\n$ node index.mjs\nDo something with the users.\n```\n\n## Changelog\n\nSee [`CHANGELOG.md`](./CHANGELOG.md).\n\n## Contributing\n\nSee [`CONTRIBUTING.md`](./CONTRIBUTING.md).\n\n## License\n\nSee [`LICENSE`](./LICENSE).\n","readmeFilename":"README.md"}