{"_id":"@chaucerbao/suplex","_rev":"2-aad97396eeb04b8ee3e37777465eb522","name":"@chaucerbao/suplex","description":"A simple, yet efficient, store management library","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"@chaucerbao/suplex","description":"A simple, yet efficient, store management library","version":"0.1.0","author":{"name":"Alvin Chan","email":"no@email.com"},"license":"MIT","main":"dist/index.js","types":"dist/index.d.ts","files":["dist/index.js","dist/index.d.ts"],"lint-staged":{"*.ts":["prettier --write --no-semi --single-quote","git add"]},"devDependencies":{"@types/isomorphic-fetch":"0.0.34","@types/nock":"^8.2.1","ava":"^0.20.0","husky":"^0.14.3","lint-staged":"^4.0.1","nock":"^9.0.13","prettier":"^1.5.2","typescript":"^2.4.1"},"dependencies":{"isomorphic-fetch":"^2.2.1"},"scripts":{"start":"tsc --watch & ava --watch & wait","test":"tsc && ava","precommit":"lint-staged","prepare":"tsc --declaration && ava"},"gitHead":"08673f377447b084ecc78772763fd8a637d272d6","_id":"@chaucerbao/suplex@0.1.0","_npmVersion":"5.2.0","_nodeVersion":"8.1.4","_npmUser":{"name":"chaucerbao","email":"aschan98@yahoo.com"},"dist":{"integrity":"sha512-k+JrvEUsUFu2sINS/2QLkfXL9q1HVAOC1NqbzJpWLCr5AN/uG3ihbeU3ta7VscXD68HJExgsOnUpeJpDfGcQ5w==","shasum":"8fdf7de8134368ab198bf05ba603e6036a360ecf","tarball":"https://registry.npmjs.org/@chaucerbao/suplex/-/suplex-0.1.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDla0m5+czFWpPj4KGf/l7Rv4t8t6t6o7vN9w8BvUYsyQIgKJa1f/kZvyHgx99ykGr0zNXFujh+bb127v2x3mFxyS4="}]},"maintainers":[{"name":"chaucerbao","email":"aschan98@yahoo.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/suplex-0.1.0.tgz_1500316882719_0.2910353043116629"}},"0.1.1":{"name":"@chaucerbao/suplex","description":"A simple, yet efficient, store management library","version":"0.1.1","author":{"name":"Alvin Chan","email":"no@email.com"},"license":"MIT","main":"dist/index.js","types":"dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/chaucerbao/suplex.git"},"bugs":{"url":"https://github.com/chaucerbao/suplex/issues"},"homepage":"https://github.com/chaucerbao/suplex#readme","files":["dist/index.js","dist/index.d.ts"],"lint-staged":{"*.ts":["prettier --write --no-semi --single-quote","git add"]},"devDependencies":{"@types/isomorphic-fetch":"0.0.34","@types/nock":"^8.2.1","ava":"^0.21.0","husky":"^0.14.3","lint-staged":"^4.0.2","nock":"^9.0.14","prettier":"^1.5.3","typescript":"^2.4.1"},"dependencies":{"isomorphic-fetch":"^2.2.1"},"scripts":{"start":"tsc --watch & ava --watch & wait","test":"tsc && ava","precommit":"lint-staged","prepare":"tsc --declaration && ava"},"gitHead":"1a9522f803649021c004992f8b072eb26eb88225","_id":"@chaucerbao/suplex@0.1.1","_npmVersion":"5.2.0","_nodeVersion":"8.1.4","_npmUser":{"name":"chaucerbao","email":"aschan98@yahoo.com"},"dist":{"integrity":"sha512-fGvUsDv7aP2z31XgyF3npHUvml0yu+LJqNAAp+wbBsfLNIl7k0mbgLy0fXtrVW3dRXIu+mjpoGIT5iXD8bYozg==","shasum":"600cda66b996f59cf089faa2b9340a04b916b8da","tarball":"https://registry.npmjs.org/@chaucerbao/suplex/-/suplex-0.1.1.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAtbPkoX7BMeiPkCNYJ29ptMXg02chWYljEMOWmQFoiOAiEAkOh939Fgg3yhisolNrpeD+ppd45xntErCOe7+hcOLBo="}]},"maintainers":[{"name":"chaucerbao","email":"aschan98@yahoo.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/suplex-0.1.1.tgz_1500321530219_0.5413059093989432"}}},"readme":"# Suplex\nA simple, yet efficient, store management library\n\n## Installation\n\n```sh\nnpm install --save @chaucerbao/suplex\n```\n\n## Quick Start\nCreate your own models and stores, then attach Suplex\n\n```ts\nimport suplex from '@chaucerbao/suplex'\n\n// Start by defining some model\nclass User {\n  id: 0\n  name: ''\n  email: ''\n}\n\n// Then, create a store to manage those models\nclass UserStore {\n  suplex: any\n\n  constructor() {\n    this.suplex = suplex(User, 'id')\n  }\n\n  // Make an array to hold all the users\n  all = []\n\n  // And a function to fetch and load a list of users from some API\n  async fetchAll() {\n    const response = await this.suplex.fetch(\n      '//jsonplaceholder.typicode.com/users'\n    )\n    this.all = this.suplex.load(response.body)\n  }\n}\n\n// Now, initialize the store\nconst userStore = new UserStore()\n\n// And access your data!\nasync function callApi() {\n  await userStore.fetchAll()\n\n  console.log(userStore.all.length)\n}\n\ncallApi()\n```\n\n## Usage\n\n**suplex(Model, idProp)**\n\nCreate a Suplex store to manage your models\n\n```js\nclass TheModel {\n  uniqueId: 0\n  someProp: ''\n}\n\nconst suplexStore = suplex(TheModel, 'uniqueId')\n```\n\n### Suplex store API\n\n**.get(id, [props])** => Model\n\nDispenses a model from the store's internal storage, and optionally update its properties.\n\n```js\nconst instance = suplexStore.get(20, {\n  someProp: 'Updated value'\n})\n```\n\n**.load(collection, [transform])** => Model[]\n\nLoops over an array of objects, injecting each object into a model and storing it. If a `transform` callback is given, each object will run through the callback before being passed into the model. This is useful for processing a JSON response before consuming it (e.g. rename properties, filter values).\n\n```js\nconst arrayOfModels = suplexStore.load(\n  [\n    { uniqueId: 1, wrongName: \"One\" },\n    { uniqueId: 2, wrongName: \"Two\" }\n  ],\n\n  // Callback to rename the `wrongName` property into `someProp`\n  model => ({ uniqueId: model.uniqueId, someProp: model.wrongName })\n)\n```\n\n**.fetch(request)** => Response\n\nMakes an API call and returns the response. If there's a duplicate request while one is still pending, an error is thrown.\n\n```js\nasync callApi function() {\n  const response = await suplexStore.fetch(\"http://api.domain.com/\")\n\n  // Content of the response is in `response.body`\n  console.log(response.body)\n}\n```\n","maintainers":[{"name":"chaucerbao","email":"aschan98@yahoo.com"}],"time":{"modified":"2022-04-04T22:34:13.239Z","created":"2017-07-17T18:41:22.807Z","0.1.0":"2017-07-17T18:41:22.807Z","0.1.1":"2017-07-17T19:58:50.324Z"},"author":{"name":"Alvin Chan","email":"no@email.com"},"license":"MIT","readmeFilename":"README.md","homepage":"https://github.com/chaucerbao/suplex#readme","repository":{"type":"git","url":"git+https://github.com/chaucerbao/suplex.git"},"bugs":{"url":"https://github.com/chaucerbao/suplex/issues"}}