{"_id":"@blinkmobile/json-as-files","_rev":"15-5553d6c2f560a10575b3c43276f2af78","name":"@blinkmobile/json-as-files","description":"convert between files and JSON strings, maintaining certain values as separate files","dist-tags":{"latest":"1.2.1"},"versions":{"1.0.0":{"name":"@blinkmobile/json-as-files","description":"convert between files and JSON strings, maintaining certain values as separate files","version":"1.0.0","bugs":{"url":"https://github.com/blinkmobile/json-as-files.js/issues"},"dependencies":{"graceful-fs":"4.1.2","json3":"3.3.2","lodash.isequal":"3.0.4","traverse":"0.6.6"},"devDependencies":{"@jokeyrhyme/eslint-config-es2015":"^1.0.0","@jokeyrhyme/eslint-config-es5":"^1.0.0","ava":"0.6.1","eslint":"^1.9.0","eslint-config-semistandard":"^5.0.0","eslint-config-standard":"^4.4.0","eslint-plugin-standard":"^1.3.1","fixpack":"^2.2.0","mkdirp":"0.5.1","nyc":"^3.2.2"},"engines":{"node":">=5.0.0","npm":">=3.0.0"},"homepage":"https://github.com/blinkmobile/json-as-files.js#readme","keywords":[],"license":"BSD-3-Clause","main":"index.js","repository":{"type":"git","url":"git+https://github.com/blinkmobile/json-as-files.js.git"},"scripts":{"eslint":"eslint --fix .","fixpack":"fixpack","nyc":"nyc check-coverage -f 80 -l 80 -s 80","posttest":"npm run nyc && npm run eslint && npm run fixpack","test":"nyc ava tests/**/*.js"},"gitHead":"0780e3ed11d2c6a67bf78b09030b8d50e1664565","_id":"@blinkmobile/json-as-files@1.0.0","_shasum":"ad717a1bb0d60e163b0802f9b4bbcbc2d1d64aa0","_from":".","_npmVersion":"3.5.1","_nodeVersion":"5.1.0","_npmUser":{"name":"blinkmobile","email":"ron@blinkmobile.com.au"},"dist":{"shasum":"ad717a1bb0d60e163b0802f9b4bbcbc2d1d64aa0","tarball":"https://registry.npmjs.org/@blinkmobile/json-as-files/-/json-as-files-1.0.0.tgz","integrity":"sha512-M7a3MnyrrGSTvi0a2M7Rs/+ewDCcnXAHHaNPwLhH9WwoZdOcef92dLupfAWwdLfYjx8YWUqRGxK2spHjvDgc9A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEjE1Hfhmtxx4nsFIEeRYUDWoAsHsZxuk30lTgEqIUINAiByyHWjcmNwKv18Iliv9Vl6D0nSEQbvajZCVSxIYGA76Q=="}]},"maintainers":[{"name":"blinkmobile","email":"ron@blinkmobile.com.au"}],"directories":{},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."},"1.1.0":{"name":"@blinkmobile/json-as-files","description":"convert between files and JSON strings, maintaining certain values as separate files","version":"1.1.0","bugs":{"url":"https://github.com/blinkmobile/json-as-files.js/issues"},"dependencies":{"graceful-fs":"^4.1.3","load-json-file":"^1.1.0","lodash.isequal":"^4.0.0","pify":"^2.3.0","traverse":"0.6.6","write-json-file":"^1.2.0"},"devDependencies":{"@jokeyrhyme/eslint-config-es2015":"^1.0.0","@jokeyrhyme/eslint-config-es5":"^1.0.0","ava":"^0.11.0","eslint":"^1.9.0","eslint-config-semistandard":"^5.0.0","eslint-config-standard":"^4.4.0","eslint-plugin-standard":"^1.3.1","fixpack":"^2.2.0","mkdirp":"^0.5.1","nyc":"^5.6.0","temp":"0.8.3"},"engines":{"node":">=4.0.0","npm":">=3.0.0"},"homepage":"https://github.com/blinkmobile/json-as-files.js#readme","keywords":[],"license":"BSD-3-Clause","main":"index.js","repository":{"type":"git","url":"git+https://github.com/blinkmobile/json-as-files.js.git"},"scripts":{"eslint":"eslint --fix .","fixpack":"fixpack","nyc":"nyc check-coverage -f 80 -l 80 -s 80","posttest":"npm run nyc && npm run eslint && npm run fixpack","test":"nyc ava tests/**/*.js"},"gitHead":"5e5885e25260188f5fc00e1f08fb2785aa2b4655","_id":"@blinkmobile/json-as-files@1.1.0","_shasum":"37851dfe45d7ff21045f2da36b026252c194a2f9","_from":".","_npmVersion":"3.7.1","_nodeVersion":"5.6.0","_npmUser":{"name":"jokeyrhyme","email":"jokeyrhyme@gmail.com"},"dist":{"shasum":"37851dfe45d7ff21045f2da36b026252c194a2f9","tarball":"https://registry.npmjs.org/@blinkmobile/json-as-files/-/json-as-files-1.1.0.tgz","integrity":"sha512-keeVgC/39e5Qq5K76R4j/NKHT1pIohVbRbNSmAL15x90eZZOnNMtk0uUuw4UFNBSMBEtUWYqTfMwCbj4NVAwUQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCp1DPheIs46ml2QyV6VBgBB3DGCKpYW3A4Gk/SHXtHbwIhAPlhTENgktqV2XGJ+a4ZpjR40XLNEDT124gWpN4Iruhr"}]},"maintainers":[{"name":"blinkmobile","email":"ron@blinkmobile.com.au"},{"name":"jokeyrhyme","email":"jokeyrhyme@gmail.com"}],"_npmOperationalInternal":{"host":"packages-6-west.internal.npmjs.com","tmp":"tmp/json-as-files-1.1.0.tgz_1455238020429_0.07150823692791164"},"directories":{},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."},"1.1.1":{"name":"@blinkmobile/json-as-files","description":"convert between files and JSON strings, maintaining certain values as separate files","version":"1.1.1","bugs":{"url":"https://github.com/blinkmobile/json-as-files.js/issues"},"dependencies":{"graceful-fs":"^4.1.3","load-json-file":"^1.1.0","lodash.isequal":"^4.0.0","mkdirp":"^0.5.1","pify":"^2.3.0","traverse":"0.6.6","write-json-file":"^1.2.0"},"devDependencies":{"@jokeyrhyme/eslint-config-es2015":"^1.0.0","@jokeyrhyme/eslint-config-es5":"^1.0.0","ava":"^0.11.0","eslint":"^1.9.0","eslint-config-semistandard":"^5.0.0","eslint-config-standard":"^4.4.0","eslint-plugin-standard":"^1.3.1","fixpack":"^2.2.0","mkdirp":"^0.5.1","nyc":"^5.6.0","temp":"0.8.3"},"engines":{"node":">=4.0.0","npm":">=3.0.0"},"homepage":"https://github.com/blinkmobile/json-as-files.js#readme","keywords":[],"license":"BSD-3-Clause","main":"index.js","repository":{"type":"git","url":"git+https://github.com/blinkmobile/json-as-files.js.git"},"scripts":{"eslint":"eslint --fix .","fixpack":"fixpack","nyc":"nyc check-coverage -f 80 -l 80 -s 80","posttest":"npm run nyc && npm run eslint && npm run fixpack","test":"nyc ava tests/**/*.js"},"gitHead":"8b8f4f8359b6faccbd0f999d924383e5e005c8dc","_id":"@blinkmobile/json-as-files@1.1.1","_shasum":"dc6cdc350ed48d4e13b17fc72424433aedf9811b","_from":".","_npmVersion":"3.7.1","_nodeVersion":"5.6.0","_npmUser":{"name":"jokeyrhyme","email":"jokeyrhyme@gmail.com"},"dist":{"shasum":"dc6cdc350ed48d4e13b17fc72424433aedf9811b","tarball":"https://registry.npmjs.org/@blinkmobile/json-as-files/-/json-as-files-1.1.1.tgz","integrity":"sha512-xFkLXKmIpsvhxgKb8rqijvcmwoBB72tqAgyuq1PMwCNFOQLMLbe0iKbw9rMzwnpOsKx1lKtUkNtZHYw21pm6HQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGF2FbRcVWiJ3I708KRL6jb9FvHNKx3vnD7bsEAwMVP6AiARJGv6q8mua9dSXMlcL7tyr1550rOLMTQeY7ZtiF78YA=="}]},"maintainers":[{"name":"blinkmobile","email":"ron@blinkmobile.com.au"},{"name":"jokeyrhyme","email":"jokeyrhyme@gmail.com"}],"_npmOperationalInternal":{"host":"packages-5-east.internal.npmjs.com","tmp":"tmp/json-as-files-1.1.1.tgz_1455248784881_0.17427164083346725"},"directories":{},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."},"1.2.0":{"name":"@blinkmobile/json-as-files","description":"convert between files and JSON strings, maintaining certain values as separate files","version":"1.2.0","bugs":{"url":"https://github.com/blinkmobile/json-as-files.js/issues"},"dependencies":{"@jokeyrhyme/pify-fs":"^1.0.1","load-json-file":"^2.0.0","lodash.isequal":"^4.0.0","mkdirp":"^0.5.1","pify":"^2.3.0","traverse":"0.6.6","write-json-file":"^2.0.0"},"devDependencies":{"ava":"^0.16.0","eslint":"^3.3.1","eslint-config-semistandard":"^7.0.0-beta.0","eslint-config-standard":"^6.0.0-beta.1","eslint-plugin-promise":"^2.0.0","eslint-plugin-standard":"^2.0.0","fixpack":"^2.2.0","flow-bin":"^0.30.0","mkdirp":"^0.5.1","nyc":"^8.1.0","temp":"^0.8.3"},"directories":{"test":"tests"},"engines":{"node":">=4.0.0","npm":">=3.0.0"},"homepage":"https://github.com/blinkmobile/json-as-files.js#readme","keywords":["content","data","files","json"],"license":"BSD-3-Clause","main":"index.js","publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/blinkmobile/json-as-files.js.git"},"scripts":{"ava":"nyc ava tests/**/*.js","eslint":"eslint --fix --cache .","fixpack":"fixpack","flow_check":"flow check || exit 0","nyc":"nyc check-coverage","posttest":"npm run eslint && npm run flow_check && npm run fixpack","test":"npm run ava && npm run nyc"},"gitHead":"1757386a7cdb66119f271cda0280685c171b4a77","_id":"@blinkmobile/json-as-files@1.2.0","_shasum":"c3e7e7619778d9c5f696d14bad727474b7ee5a67","_from":".","_npmVersion":"3.10.7","_nodeVersion":"6.4.0","_npmUser":{"name":"jokeyrhyme","email":"jokeyrhyme@gmail.com"},"dist":{"shasum":"c3e7e7619778d9c5f696d14bad727474b7ee5a67","tarball":"https://registry.npmjs.org/@blinkmobile/json-as-files/-/json-as-files-1.2.0.tgz","integrity":"sha512-AHKhVUOHqW+FXJM/UZsKR/c7gZiz/YsM0cX8yapY5WBadthOR1Fo7imGpk52aks+whJ/ZWt66MtPqX04CI8+/w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCnA6EyLQ0sj9654p4IhNqoy4sfeDXUteoA1Nb/cTxP8wIgHIONupGtv3zmFjoPLCsRzbvYOE9mH3cIj/Njv8k6DLE="}]},"maintainers":[{"name":"blinkmobile","email":"ron@blinkmobile.com.au"},{"name":"jokeyrhyme","email":"jokeyrhyme@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/json-as-files-1.2.0.tgz_1471586160957_0.9126983878668398"},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."},"1.2.1":{"name":"@blinkmobile/json-as-files","description":"convert between files and JSON strings, maintaining certain values as separate files","version":"1.2.1","bugs":{"url":"https://github.com/blinkmobile/json-as-files.js/issues"},"dependencies":{"@jokeyrhyme/pify-fs":"^1.0.1","load-json-file":"^2.0.0","lodash.isequal":"^4.0.0","lodash.isstring":"^4.0.1","mkdirp":"^0.5.1","pify":"^2.3.0","traverse":"0.6.6","write-json-file":"^2.0.0"},"devDependencies":{"ava":"^0.16.0","eslint":"^3.3.1","eslint-config-semistandard":"^7.0.0-beta.0","eslint-config-standard":"^6.0.0-beta.1","eslint-plugin-promise":"^2.0.0","eslint-plugin-standard":"^2.0.0","fixpack":"^2.2.0","flow-bin":"^0.32.0","greenkeeper-postpublish":"^1.0.1","mkdirp":"^0.5.1","nyc":"^8.1.0","temp":"^0.8.3"},"directories":{"test":"tests"},"engines":{"node":">=4.0.0","npm":">=3.0.0"},"homepage":"https://github.com/blinkmobile/json-as-files.js#readme","keywords":["content","data","files","json"],"license":"BSD-3-Clause","main":"index.js","publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/blinkmobile/json-as-files.js.git"},"scripts":{"ava":"nyc ava tests/*.js","eslint":"eslint --fix --cache .","fixpack":"fixpack","flow_check":"flow check || exit 0","nyc":"nyc check-coverage","postpublish":"greenkeeper-postpublish","posttest":"npm run eslint && npm run flow_check && npm run fixpack","test":"npm run ava && npm run nyc"},"gitHead":"801eb3b54ae7ffea1a255f07a5a397abf644afed","_id":"@blinkmobile/json-as-files@1.2.1","_shasum":"3649486a628b6df5dd1e0b54918e760b9f3520ca","_from":".","_npmVersion":"3.10.8","_nodeVersion":"6.6.0","_npmUser":{"name":"jokeyrhyme","email":"jokeyrhyme@gmail.com"},"dist":{"shasum":"3649486a628b6df5dd1e0b54918e760b9f3520ca","tarball":"https://registry.npmjs.org/@blinkmobile/json-as-files/-/json-as-files-1.2.1.tgz","integrity":"sha512-bsZe10OBgInypDCnlHx/CAj37aGFn+c19fW4mjQL0kH+2W2tdFNL5Qnn4JZamUzmWB3OGfu70ePs9jxYcCoXIg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDowCgGN8I/SPbEJK6lKmh+lFML36kB+O+5Yz2+Siaa2QIhAL9cTOvQrk6yMLuEtpCfv+4MLyTk6uCOXxTfS2TDIyXI"}]},"maintainers":[{"name":"blinkmobile","email":"ron@blinkmobile.com.au"},{"name":"jokeyrhyme","email":"jokeyrhyme@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/json-as-files-1.2.1.tgz_1474862366393_0.2715928016696125"},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."}},"readme":"# json-as-files [![Travis CI Status](https://travis-ci.org/blinkmobile/json-as-files.js.svg?branch=master)](https://travis-ci.org/blinkmobile/json-as-files.js) [![npm](https://img.shields.io/npm/v/@blinkmobile/json-as-files.svg?maxAge=2592000)](https://www.npmjs.com/package/@blinkmobile/json-as-files) [![AppVeyor Status](https://ci.appveyor.com/api/projects/status/github/blinkmobile/json-as-files.js?branch=master&svg=true)](https://ci.appveyor.com/project/blinkmobile/json-as-files.js)\n\nconvert between files and JSON strings, maintaining certain values as separate files\n\n\n## Why?\n\nWe have a use case where we wish to serialise JSON data to files,\nbut certain values within that JSON would be more convenient to keep separate.\nThis project keeps all values in the same JSON file by default,\nbut allows you to split certain values out into their own files.\n\nFor example, if you have Markdown content within a JSON structure,\nthis project allows you to maintain it as a separate \".md\" file.\nThat way, your editor can help you with Markdown-specific highlighting, etc.\n\n\n## How?\n\nJust replace a value in your JSON `Object` with a \"$file\" reference:\n`{ \"$file\": \"foo.txt\" }`.\nMake sure you keep a \"foo.txt\" file with the desired contents.\n\nDuring JSON file reads, we find these references,\nand replace them with the contents of the referenced file.\n\n\n## Usage\n\n\n### basic examples\n\n```js\nconst { readData, writeData } = require('@blinkmobile/json-as-files');\n\nreadData({ filePath: '/path/to/object.json' })\n.then((object) => { /* ... */ });\n\nwriteData({ filePath: '/path/to/object.json', data: { /* ... */ } })\n.then(() => { /* ... */ });\n```\n\n\n### read example with \"$file\"\n\nobject.json:\n```json\n{\n  \"title\": \"short and sweet\",\n  \"content\": { \"$file\": \"content.txt\"}\n}\n```\n\ncontent.txt:\n```txt\nToo long / inconvenient to include in the primary JSON file.\n```\n\nJavaScript:\n```js\nreadData({ filePath: '/path/to/object.json' })\n.then((data) => {\n  console.assert(data.title === 'short and sweet');\n  console.assert(data.content === 'Too long / inconvenient to include in the primary JSON file.');\n});\n```\n\n### write example with \"$file\"\n\nobject.json (already on disk):\n```json\n{\n  \"title\": \"short and sweet\",\n  \"content\": { \"$file\": \"content.txt\"}\n}\n```\n\ncontent.txt may or may not exist beforehand\n\nJavaScript:\n```js\nwriteData({\n  data: {\n    title: 'new title',\n    content: 'new content'\n  },\n  filePath: '/path/to/object.json'\n})\n.then(() => {\n  // avoid ...Sync() methods in production, please!\n  console.assert(fs.existsSync('/path/to/object.json'));\n  console.assert(fs.existsSync('/path/to/content.txt'));\n\n  return readData({ filePath: '/path/to/object.json' })\n})\n.then((data) => {\n  console.assert(data.title === 'new title');\n  console.assert(data.content === 'new content');\n});\n```\n\n\n### write example with \"$file\" template\n\nobject.json and content.txt may or may not exist beforehand\n\nJavaScript:\n```js\nwriteData({\n  data: {\n    title: 'new title',\n    content: 'new content'\n  },\n  filePath: '/path/to/object.json',\n  template: {\n    title: 'short and sweet',\n    content: { $file: 'content.txt' }\n  }\n})\n.then(() => {\n  // avoid ...Sync() methods in production, please!\n  console.assert(fs.existsSync('/path/to/object.json'));\n  console.assert(fs.existsSync('/path/to/content.txt'));\n\n  return readData({ filePath: '/path/to/object.json' })\n})\n.then((data) => {\n  console.assert(data.title === 'new title');\n  console.assert(data.content === 'new content');\n});\n```\n\n\n## API\n\n\n### findReferences()\n\n```\nfindReferences (data: Object) => Promise[FoundReference[]]\n```\n\nScan a data structure to locate references. Used internally.\n\n\n#### FoundReference\n\n```\ninterface FoundReference {\n  path: String[], // property path to the reference within the parent structure\n  target: String, // for \"$file\" references, this is a filename or path\n  type: String, // only \"$file\" has been implemented so far\n}\n```\n\n\n### isFileInReferences()\n\n```\nisFileReference (refs: FoundReference[], dataPath: String, filePath: String)\n  => Boolean\n```\n\nWe scanned a data structure for references (see `findReferences()`).\nIs this file included in those references?\n\n\n### isFileReference()\n\n```\nisFileReference (value: Any) => Boolean\n```\n\nDoes this value conform to our definition of a \"file reference\"?\n\n\n### readData()\n\n```\nreadData (options: ReadOptions, callback?: Function)\n  => Promise[Object|Array]\n```\n\nRead data from the provided `filePath` and other files relative to it.\n\n\n#### ReadOptions\n\n```\ninterface ReadOptions {\n  filePath: String\n}\n```\n\n\n### writeData()\n\n```\nwriteData (options: WriteOptions, callback?: Function)\n  => Promise\n```\n\nWrite data to the provided `filePath` and other files relative to it.\nInternal uses `planWriteData()` and `writePlan()`.\n\nReads pre-existing destination file (if any) to preserve past references (if any).\nIf \"template\" option is provided, then bypass this check.\n\n\n#### WriteOptions\n\n```\ninterface WriteOptions {\n  filePath: String,\n  data?: Any,\n  template?: Any\n}\n```\n\n\n### planWriteData()\n\n```\nplanWriteData (options: WriteOptions, callback?: Function)\n  => Promise[PlannedWrite[]]\n```\n\nLike `writeData()`, but do not perform actual writes.\nPrepare a list of planned write operations instead.\n\n\n#### PlannedWrite\n\n```\ninterface PlannedWrite {\n  targetPath: String,\n  value: Any\n}\n```\n\n\n### writePlan()\n\n```\nwritePlan (options: WritePlanOptions)\n  => Promise\n```\n\nExecute a list of planned write operations, writing to target files.\nIf `plannedWrite.value` is not already a String, then `JSON.stringify()` first.\n\n\n#### WritePlanOptions\n\n```\ninterface WritePlanOptions {\n  plan: PlannedWrite[]\n}\n```\n","maintainers":[{"email":"aaronroworth@gmail.com","name":"aaronroworth"},{"email":"ron@blinkmobile.com.au","name":"blinkmobile-admin"},{"email":"kizaonline@gmail.com","name":"kizaonline"},{"email":"matt.carroll139@gmail.com","name":"mymattcarroll"},{"email":"simondobie23@gmail.com","name":"simon_marklar"}],"time":{"modified":"2023-08-23T01:44:24.498Z","created":"2015-11-26T20:35:04.485Z","1.0.0":"2015-11-26T20:35:04.485Z","1.1.0":"2016-02-12T00:47:01.999Z","1.1.1":"2016-02-12T03:46:27.862Z","1.2.0":"2016-08-19T05:56:01.193Z","1.2.1":"2016-09-26T03:59:28.941Z"},"homepage":"https://github.com/blinkmobile/json-as-files.js#readme","keywords":["content","data","files","json"],"repository":{"type":"git","url":"git+https://github.com/blinkmobile/json-as-files.js.git"},"bugs":{"url":"https://github.com/blinkmobile/json-as-files.js/issues"},"license":"BSD-3-Clause","readmeFilename":"README.md"}