{"name":"typeson-registry","version":"0.4.1","keywords":["typeson","JSON","remoting","universal"],"license":"MIT","_id":"typeson-registry@0.4.1","maintainers":[{"name":"dfahlander","email":"david.fahlander@gmail.com"}],"homepage":"https://github.com/dfahlander/typeson-registry#readme","bugs":{"url":"https://github.com/dfahlander/typeson-registry/issues"},"dist":{"shasum":"ae1198ef0c83f29f74561af51699c22d873ab024","tarball":"http://registry-npm.ywwl.com/typeson-registry/download/typeson-registry-0.4.1.tgz","integrity":"sha512-V0hreEjvz4htwMpYVaD/U0SNT0l8AdSpXmmK5Ubg4XfQhsWv/W9G7lhHb3RRCQvG/a4zPLv7JiukOkoAu0czbw==","signatures":[{"sig":"MEUCIC6YYOm1O085HSad1J13rMBn+GDPt7Nh0TyBLWOlYJn0AiEA032RX2uadtZ8XGmcc2RfnDLuiEZ0no0JJ0fSCZs2W8k=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"size":4458,"noattachment":false,"key":"/typeson-registry/-/typeson-registry-0.4.1.tgz"},"_from":".","_shasum":"ae1198ef0c83f29f74561af51699c22d873ab024","gitHead":"3fa5a7404b8d270d2e82de64912c7fe00ad99bcd","scripts":{"test":"mocha"},"_npmUser":{"name":"dfahlander","email":"david.fahlander@gmail.com"},"repository":{"url":"git+https://github.com/dfahlander/typeson-registry.git","type":"git"},"_npmVersion":"3.3.6","description":"Official registry for typeson type definitions","directories":{},"_nodeVersion":"6.2.0","dependencies":{"typeson":"^2.0.0","base64-arraybuffer":"^0.1.5"},"devDependencies":{"chai":"^3.5.0"},"_npmOperationalInternal":{"tmp":"tmp/typeson-registry-0.4.1.tgz_1464050361170_0.6548884680960327","host":"packages-12-west.internal.npmjs.com"},"readme":"# typeson-registry\n\nThe type registry for [typeson](https://github.com/dfahlander/typeson).\n\n- Types listed under\n    [types](https://github.com/dfahlander/typeson-registry/tree/master/types)\n- Presets listed under\n    [presets](https://github.com/dfahlander/typeson-registry/tree/master/presets)\n\nSee below for notes on these types and presets.\n\nNote that some types will require polyfills in Node such as via\n[`jsdom`](https://github.com/jsdom/jsdom).\nSee the testing environment of `test/test.js` for some examples.\n\n## Installation\n\nNote that for Node.js, to use the `file` or `blob` types (or the `filelist`\ntype or `structuredCloning` and `structuredCloningThrowing` presets which\ninclude them), you will need a polyfill for `Blob` or `File`, respectively,\nas well as `FileReader` and `URL.createObjectURL` (and a\npolyfill for `URL` if you are using Node < 10.0.0 or an older browser).\nNote that our `URL.createObjectURL` polyfill expects a global\n`XMLHttpRequest` and `location.href` predefined before it as well (and one\nwhich can handle `data:` URLs). For Node, you can add it like this:\n\n```js\nimport {createObjectURL} from 'typeson-registry/polyfills';\n\nURL.createObjectURL = createObjectURL;\n```\n\nWe have not added `jsdom` as a dependency, but it is required if this\npolyfill is used.\n\nAlso exported: `QuotaExceededError`, `WebTransportError`, `AudioData`, `EncodedAudioChunk`,\n    `EncodedVideoChunk`, `VideoFrame`, `DOMRect`,\n    `DOMRectReadOnly`, `DOMPoint`, `DOMPointReadOnly`, `DOMQuad`, `DOMMatrix`, `DOMMatrixReadOnly`,\n    `createImageBitmap`, `createObjectURL`, `revokeObjectURL`, `xmlHttpRequestOverrideMimeType`\n\nBesides the polyfills for `file` or `blob`, the `structuredCloningThrowing`\npreset also needs a global `DOMException` polyfill.\n\nThe `filelist` type, in addition to the polyfills for `file`, will need\na `FileList` polyfill (including a `FileList` string tag) like the one provided.\n\nThe `imagebitmap` type requires a global `createImageBitmap` polyfill (and\nan `ImageBitmap` polyfill (including an `ImageBitmap` string tag).\n\nThe `imagedata` type requires a global `ImageData` polyfill (including an\n`ImageData` string tag).\n\nYou may wish to see our `test-environment.js` file for how some\npolyfilling may be done (largely using `jsdom`).\n\n### Building files from Git clone (as opposed to npm installs)\n\nIf you have cloned the repo (and not the npm package), you must run\n`npm install` to get the `devDependencies` and then run\n`npm run rollup` to get the individual browser scripts built locally\n(into `dist`) or to get `index.js` to be rebuilt based on existing\npresets and types).\n\n## Usage (Pre-rollup in Node or browser)\n\n```js\nimport {Typeson, date, error, regexp, typedArrays} from 'typeson-registry';\n\nconst TSON = new Typeson().register([\n    date,\n    error,\n    regexp,\n    typedArrays\n    // ...\n]);\n\nconst tson = TSON.stringify({\n    Hello: 'world',\n    date: new Date(),\n    error: new Error('test'),\n    inner: {\n        x: /foo/gui,\n        bin: new Uint8Array(64)\n    }\n}, null, 2);\n\nconsole.log(tson);\n/* Output:\n\n{\n  \"Hello\": \"world\",\n  \"date\": 1464049031538,\n  \"error\": {\n    \"name\": \"Error\",\n    \"message\": \"test\"\n  },\n  \"inner\": {\n    \"x\": {\n      \"source\": \"foo\",\n      \"flags\": \"gi\"\n    },\n    \"bin\": \"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==\"\n  },\n  \"$types\": {\n    \"date\": \"Date\",\n    \"error\": \"Error\",\n    \"inner.x\": \"RegExp\",\n    \"inner.bin\": \"Uint8Array\"\n  }\n}\n*/\n\nconst parsedBack = TSON.parse(tson);\n\nconsole.log(parsedBack.date instanceof Date);\nconsole.log(parsedBack.inner.bin instanceof Uint8Array);\n```\n\n## Usage (Node without own Rollup)\n\n```js\nconst {Typeson, builtin} = require('typeson-registry');\n\nconst tson = new Typeson().register([\n    builtin\n]);\n```\n\n## Usage (`import` in supporting browsers without own Rollup)\n\n```html\n<script type=\"module\">\n\nimport {Typeson, builtin} from './node_modules/typeson-registry/dist/index.js';\n\nconst TSON = new Typeson().register([\n    builtin\n]);\n</script>\n```\n\n## Usage (with plain script tags without own Rollup)\n\nAll presets under `dist/` are UMD modules so you could also\nrequire them as AMD modules with requirejs if you prefer.\n\n```html\n<!DOCTYPE html>\n<html>\n  <head>\n    <script src=\"https://unpkg.com/typeson/dist/typeson.umd.min.js\"></script>\n    <script src=\"https://unpkg.com/typeson-registry/dist/presets/builtin.umd.cjs\"></script>\n    <script>\n\n    const TSON = new Typeson().register(builtin);\n    const tson = TSON.stringify({\n        Hello: 'world',\n        date: new Date(),\n        error: new Error('err'),\n        inner: {\n            x: /foo/giu,\n            bin: new Uint8Array(64)\n        }\n    }, null, 2);\n\n    alert(tson);\n    /* Alerts:\n\n    {\n      \"Hello\": \"world\",\n      \"date\": 1464049031538,\n      \"error\": {\n        \"name\": \"Error\",\n        \"message\": \"err\"\n      },\n      \"inner\": {\n        \"x\": {\n          \"source\": \"foo\",\n          \"flags\": \"gi\"\n        },\n        \"bin\": \"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==\"\n      },\n      \"$types\": {\n        \"date\": \"Date\",\n        \"error\": \"Error\",\n        \"inner.x\": \"RegExp\",\n        \"inner.bin\": \"Uint8Array\"\n      }\n    }\n    */\n\n    </script>\n  </head>\n</html>\n```\n\n## Notes on types and presets\n\nNote that the type name corresponds to the file name in the following manner:\n\n1. Genuine separate words are camel-cased in the type name but hyphenated in\n    the file name (e.g., `negativeInfinity` and `negativity-infinity.js`);\n    names whose original API is camel-cased are not hyphenated, however\n    (e.g., `arraybuffer` and `arraybuffer.js` given `ArrayBuffer`).\n1. All other portions of names are lower-cased (e.g., `date` and `date.js`).\n1. Type names that would clash with existing objects when exported (even after\n    lower-casing) must have a separate, preferably abbreviated form (e.g.,\n    the type and preset `undef` and `undef.js` was necessary for `undefined`)\n1. Type names which are not allowed as ES6 exports (e.g., periods in `Intl`\n    types are now removed: `Intl.Collator` -> `IntlCollator`)\n1. Type names should indicate the singular (e.g., `userObject`) except for\n    files containing multiple related exports (e.g., `errors`, `typed-arrays`,\n    and `typed-arrays-socketio.js`); files with multiple exports whose extra\n    exports are incidental (e.g., `filelist`) do not need a plural.\n\n### Types\n\n- `audiodata`\n- `arraybuffer`\n- `bigintObject`\n- `bigint`\n- `blob` - Has sync and async encapsulation/replacements (though sync only\n    via deprecated means)\n- `cloneable` - Looks for `Symbol.for('cloneEncapsulate')` and\n    `Symbol.for('cloneRevive')` methods to allow\n    for a means of extending our built-in structured cloning presets (though if\n    you are polyfilling a standard object, we welcome you to submit back as a\n    PR!). The clones cannot be revived past the current window session,\n    however.\n- `cryptokey`\n- `dataview`\n- `date`\n- `domexception`\n- `dommatrix`\n- `dommatrixreadonly`\n- `dompoint`\n- `dompointreadonly`\n- `domquad`\n- `domrect`\n- `domrectreadonly`\n- `encodedaudiochunk`\n- `encodedvideochunk`\n- `error.js` (`Error`) and `errors.js` (`TypeError`, `RangeError`, `SyntaxError`, `ReferenceError`, `EvalError`, `URIError`, `InternalError`) - These\n    provide a means of resurrecting error object across cloning boundaries\n    (since they are not otherwise treated as cloneable by the Structured\n    Cloning Algorithm).\n- `file` - Has sync and async encapsulation/replacements (though sync only\n    via deprecated means)\n- `filelist` - HTML does not provide a means of creating a `FileList` object\n    dynamically, so we polyfill one for revival. This method also sets `File`\n- `imagebitmap` - Has sync and async revivers. If `OffscreenCanvas` is not\n    supported, the sync method does not produce a genuine `ImageBitmap`\n    but instead produces a canvas element which can frequently be used in\n    a similar context to `ImageBitmap`.\n- `imagedata`\n- `infinity` - Preserves positive infinity\n- `intl-types.js` (`Intl.Collator`, `Intl.DateTimeFormat`, `Intl.NumberFormat`) -\n    Not all properties can be preserved\n- `map`\n- `nan` - Preserves `NaN` (not a number)\n- `negativeInfinity` - Preserves negative infinity\n- `negativeZero` - Preserves `-0` (produces + or - Infinity when used as divisor)\n- `nonBuiltInIgnore` - For roughly detecting non-builtin objects and to avoid\n    adding them as properties\n- `primitive-objects.js` (`StringObject`, `BooleanObject`, `NumberObject`)\n- `promise`\n- `quotaexceedederror`\n- `regexp`\n- `resurrectable` - Resurrects any non-array object, function, or symbol; can\n    only be revived for the current window session.\n- `set`\n- `symbol`\n- `typed-arrays-socketio.js` (`Int8Array`, `Uint8Array`, `Uint8ClampedArray`,\n    `Int16Array`, `Uint16Array`, `Int32Array`, `Uint32Array`, `Float32Array`,\n    `Float64Array`) - See\n    [typeson#environmentformat-support](https://github.com/dfahlander/typeson#environmentformat-support)\n    and `presets/socketio.js`\n- `typed-arrays.js` (`Int8Array`, `Uint8Array`, `Uint8ClampedArray`,\n    `Int16Array`, `Uint16Array`, `Int32Array`, `Uint32Array`,\n    `Float32Array`, `Float64Array`) - Base64-encodes\n- `undef` (for `undefined`) (See also `presets/undefined.js` and\n    `presets/sparse-undefined.js`)\n- `userObjects` - Allows for inherited objects but ensures the prototype chain\n    inherits from `Object` (or `null`). Should be low priority if one is\n    matching other objects as it will readily match many objects.\n- `videoframe` - Reconstructs a `VideoFrame` from its raw pixel data (via\n    `allocationSize`/`copyTo`); has an async encapsulation only, as\n    `VideoFrame#copyTo` is itself asynchronous.\n- `webtransporterror`\n\n### Presets\n\n- `array-nonindex-keys.js`\n- `builtin.js` - Types that are built into the JavaScript language itself.\n    Types that were added in ES6 or beyond will be checked before inclusion\n    so that this module can be consumed by both ES5 and ES6 environments.\n    Some imperfectly serializable objects (such as functions and Symbols)\n    are not included in this preset.\n- `postmessage.js` - This preset is intended as a utility to expand on what is\n    cloneable via `strcutured-cloning.js` and supports Error objects.\n- `socketio.js`\n- `sparse-undefined.js` (`sparseArrays` and `sparseUndefined`) - Supports\n    reconstructing sparse arrays (with missing properties not even assigned\n    an explicit `undefined`). See `types/undefined.js` for the explicit case\n    or `presets/undefined.js` for a utility combining both.\n- `special-numbers.js` (preserves `NaN`, `Infinity`, `-Infinity`)\n- `structured-cloning.js` - For the Structured Cloning Algorithm used by the\n    likes of `postMessage` and `indexedDB`. See also the `cloneable` type.\n- `structured-cloning-throwing.js` - Same as `structured-cloning.js` but\n    throws with non-recognized types. See also the `cloneable` type.\n- `undef.js` - Supports reconstructing explicit and implicit (sparse)\n    uses of `undefined`.\n- `universal.js`- Meant for de-facto universal types. Currently includes\n    built-ins only.\n\n### Functions (support not included)\n\nIf you are looking for a way to resurrect functions, you can use the following,\nbut please bear in mind that it uses `eval` which is prohibited by some\nContent Security Policies (CSP) (so we are not packaging it with our builds),\nthat it is unsafe, and also that the function might not behave\ndeterministically when revived (e.g., if the function were provided from\nanother context).\n\n```js\nconst functionType = {functionType: [\n    function (x) { return typeof x === 'function'; },\n    function (funcType) { return '(' + funcType.toString() + ')'; },\n    // eslint-disable-next-line no-eval -- Demonstrating\n    function (o) { return eval(o); }\n]};\n\nconst typeson = new Typeson().register(functionType);\nconst tson = typeson.stringify(function () { return 'abc'; });\nconst back = typeson.parse(tson);\nback(); // 'abc'\n```\n\n## Development\n\n[node-canvas](https://github.com/Automattic/node-canvas) is used to test\n`ImageData`.\n\nBe sure to follow the installation steps.\n\nOn Windows, besides following the\n[Windows installation steps](https://github.com/Automattic/node-canvas/wiki/Installation---Windows),\n[this](https://github.com/nodejs/node-gyp/issues/94#issuecomment-278587021)\nhelped complete the installation. If you need to have it rebuilt, you can\nrun `npm i` inside of the `node_modules/canvas` directory.\n\nThe older repo-specific Windows DLL copy workaround is no longer needed with\nmodern `canvas` versions. Follow the official node-canvas Windows installation\ninstructions for your toolchain, and then run the project normally.\n\n## See also\n\n- [typeson](https://github.com/dfahlander/typeson)\n","publish_time":1464050363476,"_cnpm_publish_time":1464050363476,"dist-tags":{"latest":"15.3.0"}}