@jscad/json-deserializer 3.0.2-alpha.0 → 3.0.4-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/jscad-json-deserializer.es.js +3 -13
- package/dist/jscad-json-deserializer.min.js +3 -13
- package/package.json +11 -12
- package/rollup.config.js +8 -4
- package/src/index.js +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.0.4-alpha.0](/compare/@jscad/json-deserializer@3.0.3-alpha.0...@jscad/json-deserializer@3.0.4-alpha.0) (2026-04-12)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @jscad/json-deserializer
|
|
9
|
+
|
|
10
|
+
## [3.0.3-alpha.0](https://github.com/jscad/OpenJSCAD/compare/@jscad/json-deserializer@3.0.2-alpha.0...@jscad/json-deserializer@3.0.3-alpha.0) (2026-01-18)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @jscad/json-deserializer
|
|
13
|
+
|
|
6
14
|
## [3.0.2-alpha.0](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/json-deserializer@3.0.1-alpha.0...@jscad/json-deserializer@3.0.2-alpha.0) (2025-09-06)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @jscad/json-deserializer
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* @version 3.0.2-alpha.0
|
|
5
|
-
* @license MIT
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* JSCAD Utility functions for arrays
|
|
9
|
-
* @module @jscad/array-utils
|
|
10
|
-
* @version 3.0.1-alpha.0
|
|
11
|
-
* @license MIT
|
|
12
|
-
*/
|
|
13
|
-
const flatten=arr=>arr.reduce(((acc,val)=>Array.isArray(val)?acc.concat(flatten(val)):acc.concat(val)),[]),deserialize=(options,input)=>{const defaults={filename:"json",output:"script",version:"3.0.2-alpha.0",addMetaData:!0};options=Object.assign({},defaults,options),input=((stringOrArrayBuffer,defaultBinaryEncoding="utf-8")=>"string"==typeof stringOrArrayBuffer?stringOrArrayBuffer:new TextDecoder(defaultBinaryEncoding).decode(new Uint8Array(stringOrArrayBuffer)))(input);let objects=JSON.parse(input);var array;return objects=flatten((array=objects,Array.isArray(array)?array:null==array?[]:[array])),"script"===options.output?translate(options,objects):objects},translate=(options,objects)=>{const{addMetaData:addMetaData,filename:filename,version:version}=options;let script=addMetaData?`//\n// Produced by JSCAD IO Library : JSON Deserializer (${version})\n// date: ${new Date}\n// source: ${filename}\n//\n`:"";return script+=`\nconst { geometries } = require('@jscad/modeling')\n\nconst main = () => {\n const objects = [${translateToList(objects)} ]\n return objects\n}\n\n${translateToObjects(objects)}\n\nmodule.exports = { main }\n`,script},translateToList=objects=>objects.reduce(((script,object,index)=>script+` json${index},`),""),translateToObjects=objects=>objects.reduce(((script,object,index)=>script+translateToObject(object,index)),""),translateToObject=(object,index)=>`const json${index} = ${JSON.stringify(object)}\n`,mimeType="application/json";export{deserialize,mimeType};
|
|
1
|
+
/*! @jscad/json-deserializer V3.0.4-alpha.0 (MIT) */
|
|
2
|
+
/*! @jscad/array-utils V3.0.2-alpha.0 (MIT) */
|
|
3
|
+
const deserialize=(options,input)=>{const defaults={filename:"json",output:"script",version:"3.0.4-alpha.0",addMetaData:!0};options=Object.assign({},defaults,options),input=((stringOrArrayBuffer,defaultBinaryEncoding="utf-8")=>"string"==typeof stringOrArrayBuffer?stringOrArrayBuffer:new TextDecoder(defaultBinaryEncoding).decode(new Uint8Array(stringOrArrayBuffer)))(input);let objects=JSON.parse(input);var array;return array=objects,objects=(Array.isArray(array)?array:null==array?[]:[array]).flat(1/0),"script"===options.output?translate(options,objects):objects},translate=(options,objects)=>{const{addMetaData:addMetaData,filename:filename,version:version}=options;let script=addMetaData?`//\n// Produced by JSCAD IO Library : JSON Deserializer (${version})\n// date: ${new Date}\n// source: ${filename}\n//\n`:"";return script+=`\nconst { geometries } = require('@jscad/modeling')\n\nconst main = () => {\n const objects = [${translateToList(objects)} ]\n return objects\n}\n\n${translateToObjects(objects)}\n\nmodule.exports = { main }\n`,script},translateToList=objects=>objects.reduce((script,object,index)=>script+` json${index},`,""),translateToObjects=objects=>objects.reduce((script,object,index)=>script+translateToObject(object,index),""),translateToObject=(object,index)=>`const json${index} = ${JSON.stringify(object)}\n`,mimeType="application/json";export{deserialize,mimeType};
|
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* JSON Deserializer for JSCAD
|
|
3
|
-
* @module @jscad/json-deserializer
|
|
4
|
-
* @version 3.0.2-alpha.0
|
|
5
|
-
* @license MIT
|
|
6
|
-
*/
|
|
1
|
+
/*! @jscad/json-deserializer V3.0.4-alpha.0 (MIT) */
|
|
7
2
|
var global,factory;global=this,factory=function(exports){
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* @module @jscad/array-utils
|
|
11
|
-
* @version 3.0.1-alpha.0
|
|
12
|
-
* @license MIT
|
|
13
|
-
*/
|
|
14
|
-
const flatten=arr=>arr.reduce(((acc,val)=>Array.isArray(val)?acc.concat(flatten(val)):acc.concat(val)),[]),translate=(options,objects)=>{const{addMetaData:addMetaData,filename:filename,version:version}=options;let script=addMetaData?`//\n// Produced by JSCAD IO Library : JSON Deserializer (${version})\n// date: ${new Date}\n// source: ${filename}\n//\n`:"";return script+=`\nconst { geometries } = require('@jscad/modeling')\n\nconst main = () => {\n const objects = [${translateToList(objects)} ]\n return objects\n}\n\n${translateToObjects(objects)}\n\nmodule.exports = { main }\n`,script},translateToList=objects=>objects.reduce(((script,object,index)=>script+` json${index},`),""),translateToObjects=objects=>objects.reduce(((script,object,index)=>script+translateToObject(object,index)),""),translateToObject=(object,index)=>`const json${index} = ${JSON.stringify(object)}\n`;exports.deserialize=(options,input)=>{const defaults={filename:"json",output:"script",version:"3.0.2-alpha.0",addMetaData:!0};options=Object.assign({},defaults,options),input=((stringOrArrayBuffer,defaultBinaryEncoding="utf-8")=>"string"==typeof stringOrArrayBuffer?stringOrArrayBuffer:new TextDecoder(defaultBinaryEncoding).decode(new Uint8Array(stringOrArrayBuffer)))(input);let objects=JSON.parse(input);var array;return objects=flatten((array=objects,Array.isArray(array)?array:null==array?[]:[array])),"script"===options.output?translate(options,objects):objects},exports.mimeType="application/json",Object.defineProperty(exports,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?factory(exports):"function"==typeof define&&define.amd?define(["exports"],factory):factory((global="undefined"!=typeof globalThis?globalThis:global||self).jscadJsonDeserializer={});
|
|
3
|
+
/*! @jscad/array-utils V3.0.2-alpha.0 (MIT) */
|
|
4
|
+
const translate=(options,objects)=>{const{addMetaData:addMetaData,filename:filename,version:version}=options;let script=addMetaData?`//\n// Produced by JSCAD IO Library : JSON Deserializer (${version})\n// date: ${new Date}\n// source: ${filename}\n//\n`:"";return script+=`\nconst { geometries } = require('@jscad/modeling')\n\nconst main = () => {\n const objects = [${translateToList(objects)} ]\n return objects\n}\n\n${translateToObjects(objects)}\n\nmodule.exports = { main }\n`,script},translateToList=objects=>objects.reduce((script,object,index)=>script+` json${index},`,""),translateToObjects=objects=>objects.reduce((script,object,index)=>script+translateToObject(object,index),""),translateToObject=(object,index)=>`const json${index} = ${JSON.stringify(object)}\n`;exports.deserialize=(options,input)=>{const defaults={filename:"json",output:"script",version:"3.0.4-alpha.0",addMetaData:!0};options=Object.assign({},defaults,options),input=((stringOrArrayBuffer,defaultBinaryEncoding="utf-8")=>"string"==typeof stringOrArrayBuffer?stringOrArrayBuffer:new TextDecoder(defaultBinaryEncoding).decode(new Uint8Array(stringOrArrayBuffer)))(input);let objects=JSON.parse(input);var array;return array=objects,objects=(Array.isArray(array)?array:null==array?[]:[array]).flat(1/0),"script"===options.output?translate(options,objects):objects},exports.mimeType="application/json"},"object"==typeof exports&&"undefined"!=typeof module?factory(exports):"function"==typeof define&&define.amd?define(["exports"],factory):factory((global="undefined"!=typeof globalThis?globalThis:global||self).jscadJsonDeserializer={});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jscad/json-deserializer",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4-alpha.0",
|
|
4
4
|
"description": "JSON Deserializer for JSCAD",
|
|
5
5
|
"homepage": "https://openjscad.xyz/",
|
|
6
6
|
"repository": "https://github.com/jscad/OpenJSCAD.org",
|
|
@@ -33,18 +33,17 @@
|
|
|
33
33
|
],
|
|
34
34
|
"license": "MIT",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@jscad/array-utils": "3.0.
|
|
37
|
-
"@jscad/io-utils": "3.0.
|
|
36
|
+
"@jscad/array-utils": "3.0.2-alpha.0",
|
|
37
|
+
"@jscad/io-utils": "3.0.4-alpha.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@jscad/modeling": "3.0.
|
|
41
|
-
"@rollup/plugin-node-resolve": "^15.0.
|
|
42
|
-
"@rollup/plugin-terser": "^0.4.
|
|
43
|
-
"ava": "^
|
|
44
|
-
"c8": "^
|
|
45
|
-
"rollup": "^
|
|
46
|
-
"rollup-plugin-
|
|
47
|
-
"rollup-plugin-version-injector": "^1.3.3"
|
|
40
|
+
"@jscad/modeling": "3.0.4-alpha.0",
|
|
41
|
+
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
42
|
+
"@rollup/plugin-terser": "^0.4.0",
|
|
43
|
+
"ava": "^6.3.0",
|
|
44
|
+
"c8": "^10.1.0",
|
|
45
|
+
"rollup": "^4.52.0",
|
|
46
|
+
"rollup-plugin-version-injector": "^1.3.0"
|
|
48
47
|
},
|
|
49
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "1de52a2b7b6bd31134fd0b72a2842f31ecf8f237"
|
|
50
49
|
}
|
package/rollup.config.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as fs from 'fs'
|
|
2
|
+
|
|
2
3
|
import versionInjector from 'rollup-plugin-version-injector'
|
|
3
4
|
import { nodeResolve } from '@rollup/plugin-node-resolve'
|
|
4
5
|
import terser from '@rollup/plugin-terser'
|
|
5
6
|
|
|
7
|
+
const {name, version, license} = JSON.parse(fs.readFileSync('package.json'))
|
|
8
|
+
|
|
6
9
|
export default {
|
|
7
10
|
input: 'src/index.js',
|
|
8
11
|
|
|
@@ -10,17 +13,18 @@ export default {
|
|
|
10
13
|
{
|
|
11
14
|
file: 'dist/jscad-json-deserializer.min.js',
|
|
12
15
|
format: 'umd',
|
|
13
|
-
name: 'jscadJsonDeserializer'
|
|
16
|
+
name: 'jscadJsonDeserializer',
|
|
17
|
+
banner: `/*! ${name} V${version} (${license}) */`
|
|
14
18
|
},
|
|
15
19
|
{
|
|
16
20
|
file: 'dist/jscad-json-deserializer.es.js',
|
|
17
|
-
format: 'es'
|
|
21
|
+
format: 'es',
|
|
22
|
+
banner: `/*! ${name} V${version} (${license}) */`
|
|
18
23
|
}
|
|
19
24
|
],
|
|
20
25
|
|
|
21
26
|
plugins: [
|
|
22
27
|
nodeResolve(),
|
|
23
|
-
banner('<%= pkg.description %>\n@module <%= pkg.name %>\n@version <%= pkg.version %>\n@license <%= pkg.license %>'),
|
|
24
28
|
versionInjector({ injectInComments: { fileRegexp: /\.(html)$/ }, logLevel: 'warn' }),
|
|
25
29
|
terser({ compress: { module: true }, mangle: false, format: { comments: 'some' } })
|
|
26
30
|
]
|
package/src/index.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @see https://www.json.org
|
|
11
11
|
* @module io/json-deserializer
|
|
12
12
|
* @example
|
|
13
|
-
*
|
|
13
|
+
* import { deserializer, mimeType } from '@jscad/json-deserializer'
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
import { flatten, toArray } from '@jscad/array-utils'
|
|
@@ -20,14 +20,14 @@ const version = '[VI]{version}[/VI]' // version is injected by rollup
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Deserialize the given JSON notation (string) into either a script or an array of geometry.
|
|
23
|
+
*
|
|
23
24
|
* @param {Object} options - options used during deserializing, REQUIRED
|
|
24
25
|
* @param {String} [options.filename='json'] - filename of original JSON source
|
|
25
26
|
* @param {String} [options.output='script'] - either 'script' or 'geometry' to set desired output
|
|
26
27
|
* @param {String} [options.version='0.0.0'] - version number to add to the metadata
|
|
27
28
|
* @param {Boolean} [options.addMetadata=true] - toggle injection of metadata at the start of the script
|
|
28
29
|
* @param {String} input - JSON source data
|
|
29
|
-
* @return {
|
|
30
|
-
* @alias module:io/json-deserializer.deserialize
|
|
30
|
+
* @return {(Array|String)} either an array of objects (geometry) or a string (script)
|
|
31
31
|
*/
|
|
32
32
|
const deserialize = (options, input) => {
|
|
33
33
|
const defaults = {
|
|
@@ -39,7 +39,7 @@ const deserialize = (options, input) => {
|
|
|
39
39
|
options = Object.assign({}, defaults, options)
|
|
40
40
|
|
|
41
41
|
// convert the JSON notation into anonymous object(s)
|
|
42
|
-
input = ensureString(input)
|
|
42
|
+
input = ensureString(input)
|
|
43
43
|
let objects = JSON.parse(input)
|
|
44
44
|
|
|
45
45
|
// cleanup the objects
|