Comparing version 1.2.3 to 1.2.4
@@ -23,3 +23,3 @@ import n from "moo"; | ||
*/ | ||
Punctuator: /--|\+\+|=>|\.{3}|\??\.(?!\d)|(?:&&|\|\||\?\?|[+\-%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2}|\/(?![\/*]))=?|[?~,:;[\](){}]/u, | ||
Punctuator: /--|\+\+|=>|\.{3}|\??\.(?!\d)|(?:&&|\|\||\?\?|[+\-%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2}|\/(?![/*]))=?|[?~,:;[\](){}]/u, | ||
/** | ||
@@ -49,7 +49,5 @@ * Matches boolean literals, allowing for optional single or double quotes. | ||
function d(t, a = {}) { | ||
const u = t.trim().replace(/[\,]+$/, ""); | ||
if (u === "") | ||
return "{}"; | ||
if (!l(u)) | ||
throw new TypeError("Unexpected input format"); | ||
const u = t.trim().replace(/[,]+$/, ""); | ||
if (u === "") return "{}"; | ||
if (!l(u)) throw new TypeError("Unexpected input format"); | ||
let r = ""; | ||
@@ -69,3 +67,3 @@ i.reset(u); | ||
} | ||
return r.replace(/\,([\}\]])/g, "$1"); | ||
return r.replace(/,([}\]])/g, "$1"); | ||
} | ||
@@ -72,0 +70,0 @@ function l(t) { |
@@ -1,1 +0,1 @@ | ||
(function(u,n){typeof exports=="object"&&typeof module<"u"?module.exports=n(require("moo")):typeof define=="function"&&define.amd?define(["moo"],n):(u=typeof globalThis<"u"?globalThis:u||self,u.jsonLoose=n(u.moo))})(this,function(u){"use strict";const n=u.compile({WhiteSpace:{match:/[\t\v\f\ufeff\p{Zs}]+/u,lineBreaks:!0},Lines:{match:/\r?\n|[\r\u2028\u2029]/u,lineBreaks:!0},ObjectKey:/\[?(?:\x23)?(?=[$_\p{ID_Start}\\])(?:[$_\u200C\u200D\p{ID_Continue}]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+\]?(?=:)/u,Punctuator:/--|\+\+|=>|\.{3}|\??\.(?!\d)|(?:&&|\|\||\?\?|[+\-%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2}|\/(?![\/*]))=?|[?~,:;[\](){}]/u,BooleanLiteral:/true|false/u,NumericLiteral:/(?:0[xX][\da-fA-F](?:_?[\da-fA-F])*|0[oO][0-7](?:_?[0-7])*|0[bB][01](?:_?[01])*)n?|0n|[1-9](?:_?\d)*n|(?:(?:0(?!\d)|0\d*[89]\d*|[1-9](?:_?\d)*)(?:\.(?:\d(?:_?\d)*)?)?|\.\d(?:_?\d)*)(?:[eE][+-]?\d(?:_?\d)*)?|0[0-7]+/u,StringLiteral:{match:/(?:'(?:(?!')[^\\\n\r]|\\(?:\r\n|[^]))*')|(?:"(?:(?!")[^\\\n\r]|\\(?:\r\n|[^]))*")/u,value:t=>`"${t.slice(1,-1)}"`},Identifier:/(?:\x23)?(?=[$_\p{ID_Start}\\])(?:[$_\u200C\u200D\p{ID_Continue}]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+/u});function o(t,r={}){const i=t.trim().replace(/[\,]+$/,"");if(i==="")return"{}";if(!d(i))throw new TypeError("Unexpected input format");let a="";n.reset(i);for(const e of n)if(!(e.type==="WhiteSpace"||e.type==="Lines")){switch(e.type){case"Identifier":e.value=`"${r[e.value]||e.value}"`;break;case"ObjectKey":e.value.slice(0,1)==="["&&e.value.slice(-1)==="]"?e.value=`"${r[e.value.slice(1,-1)]||e.value.slice(1,-1)}"`:e.value=`"${e.value}"`;break}a+=e.value}return a.replace(/\,([\}\]])/g,"$1")}function d(t){return t.startsWith("{")&&t.endsWith("}")||t.startsWith("[")&&t.endsWith("]")}return o}); | ||
(function(u,n){typeof exports=="object"&&typeof module<"u"?module.exports=n(require("moo")):typeof define=="function"&&define.amd?define(["moo"],n):(u=typeof globalThis<"u"?globalThis:u||self,u.jsonLoose=n(u.moo))})(this,function(u){"use strict";const n=u.compile({WhiteSpace:{match:/[\t\v\f\ufeff\p{Zs}]+/u,lineBreaks:!0},Lines:{match:/\r?\n|[\r\u2028\u2029]/u,lineBreaks:!0},ObjectKey:/\[?(?:\x23)?(?=[$_\p{ID_Start}\\])(?:[$_\u200C\u200D\p{ID_Continue}]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+\]?(?=:)/u,Punctuator:/--|\+\+|=>|\.{3}|\??\.(?!\d)|(?:&&|\|\||\?\?|[+\-%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2}|\/(?![/*]))=?|[?~,:;[\](){}]/u,BooleanLiteral:/true|false/u,NumericLiteral:/(?:0[xX][\da-fA-F](?:_?[\da-fA-F])*|0[oO][0-7](?:_?[0-7])*|0[bB][01](?:_?[01])*)n?|0n|[1-9](?:_?\d)*n|(?:(?:0(?!\d)|0\d*[89]\d*|[1-9](?:_?\d)*)(?:\.(?:\d(?:_?\d)*)?)?|\.\d(?:_?\d)*)(?:[eE][+-]?\d(?:_?\d)*)?|0[0-7]+/u,StringLiteral:{match:/(?:'(?:(?!')[^\\\n\r]|\\(?:\r\n|[^]))*')|(?:"(?:(?!")[^\\\n\r]|\\(?:\r\n|[^]))*")/u,value:t=>`"${t.slice(1,-1)}"`},Identifier:/(?:\x23)?(?=[$_\p{ID_Start}\\])(?:[$_\u200C\u200D\p{ID_Continue}]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+/u});function o(t,r={}){const i=t.trim().replace(/[,]+$/,"");if(i==="")return"{}";if(!d(i))throw new TypeError("Unexpected input format");let a="";n.reset(i);for(const e of n)if(!(e.type==="WhiteSpace"||e.type==="Lines")){switch(e.type){case"Identifier":e.value=`"${r[e.value]||e.value}"`;break;case"ObjectKey":e.value.slice(0,1)==="["&&e.value.slice(-1)==="]"?e.value=`"${r[e.value.slice(1,-1)]||e.value.slice(1,-1)}"`:e.value=`"${e.value}"`;break}a+=e.value}return a.replace(/,([}\]])/g,"$1")}function d(t){return t.startsWith("{")&&t.endsWith("}")||t.startsWith("[")&&t.endsWith("]")}return o}); |
{ | ||
"name": "json-loose", | ||
"description": "Transforms loosely structured plain object strings into valid JSON strings", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"publishConfig": { | ||
@@ -54,5 +54,5 @@ "access": "public" | ||
"@types/moo": "0.5.9", | ||
"doogu": "3.2.8", | ||
"semantic-release": "^22.0.10", | ||
"vite-plugin-resolve-umd-format": "^1.0.0" | ||
"doogu": "4.0.4", | ||
"semantic-release": "^24.1.0", | ||
"vite-plugin-resolve-umd-format": "1.0.0" | ||
}, | ||
@@ -64,6 +64,3 @@ "config": { | ||
}, | ||
"eslintConfig": { | ||
"extends": "./node_modules/doogu/eslint" | ||
}, | ||
"prettier": "doogu/prettier.json", | ||
"prettier": "doogu/prettier.config.js", | ||
"release": { | ||
@@ -70,0 +67,0 @@ "extends": "doogu/release.config.js" |
# json-loose | ||
A utility to handle and transform loosely structured data into valid JSON strings. It offers an intuitive solution to ensure data consistency and compatibility, providing a safer alternative to using the `Function` constructor to obtain an object from a string. | ||
A utility that converts loosely structured data into valid JSON strings, ensuring data consistency and compatibility. It provides a safer alternative to using the `Function` constructor to create objects from strings. | ||
@@ -118,12 +118,3 @@ ## Install | ||
- [attributes-parser](https://github.com/bent10/attributes-parser) – A utility for parsing and tokenizing attributes string into meaningful tokens and key-value pairs. | ||
- [js-tokens](https://www.npmjs.com/package/js-tokens) – A JavaScript tokenizer that never fails. | ||
## Benchmarks | ||
```bash | ||
name hz min max mean p75 p99 p995 p999 rme samples | ||
· json-loose 109,620.27 0.0077 0.7080 0.0091 0.0083 0.0168 0.0363 0.2052 ±1.19% 54811 fastest | ||
· js-tokens 54,156.77 0.0116 24.3425 0.0185 0.0122 0.0247 0.0643 1.1352 ±15.68% 27267 | ||
``` | ||
## Contributing | ||
@@ -130,0 +121,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12553
96
140