teptris 0.3.7 → 0.3.10
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/README.md +4 -0
- package/dist/teptris.mjs +1 -1
- package/dist/teptris.wasm +0 -0
- package/package.json +1 -1
- package/src/index.js +157 -9
- package/src/teptris_wasm.c +28 -0
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# teptris (JavaScript/TypeScript)
|
|
2
2
|
|
|
3
|
+
**Mission: be the best TOML parser and builder ever made — in C, Ruby,
|
|
4
|
+
Rust, and JS — measured, not claimed.** The bar and the family ledger:
|
|
5
|
+
[BEST-EVER.md](https://github.com/leptris/teptris/blob/main/BEST-EVER.md).
|
|
6
|
+
|
|
3
7
|
TOML for JavaScript at libteptris speed — the engine compiled to
|
|
4
8
|
WebAssembly (emscripten, ES module), no fallback.
|
|
5
9
|
|
package/dist/teptris.mjs
CHANGED
|
@@ -6,7 +6,7 @@ var Module = (() => {
|
|
|
6
6
|
async function(moduleArg = {}) {
|
|
7
7
|
var moduleRtn;
|
|
8
8
|
|
|
9
|
-
var Module=moduleArg;var readyPromiseResolve,readyPromiseReject;var readyPromise=new Promise((resolve,reject)=>{readyPromiseResolve=resolve;readyPromiseReject=reject});var ENVIRONMENT_IS_WEB=typeof window=="object";var ENVIRONMENT_IS_WORKER=typeof WorkerGlobalScope!="undefined";var ENVIRONMENT_IS_NODE=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string"&&process.type!="renderer";if(ENVIRONMENT_IS_NODE){const{createRequire}=await import("module");let dirname=import.meta.url;if(dirname.startsWith("data:")){dirname="/"}var require=createRequire(dirname)}var moduleOverrides=Object.assign({},Module);var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("fs");var nodePath=require("path");if(!import.meta.url.startsWith("data:")){scriptDirectory=nodePath.dirname(require("url").fileURLToPath(import.meta.url))+"/"}readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?undefined:"utf8");return ret};if(!Module["thisProgram"]&&process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}arguments_=process.argv.slice(2);quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(ENVIRONMENT_IS_WORKER){scriptDirectory=self.location.href}else if(typeof document!="undefined"&&document.currentScript){scriptDirectory=document.currentScript.src}if(_scriptName){scriptDirectory=_scriptName}if(scriptDirectory.startsWith("blob:")){scriptDirectory=""}else{scriptDirectory=scriptDirectory.substr(0,scriptDirectory.replace(/[?#].*/,"").lastIndexOf("/")+1)}{readAsync=async url=>{var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)}}}else{}var out=Module["print"]||console.log.bind(console);var err=Module["printErr"]||console.error.bind(console);Object.assign(Module,moduleOverrides);moduleOverrides=null;if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];var wasmBinary=Module["wasmBinary"];var wasmMemory;var ABORT=false;var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAP64,HEAPU64,HEAPF64;function updateMemoryViews(){var b=wasmMemory.buffer;Module["HEAP8"]=HEAP8=new Int8Array(b);Module["HEAP16"]=HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);Module["HEAPU16"]=HEAPU16=new Uint16Array(b);Module["HEAP32"]=HEAP32=new Int32Array(b);Module["HEAPU32"]=HEAPU32=new Uint32Array(b);Module["HEAPF32"]=HEAPF32=new Float32Array(b);Module["HEAPF64"]=HEAPF64=new Float64Array(b);Module["HEAP64"]=HEAP64=new BigInt64Array(b);Module["HEAPU64"]=HEAPU64=new BigUint64Array(b)}var __ATPRERUN__=[];var __ATINIT__=[];var __ATPOSTRUN__=[];var runtimeInitialized=false;function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(__ATPRERUN__)}function initRuntime(){runtimeInitialized=true;callRuntimeCallbacks(__ATINIT__)}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(__ATPOSTRUN__)}function addOnPreRun(cb){__ATPRERUN__.unshift(cb)}function addOnInit(cb){__ATINIT__.unshift(cb)}function addOnPostRun(cb){__ATPOSTRUN__.unshift(cb)}var runDependencies=0;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;Module["monitorRunDependencies"]?.(runDependencies)}function removeRunDependency(id){runDependencies--;Module["monitorRunDependencies"]?.(runDependencies);if(runDependencies==0){if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}function abort(what){Module["onAbort"]?.(what);what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);readyPromiseReject(e);throw e}var dataURIPrefix="data:application/octet-stream;base64,";var isDataURI=filename=>filename.startsWith(dataURIPrefix);var isFileURI=filename=>filename.startsWith("file://");function findWasmBinary(){if(Module["locateFile"]){var f="teptris.wasm";if(!isDataURI(f)){return locateFile(f)}return f}return new URL("teptris.wasm",import.meta.url).href}var wasmBinaryFile;function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary&&typeof WebAssembly.instantiateStreaming=="function"&&!isDataURI(binaryFile)&&!ENVIRONMENT_IS_NODE&&typeof fetch=="function"){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){return{a:wasmImports}}async function createWasm(){function receiveInstance(instance,module){wasmExports=instance.exports;wasmMemory=wasmExports["c"];updateMemoryViews();addOnInit(wasmExports["d"]);removeRunDependency("wasm-instantiate");return wasmExports}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){receiveInstance(result["instance"])}var info=getWasmImports();if(Module["instantiateWasm"]){try{return Module["instantiateWasm"](info,receiveInstance)}catch(e){err(`Module.instantiateWasm callback failed with error: ${e}`);readyPromiseReject(e)}}wasmBinaryFile??=findWasmBinary();try{var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);receiveInstantiationResult(result);return result}catch(e){readyPromiseReject(e);return}}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var noExitRuntime=Module["noExitRuntime"]||true;var UTF8Decoder=typeof TextDecoder!="undefined"?new TextDecoder:undefined;var UTF8ArrayToString=(heapOrArray,idx=0,maxBytesToRead=NaN)=>{var endIdx=idx+maxBytesToRead;var endPtr=idx;while(heapOrArray[endPtr]&&!(endPtr>=endIdx))++endPtr;if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str="";while(idx<endPtr){var u0=heapOrArray[idx++];if(!(u0&128)){str+=String.fromCharCode(u0);continue}var u1=heapOrArray[idx++]&63;if((u0&224)==192){str+=String.fromCharCode((u0&31)<<6|u1);continue}var u2=heapOrArray[idx++]&63;if((u0&240)==224){u0=(u0&15)<<12|u1<<6|u2}else{u0=(u0&7)<<18|u1<<12|u2<<6|heapOrArray[idx++]&63}if(u0<65536){str+=String.fromCharCode(u0)}else{var ch=u0-65536;str+=String.fromCharCode(55296|ch>>10,56320|ch&1023)}}return str};var UTF8ToString=(ptr,maxBytesToRead)=>ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead):"";var ___assert_fail=(condition,filename,line,func)=>abort(`Assertion failed: ${UTF8ToString(condition)}, at: `+[filename?UTF8ToString(filename):"unknown filename",line,func?UTF8ToString(func):"unknown function"]);var getHeapMax=()=>2147483648;var alignMemory=(size,alignment)=>Math.ceil(size/alignment)*alignment;var growMemory=size=>{var b=wasmMemory.buffer;var pages=(size-b.byteLength+65535)/65536|0;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignMemory(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement){return true}}return false};var stringToUTF8Array=(str,heap,outIdx,maxBytesToWrite)=>{if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i<str.length;++i){var u=str.charCodeAt(i);if(u>=55296&&u<=57343){var u1=str.charCodeAt(++i);u=65536+((u&1023)<<10)|u1&1023}if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++]=192|u>>6;heap[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++]=224|u>>12;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}else{if(outIdx+3>=endIdx)break;heap[outIdx++]=240|u>>18;heap[outIdx++]=128|u>>12&63;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}}heap[outIdx]=0;return outIdx-startIdx};var stringToUTF8=(str,outPtr,maxBytesToWrite)=>stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite);var lengthBytesUTF8=str=>{var len=0;for(var i=0;i<str.length;++i){var c=str.charCodeAt(i);if(c<=127){len++}else if(c<=2047){len+=2}else if(c>=55296&&c<=57343){len+=4;++i}else{len+=3}}return len};var wasmImports={a:___assert_fail,b:_emscripten_resize_heap};var wasmExports;createWasm();var ___wasm_call_ctors=()=>(___wasm_call_ctors=wasmExports["d"])();var _teptris_wasm_load=Module["_teptris_wasm_load"]=(a0,a1)=>(_teptris_wasm_load=Module["_teptris_wasm_load"]=wasmExports["e"])(a0,a1);var _teptris_wasm_last_error=Module["_teptris_wasm_last_error"]=()=>(_teptris_wasm_last_error=Module["_teptris_wasm_last_error"]=wasmExports["f"])();var _teptris_wasm_last_error_line=Module["_teptris_wasm_last_error_line"]=()=>(_teptris_wasm_last_error_line=Module["_teptris_wasm_last_error_line"]=wasmExports["g"])();var _teptris_wasm_last_error_column=Module["_teptris_wasm_last_error_column"]=()=>(_teptris_wasm_last_error_column=Module["_teptris_wasm_last_error_column"]=wasmExports["h"])();var _teptris_wasm_json=Module["_teptris_wasm_json"]=()=>(_teptris_wasm_json=Module["_teptris_wasm_json"]=wasmExports["i"])();var _teptris_wasm_json_len=Module["_teptris_wasm_json_len"]=()=>(_teptris_wasm_json_len=Module["_teptris_wasm_json_len"]=wasmExports["j"])();var _teptris_wasm_free=Module["_teptris_wasm_free"]=a0=>(_teptris_wasm_free=Module["_teptris_wasm_free"]=wasmExports["k"])(a0);var _teptris_wasm_alloc=Module["_teptris_wasm_alloc"]=a0=>(_teptris_wasm_alloc=Module["_teptris_wasm_alloc"]=wasmExports["l"])(a0);var _teptris_wasm_builder_new=Module["_teptris_wasm_builder_new"]=()=>(_teptris_wasm_builder_new=Module["_teptris_wasm_builder_new"]=wasmExports["m"])();var _teptris_wasm_builder_free=Module["_teptris_wasm_builder_free"]=a0=>(_teptris_wasm_builder_free=Module["_teptris_wasm_builder_free"]=wasmExports["n"])(a0);var _teptris_wasm_builder_put_string=Module["_teptris_wasm_builder_put_string"]=(a0,a1,a2)=>(_teptris_wasm_builder_put_string=Module["_teptris_wasm_builder_put_string"]=wasmExports["o"])(a0,a1,a2);var _teptris_wasm_builder_put_integer=Module["_teptris_wasm_builder_put_integer"]=(a0,a1,a2)=>(_teptris_wasm_builder_put_integer=Module["_teptris_wasm_builder_put_integer"]=wasmExports["p"])(a0,a1,a2);var _teptris_wasm_builder_put_float=Module["_teptris_wasm_builder_put_float"]=(a0,a1,a2)=>(_teptris_wasm_builder_put_float=Module["_teptris_wasm_builder_put_float"]=wasmExports["q"])(a0,a1,a2);var _teptris_wasm_builder_put_boolean=Module["_teptris_wasm_builder_put_boolean"]=(a0,a1,a2)=>(_teptris_wasm_builder_put_boolean=Module["_teptris_wasm_builder_put_boolean"]=wasmExports["r"])(a0,a1,a2);var _teptris_wasm_builder_put_datetime=Module["_teptris_wasm_builder_put_datetime"]=(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)=>(_teptris_wasm_builder_put_datetime=Module["_teptris_wasm_builder_put_datetime"]=wasmExports["s"])(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10);var _teptris_wasm_builder_open_table=Module["_teptris_wasm_builder_open_table"]=(a0,a1)=>(_teptris_wasm_builder_open_table=Module["_teptris_wasm_builder_open_table"]=wasmExports["t"])(a0,a1);var _teptris_wasm_builder_open_array=Module["_teptris_wasm_builder_open_array"]=(a0,a1)=>(_teptris_wasm_builder_open_array=Module["_teptris_wasm_builder_open_array"]=wasmExports["u"])(a0,a1);var _teptris_wasm_builder_close=Module["_teptris_wasm_builder_close"]=a0=>(_teptris_wasm_builder_close=Module["_teptris_wasm_builder_close"]=wasmExports["v"])(a0);var _teptris_wasm_builder_finish=Module["_teptris_wasm_builder_finish"]=a0=>(_teptris_wasm_builder_finish=Module["_teptris_wasm_builder_finish"]=wasmExports["w"])(a0);var _teptris_wasm_builder_finish_json_natural=Module["_teptris_wasm_builder_finish_json_natural"]=a0=>(_teptris_wasm_builder_finish_json_natural=Module["_teptris_wasm_builder_finish_json_natural"]=wasmExports["x"])(a0);var _teptris_wasm_toml=Module["_teptris_wasm_toml"]=()=>(_teptris_wasm_toml=Module["_teptris_wasm_toml"]=wasmExports["y"])();var _teptris_wasm_toml_len=Module["_teptris_wasm_toml_len"]=()=>(_teptris_wasm_toml_len=Module["_teptris_wasm_toml_len"]=wasmExports["z"])();var _teptris_wasm_plan_build=Module["_teptris_wasm_plan_build"]=(a0,a1,a2,a3,a4,a5)=>(_teptris_wasm_plan_build=Module["_teptris_wasm_plan_build"]=wasmExports["A"])(a0,a1,a2,a3,a4,a5);var _teptris_wasm_plan_free=Module["_teptris_wasm_plan_free"]=a0=>(_teptris_wasm_plan_free=Module["_teptris_wasm_plan_free"]=wasmExports["B"])(a0);var _teptris_wasm_poke_u32=Module["_teptris_wasm_poke_u32"]=(a0,a1,a2)=>(_teptris_wasm_poke_u32=Module["_teptris_wasm_poke_u32"]=wasmExports["C"])(a0,a1,a2);var _teptris_wasm_poke_u8=Module["_teptris_wasm_poke_u8"]=(a0,a1,a2)=>(_teptris_wasm_poke_u8=Module["_teptris_wasm_poke_u8"]=wasmExports["D"])(a0,a1,a2);var _teptris_wasm_plan_walk=Module["_teptris_wasm_plan_walk"]=(a0,a1,a2)=>(_teptris_wasm_plan_walk=Module["_teptris_wasm_plan_walk"]=wasmExports["E"])(a0,a1,a2);var _teptris_version_string=Module["_teptris_version_string"]=()=>(_teptris_version_string=Module["_teptris_version_string"]=wasmExports["G"])();Module["UTF8ToString"]=UTF8ToString;Module["stringToUTF8"]=stringToUTF8;Module["lengthBytesUTF8"]=lengthBytesUTF8;var calledRun;dependenciesFulfilled=function runCaller(){if(!calledRun)run();if(!calledRun)dependenciesFulfilled=runCaller};function run(){if(runDependencies>0){return}preRun();if(runDependencies>0){return}function doRun(){if(calledRun)return;calledRun=true;Module["calledRun"]=true;if(ABORT)return;initRuntime();readyPromiseResolve(Module);Module["onRuntimeInitialized"]?.();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(()=>{setTimeout(()=>Module["setStatus"](""),1);doRun()},1)}else{doRun()}}if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}run();moduleRtn=readyPromise;
|
|
9
|
+
var Module=moduleArg;var readyPromiseResolve,readyPromiseReject;var readyPromise=new Promise((resolve,reject)=>{readyPromiseResolve=resolve;readyPromiseReject=reject});var ENVIRONMENT_IS_WEB=typeof window=="object";var ENVIRONMENT_IS_WORKER=typeof WorkerGlobalScope!="undefined";var ENVIRONMENT_IS_NODE=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string"&&process.type!="renderer";if(ENVIRONMENT_IS_NODE){const{createRequire}=await import("module");let dirname=import.meta.url;if(dirname.startsWith("data:")){dirname="/"}var require=createRequire(dirname)}var moduleOverrides=Object.assign({},Module);var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("fs");var nodePath=require("path");if(!import.meta.url.startsWith("data:")){scriptDirectory=nodePath.dirname(require("url").fileURLToPath(import.meta.url))+"/"}readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?undefined:"utf8");return ret};if(!Module["thisProgram"]&&process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}arguments_=process.argv.slice(2);quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(ENVIRONMENT_IS_WORKER){scriptDirectory=self.location.href}else if(typeof document!="undefined"&&document.currentScript){scriptDirectory=document.currentScript.src}if(_scriptName){scriptDirectory=_scriptName}if(scriptDirectory.startsWith("blob:")){scriptDirectory=""}else{scriptDirectory=scriptDirectory.substr(0,scriptDirectory.replace(/[?#].*/,"").lastIndexOf("/")+1)}{readAsync=async url=>{var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)}}}else{}var out=Module["print"]||console.log.bind(console);var err=Module["printErr"]||console.error.bind(console);Object.assign(Module,moduleOverrides);moduleOverrides=null;if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];var wasmBinary=Module["wasmBinary"];var wasmMemory;var ABORT=false;var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAP64,HEAPU64,HEAPF64;function updateMemoryViews(){var b=wasmMemory.buffer;Module["HEAP8"]=HEAP8=new Int8Array(b);Module["HEAP16"]=HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);Module["HEAPU16"]=HEAPU16=new Uint16Array(b);Module["HEAP32"]=HEAP32=new Int32Array(b);Module["HEAPU32"]=HEAPU32=new Uint32Array(b);Module["HEAPF32"]=HEAPF32=new Float32Array(b);Module["HEAPF64"]=HEAPF64=new Float64Array(b);Module["HEAP64"]=HEAP64=new BigInt64Array(b);Module["HEAPU64"]=HEAPU64=new BigUint64Array(b)}var __ATPRERUN__=[];var __ATINIT__=[];var __ATPOSTRUN__=[];var runtimeInitialized=false;function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(__ATPRERUN__)}function initRuntime(){runtimeInitialized=true;callRuntimeCallbacks(__ATINIT__)}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(__ATPOSTRUN__)}function addOnPreRun(cb){__ATPRERUN__.unshift(cb)}function addOnInit(cb){__ATINIT__.unshift(cb)}function addOnPostRun(cb){__ATPOSTRUN__.unshift(cb)}var runDependencies=0;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;Module["monitorRunDependencies"]?.(runDependencies)}function removeRunDependency(id){runDependencies--;Module["monitorRunDependencies"]?.(runDependencies);if(runDependencies==0){if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}function abort(what){Module["onAbort"]?.(what);what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);readyPromiseReject(e);throw e}var dataURIPrefix="data:application/octet-stream;base64,";var isDataURI=filename=>filename.startsWith(dataURIPrefix);var isFileURI=filename=>filename.startsWith("file://");function findWasmBinary(){if(Module["locateFile"]){var f="teptris.wasm";if(!isDataURI(f)){return locateFile(f)}return f}return new URL("teptris.wasm",import.meta.url).href}var wasmBinaryFile;function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary&&typeof WebAssembly.instantiateStreaming=="function"&&!isDataURI(binaryFile)&&!ENVIRONMENT_IS_NODE&&typeof fetch=="function"){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){return{a:wasmImports}}async function createWasm(){function receiveInstance(instance,module){wasmExports=instance.exports;wasmMemory=wasmExports["c"];updateMemoryViews();addOnInit(wasmExports["d"]);removeRunDependency("wasm-instantiate");return wasmExports}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){receiveInstance(result["instance"])}var info=getWasmImports();if(Module["instantiateWasm"]){try{return Module["instantiateWasm"](info,receiveInstance)}catch(e){err(`Module.instantiateWasm callback failed with error: ${e}`);readyPromiseReject(e)}}wasmBinaryFile??=findWasmBinary();try{var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);receiveInstantiationResult(result);return result}catch(e){readyPromiseReject(e);return}}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var noExitRuntime=Module["noExitRuntime"]||true;var UTF8Decoder=typeof TextDecoder!="undefined"?new TextDecoder:undefined;var UTF8ArrayToString=(heapOrArray,idx=0,maxBytesToRead=NaN)=>{var endIdx=idx+maxBytesToRead;var endPtr=idx;while(heapOrArray[endPtr]&&!(endPtr>=endIdx))++endPtr;if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str="";while(idx<endPtr){var u0=heapOrArray[idx++];if(!(u0&128)){str+=String.fromCharCode(u0);continue}var u1=heapOrArray[idx++]&63;if((u0&224)==192){str+=String.fromCharCode((u0&31)<<6|u1);continue}var u2=heapOrArray[idx++]&63;if((u0&240)==224){u0=(u0&15)<<12|u1<<6|u2}else{u0=(u0&7)<<18|u1<<12|u2<<6|heapOrArray[idx++]&63}if(u0<65536){str+=String.fromCharCode(u0)}else{var ch=u0-65536;str+=String.fromCharCode(55296|ch>>10,56320|ch&1023)}}return str};var UTF8ToString=(ptr,maxBytesToRead)=>ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead):"";var ___assert_fail=(condition,filename,line,func)=>abort(`Assertion failed: ${UTF8ToString(condition)}, at: `+[filename?UTF8ToString(filename):"unknown filename",line,func?UTF8ToString(func):"unknown function"]);var getHeapMax=()=>2147483648;var alignMemory=(size,alignment)=>Math.ceil(size/alignment)*alignment;var growMemory=size=>{var b=wasmMemory.buffer;var pages=(size-b.byteLength+65535)/65536|0;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignMemory(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement){return true}}return false};var stringToUTF8Array=(str,heap,outIdx,maxBytesToWrite)=>{if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i<str.length;++i){var u=str.charCodeAt(i);if(u>=55296&&u<=57343){var u1=str.charCodeAt(++i);u=65536+((u&1023)<<10)|u1&1023}if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++]=192|u>>6;heap[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++]=224|u>>12;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}else{if(outIdx+3>=endIdx)break;heap[outIdx++]=240|u>>18;heap[outIdx++]=128|u>>12&63;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}}heap[outIdx]=0;return outIdx-startIdx};var stringToUTF8=(str,outPtr,maxBytesToWrite)=>stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite);var lengthBytesUTF8=str=>{var len=0;for(var i=0;i<str.length;++i){var c=str.charCodeAt(i);if(c<=127){len++}else if(c<=2047){len+=2}else if(c>=55296&&c<=57343){len+=4;++i}else{len+=3}}return len};var wasmImports={a:___assert_fail,b:_emscripten_resize_heap};var wasmExports;createWasm();var ___wasm_call_ctors=()=>(___wasm_call_ctors=wasmExports["d"])();var _teptris_wasm_load=Module["_teptris_wasm_load"]=(a0,a1)=>(_teptris_wasm_load=Module["_teptris_wasm_load"]=wasmExports["e"])(a0,a1);var _teptris_wasm_last_error=Module["_teptris_wasm_last_error"]=()=>(_teptris_wasm_last_error=Module["_teptris_wasm_last_error"]=wasmExports["f"])();var _teptris_wasm_last_error_line=Module["_teptris_wasm_last_error_line"]=()=>(_teptris_wasm_last_error_line=Module["_teptris_wasm_last_error_line"]=wasmExports["g"])();var _teptris_wasm_last_error_column=Module["_teptris_wasm_last_error_column"]=()=>(_teptris_wasm_last_error_column=Module["_teptris_wasm_last_error_column"]=wasmExports["h"])();var _teptris_wasm_json=Module["_teptris_wasm_json"]=()=>(_teptris_wasm_json=Module["_teptris_wasm_json"]=wasmExports["i"])();var _teptris_wasm_json_len=Module["_teptris_wasm_json_len"]=()=>(_teptris_wasm_json_len=Module["_teptris_wasm_json_len"]=wasmExports["j"])();var _teptris_wasm_free=Module["_teptris_wasm_free"]=a0=>(_teptris_wasm_free=Module["_teptris_wasm_free"]=wasmExports["k"])(a0);var _teptris_wasm_alloc=Module["_teptris_wasm_alloc"]=a0=>(_teptris_wasm_alloc=Module["_teptris_wasm_alloc"]=wasmExports["l"])(a0);var _teptris_wasm_builder_new=Module["_teptris_wasm_builder_new"]=()=>(_teptris_wasm_builder_new=Module["_teptris_wasm_builder_new"]=wasmExports["m"])();var _teptris_wasm_builder_free=Module["_teptris_wasm_builder_free"]=a0=>(_teptris_wasm_builder_free=Module["_teptris_wasm_builder_free"]=wasmExports["n"])(a0);var _teptris_wasm_builder_put_string=Module["_teptris_wasm_builder_put_string"]=(a0,a1,a2)=>(_teptris_wasm_builder_put_string=Module["_teptris_wasm_builder_put_string"]=wasmExports["o"])(a0,a1,a2);var _teptris_wasm_builder_put_integer=Module["_teptris_wasm_builder_put_integer"]=(a0,a1,a2)=>(_teptris_wasm_builder_put_integer=Module["_teptris_wasm_builder_put_integer"]=wasmExports["p"])(a0,a1,a2);var _teptris_wasm_builder_put_float=Module["_teptris_wasm_builder_put_float"]=(a0,a1,a2)=>(_teptris_wasm_builder_put_float=Module["_teptris_wasm_builder_put_float"]=wasmExports["q"])(a0,a1,a2);var _teptris_wasm_builder_put_boolean=Module["_teptris_wasm_builder_put_boolean"]=(a0,a1,a2)=>(_teptris_wasm_builder_put_boolean=Module["_teptris_wasm_builder_put_boolean"]=wasmExports["r"])(a0,a1,a2);var _teptris_wasm_builder_put_datetime=Module["_teptris_wasm_builder_put_datetime"]=(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)=>(_teptris_wasm_builder_put_datetime=Module["_teptris_wasm_builder_put_datetime"]=wasmExports["s"])(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10);var _teptris_wasm_builder_open_table=Module["_teptris_wasm_builder_open_table"]=(a0,a1)=>(_teptris_wasm_builder_open_table=Module["_teptris_wasm_builder_open_table"]=wasmExports["t"])(a0,a1);var _teptris_wasm_builder_open_array=Module["_teptris_wasm_builder_open_array"]=(a0,a1)=>(_teptris_wasm_builder_open_array=Module["_teptris_wasm_builder_open_array"]=wasmExports["u"])(a0,a1);var _teptris_wasm_builder_close=Module["_teptris_wasm_builder_close"]=a0=>(_teptris_wasm_builder_close=Module["_teptris_wasm_builder_close"]=wasmExports["v"])(a0);var _teptris_wasm_dump_ops=Module["_teptris_wasm_dump_ops"]=(a0,a1)=>(_teptris_wasm_dump_ops=Module["_teptris_wasm_dump_ops"]=wasmExports["w"])(a0,a1);var _teptris_wasm_builder_finish=Module["_teptris_wasm_builder_finish"]=a0=>(_teptris_wasm_builder_finish=Module["_teptris_wasm_builder_finish"]=wasmExports["x"])(a0);var _teptris_wasm_builder_finish_json_natural=Module["_teptris_wasm_builder_finish_json_natural"]=a0=>(_teptris_wasm_builder_finish_json_natural=Module["_teptris_wasm_builder_finish_json_natural"]=wasmExports["y"])(a0);var _teptris_wasm_toml=Module["_teptris_wasm_toml"]=()=>(_teptris_wasm_toml=Module["_teptris_wasm_toml"]=wasmExports["z"])();var _teptris_wasm_toml_len=Module["_teptris_wasm_toml_len"]=()=>(_teptris_wasm_toml_len=Module["_teptris_wasm_toml_len"]=wasmExports["A"])();var _teptris_wasm_plan_build=Module["_teptris_wasm_plan_build"]=(a0,a1,a2,a3,a4,a5)=>(_teptris_wasm_plan_build=Module["_teptris_wasm_plan_build"]=wasmExports["B"])(a0,a1,a2,a3,a4,a5);var _teptris_wasm_plan_free=Module["_teptris_wasm_plan_free"]=a0=>(_teptris_wasm_plan_free=Module["_teptris_wasm_plan_free"]=wasmExports["C"])(a0);var _teptris_wasm_poke_u32=Module["_teptris_wasm_poke_u32"]=(a0,a1,a2)=>(_teptris_wasm_poke_u32=Module["_teptris_wasm_poke_u32"]=wasmExports["D"])(a0,a1,a2);var _teptris_wasm_poke_u8=Module["_teptris_wasm_poke_u8"]=(a0,a1,a2)=>(_teptris_wasm_poke_u8=Module["_teptris_wasm_poke_u8"]=wasmExports["E"])(a0,a1,a2);var _teptris_wasm_plan_walk=Module["_teptris_wasm_plan_walk"]=(a0,a1,a2)=>(_teptris_wasm_plan_walk=Module["_teptris_wasm_plan_walk"]=wasmExports["F"])(a0,a1,a2);var _teptris_version_string=Module["_teptris_version_string"]=()=>(_teptris_version_string=Module["_teptris_version_string"]=wasmExports["H"])();Module["UTF8ToString"]=UTF8ToString;Module["stringToUTF8"]=stringToUTF8;Module["lengthBytesUTF8"]=lengthBytesUTF8;var calledRun;dependenciesFulfilled=function runCaller(){if(!calledRun)run();if(!calledRun)dependenciesFulfilled=runCaller};function run(){if(runDependencies>0){return}preRun();if(runDependencies>0){return}function doRun(){if(calledRun)return;calledRun=true;Module["calledRun"]=true;if(ABORT)return;initRuntime();readyPromiseResolve(Module);Module["onRuntimeInitialized"]?.();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(()=>{setTimeout(()=>Module["setStatus"](""),1);doRun()},1)}else{doRun()}}if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}run();moduleRtn=readyPromise;
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
return moduleRtn;
|
package/dist/teptris.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "teptris",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.10",
|
|
4
4
|
"description": "TOML for JavaScript/TypeScript at libteptris speed (WebAssembly, no fallback) - version tracks the engine ({engine}.{iteration}; npm semver is 3-part)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
package/src/index.js
CHANGED
|
@@ -51,6 +51,20 @@ function parseDateTime(str) {
|
|
|
51
51
|
const RFC3339 =
|
|
52
52
|
/^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})?)?$|^\d{2}:\d{2}:\d{2}(\.\d+)?$/;
|
|
53
53
|
|
|
54
|
+
// cheap charset pre-check before the RFC 3339 regex: datetimes start
|
|
55
|
+
// with a digit and only ever contain digits, date/time punctuation
|
|
56
|
+
// and TZ marks - rejects nearly all plain strings without the regex
|
|
57
|
+
const DATETIME_CHARS = /[0-9Tt: .+Zz-]/;
|
|
58
|
+
const utf8 = new TextDecoder("utf-8");
|
|
59
|
+
function maybeRfc3339(v) {
|
|
60
|
+
const c0 = v.charCodeAt(0);
|
|
61
|
+
if (!(c0 >= 48 && c0 <= 57)) return false;
|
|
62
|
+
for (let i = 1; i < v.length; i++) {
|
|
63
|
+
if (!DATETIME_CHARS.test(v[i])) return false;
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
|
|
54
68
|
function buildValue(mod, b, key, v, errs) {
|
|
55
69
|
const kp = key == null ? 0 : cstr(mod, key);
|
|
56
70
|
try {
|
|
@@ -122,7 +136,9 @@ export function initApi(mod) {
|
|
|
122
136
|
let value = null, error = null;
|
|
123
137
|
if (st === 0) {
|
|
124
138
|
const jptr = mod._teptris_wasm_json();
|
|
125
|
-
|
|
139
|
+
const jlen = mod._teptris_wasm_json_len();
|
|
140
|
+
value = JSON.parse(
|
|
141
|
+
utf8.decode(mod.HEAPU8.subarray(jptr, jptr + jlen)));
|
|
126
142
|
mod._teptris_wasm_free(jptr);
|
|
127
143
|
} else {
|
|
128
144
|
error = {
|
|
@@ -166,17 +182,149 @@ export function initApi(mod) {
|
|
|
166
182
|
return out;
|
|
167
183
|
}
|
|
168
184
|
|
|
185
|
+
// Fused dumps: the object tree is encoded ONCE into a writer
|
|
186
|
+
// op-stream (Uint8Array), then a single crossing builds the TOML
|
|
187
|
+
// text - no per-value builder calls, no DOM, no second walk.
|
|
169
188
|
function dump(obj) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
189
|
+
if (obj === null || typeof obj !== "object" || Array.isArray(obj)) {
|
|
190
|
+
throw new TypeError("dump expects a table object (TOML roots are tables)");
|
|
191
|
+
}
|
|
192
|
+
const enc = new TextEncoder();
|
|
193
|
+
let buf = new Uint8Array(1 << 16);
|
|
194
|
+
let n = 0;
|
|
195
|
+
let dv = new DataView(buf.buffer);
|
|
196
|
+
const ensure = (k) => {
|
|
197
|
+
if (n + k <= buf.length) return;
|
|
198
|
+
let cap = buf.length * 2;
|
|
199
|
+
while (n + k > cap) cap *= 2;
|
|
200
|
+
const nb = new Uint8Array(cap);
|
|
201
|
+
nb.set(buf.subarray(0, n));
|
|
202
|
+
buf = nb;
|
|
203
|
+
dv = new DataView(buf.buffer);
|
|
204
|
+
};
|
|
205
|
+
const byte = (c) => { ensure(1); buf[n++] = c; };
|
|
206
|
+
const u32 = (v) => {
|
|
207
|
+
ensure(4);
|
|
208
|
+
dv.setUint32(n, v, true);
|
|
209
|
+
n += 4;
|
|
210
|
+
};
|
|
211
|
+
const i64 = (v) => {
|
|
212
|
+
ensure(8);
|
|
213
|
+
if (v >= -2147483648 && v <= 2147483647) {
|
|
214
|
+
dv.setInt32(n, v, true);
|
|
215
|
+
dv.setInt32(n + 4, v < 0 ? -1 : 0, true);
|
|
216
|
+
} else {
|
|
217
|
+
dv.setBigInt64(n, BigInt(v), true);
|
|
175
218
|
}
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
219
|
+
n += 8;
|
|
220
|
+
};
|
|
221
|
+
const f64 = (d) => {
|
|
222
|
+
ensure(8);
|
|
223
|
+
dv.setFloat64(n, d, true);
|
|
224
|
+
n += 8;
|
|
225
|
+
};
|
|
226
|
+
const wkey = (k) => {
|
|
227
|
+
ensure(2 + k.length * 3);
|
|
228
|
+
buf[n++] = 1;
|
|
229
|
+
const { written } = enc.encodeInto(k, buf.subarray(n + 1));
|
|
230
|
+
buf[n] = written;
|
|
231
|
+
n += 1 + written;
|
|
232
|
+
};
|
|
233
|
+
const scalar = (k, v) => {
|
|
234
|
+
if (k === null) { ensure(2); buf[n++] = 1; buf[n++] = 0; }
|
|
235
|
+
else wkey(k);
|
|
236
|
+
if (typeof v === "boolean") { byte(v ? 6 : 5); return; }
|
|
237
|
+
if (typeof v === "number") {
|
|
238
|
+
if (Number.isInteger(v)) { byte(3); i64(v); }
|
|
239
|
+
else { byte(4); f64(v); }
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (typeof v === "bigint") { byte(3); i64(v); return; }
|
|
243
|
+
if (typeof v === "string") {
|
|
244
|
+
if (maybeRfc3339(v) && RFC3339.test(v)) {
|
|
245
|
+
const dt = parseDateTime(v);
|
|
246
|
+
wkey(k);
|
|
247
|
+
ensure(27);
|
|
248
|
+
buf[n++] = 7;
|
|
249
|
+
buf[n++] = dt.kind;
|
|
250
|
+
i64(dt.year);
|
|
251
|
+
buf[n++] = dt.month; buf[n++] = dt.day; buf[n++] = dt.hour;
|
|
252
|
+
buf[n++] = dt.minute; buf[n++] = dt.second;
|
|
253
|
+
u32(dt.nanosecond);
|
|
254
|
+
i64(dt.offset_seconds);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
ensure(5 + v.length * 3);
|
|
258
|
+
buf[n++] = 2;
|
|
259
|
+
const { written } = enc.encodeInto(v, buf.subarray(n + 4));
|
|
260
|
+
dv.setUint32(n, written, true);
|
|
261
|
+
n += 4 + written;
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
throw new Error("null/undefined cannot round-trip through TOML");
|
|
265
|
+
};
|
|
266
|
+
const isScalar = (v) =>
|
|
267
|
+
v !== null && (typeof v !== "object" || Array.isArray(v) === false &&
|
|
268
|
+
(typeof v === "string" || typeof v === "number" ||
|
|
269
|
+
typeof v === "boolean" || typeof v === "bigint"));
|
|
270
|
+
const members = (o, inline) => {
|
|
271
|
+
const keys = Object.keys(o);
|
|
272
|
+
for (let i = 0; i < keys.length; i++) {
|
|
273
|
+
const k = keys[i], v = o[k];
|
|
274
|
+
if (isScalar(v)) scalar(k, v);
|
|
275
|
+
}
|
|
276
|
+
for (let i = 0; i < keys.length; i++) {
|
|
277
|
+
const k = keys[i], v = o[k];
|
|
278
|
+
if (isScalar(v)) continue;
|
|
279
|
+
if (v === null || v === undefined) {
|
|
280
|
+
throw new Error("null/undefined cannot round-trip through TOML");
|
|
281
|
+
}
|
|
282
|
+
wkey(k);
|
|
283
|
+
if (Array.isArray(v)) {
|
|
284
|
+
const aot = v.length > 0 && !inline && v.every(
|
|
285
|
+
(x) => x !== null && typeof x === "object" &&
|
|
286
|
+
!Array.isArray(x));
|
|
287
|
+
if (aot) {
|
|
288
|
+
byte(0x0A);
|
|
289
|
+
for (const el of v) { byte(8); members(el, true); byte(0x0C); }
|
|
290
|
+
byte(0x0C);
|
|
291
|
+
} else {
|
|
292
|
+
byte(0x09);
|
|
293
|
+
for (const el of v) arrayVal(el);
|
|
294
|
+
byte(0x0C);
|
|
295
|
+
}
|
|
296
|
+
} else {
|
|
297
|
+
byte(inline ? 0x0B : 0x08);
|
|
298
|
+
members(v, inline);
|
|
299
|
+
byte(0x0C);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
const arrayVal = (el) => {
|
|
304
|
+
if (isScalar(el)) { scalar(null, el); return; }
|
|
305
|
+
if (Array.isArray(el)) {
|
|
306
|
+
byte(0x09);
|
|
307
|
+
for (const x of el) arrayVal(x);
|
|
308
|
+
byte(0x0C);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
if (el === null || el === undefined) {
|
|
312
|
+
throw new Error("null/undefined cannot round-trip through TOML");
|
|
313
|
+
}
|
|
314
|
+
byte(0x0B);
|
|
315
|
+
members(el, true);
|
|
316
|
+
byte(0x0C);
|
|
317
|
+
};
|
|
318
|
+
members(obj, false);
|
|
319
|
+
byte(0x00);
|
|
320
|
+
const ptr = mod._teptris_wasm_alloc(n);
|
|
321
|
+
mod.HEAPU8.set(buf.subarray(0, n), ptr);
|
|
322
|
+
const st = mod._teptris_wasm_dump_ops(ptr, n);
|
|
323
|
+
mod._teptris_wasm_free(ptr);
|
|
324
|
+
if (st !== 0) {
|
|
325
|
+
throw new Error(`dump failed (status ${st})`);
|
|
179
326
|
}
|
|
327
|
+
return readOut(mod._teptris_wasm_toml());
|
|
180
328
|
}
|
|
181
329
|
|
|
182
330
|
// Natural JSON (engine 0.3.0): real numbers, booleans, RFC 3339
|
package/src/teptris_wasm.c
CHANGED
|
@@ -134,6 +134,34 @@ int teptris_wasm_builder_close(void *b) {
|
|
|
134
134
|
static char *g_toml;
|
|
135
135
|
static size_t g_toml_len;
|
|
136
136
|
|
|
137
|
+
/* fused dumps: the JS side encodes one op-stream (writer grammar),
|
|
138
|
+
* this builds TOML in one crossing - no per-value builder calls, no
|
|
139
|
+
* DOM */
|
|
140
|
+
EMSCRIPTEN_KEEPALIVE
|
|
141
|
+
int teptris_wasm_dump_ops(const uint8_t *ops, size_t len) {
|
|
142
|
+
teptris_writer *w = teptris_writer_new();
|
|
143
|
+
if (w == NULL) {
|
|
144
|
+
snprintf(last_error, sizeof last_error, "writer alloc failed");
|
|
145
|
+
return (int)TEPTRIS_ERR_ALLOC;
|
|
146
|
+
}
|
|
147
|
+
teptris_status st = teptris_writer_feed(w, ops, len);
|
|
148
|
+
if (st == TEPTRIS_OK) {
|
|
149
|
+
st = teptris_writer_finish(w, &g_toml, &g_toml_len);
|
|
150
|
+
} else {
|
|
151
|
+
teptris_writer_free(w);
|
|
152
|
+
snprintf(last_error, sizeof last_error, "%s",
|
|
153
|
+
teptris_status_string(st));
|
|
154
|
+
return (int)st;
|
|
155
|
+
}
|
|
156
|
+
teptris_writer_free(w);
|
|
157
|
+
if (st != TEPTRIS_OK) {
|
|
158
|
+
snprintf(last_error, sizeof last_error, "%s",
|
|
159
|
+
teptris_status_string(st));
|
|
160
|
+
}
|
|
161
|
+
return (int)st;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
|
|
137
165
|
static int finish_with(void *b,
|
|
138
166
|
teptris_status (*emit)(const teptris_document *,
|
|
139
167
|
char **, size_t *)) {
|