Comparing version 1.0.10 to 1.0.11
{ | ||
"name": "kscryp", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"description": "Cryptography package with support for: JWT, RSA, MD5, SHA, Base64, HEX, JSON, Basic", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -232,3 +232,3 @@ # Ks Cryp | ||
`; | ||
const resObj = target.decode(srtObj, "json", { defaultValue: null, strict: true }); | ||
const resObj = target.decode(srtObj, "json", { clean: true }); | ||
console.log( | ||
@@ -235,0 +235,0 @@ resObj.name === "PIL W2F", |
@@ -18,2 +18,35 @@ const KsDriver = require("../KsDriver"); | ||
#clean(val) { | ||
if (typeof val !== "string") { | ||
return val; | ||
} | ||
return val | ||
.replace(/\\r|\r|\n|\\n/g, "") | ||
.replace(/{[\s|\\]+"/g, '{"') | ||
.replace(/[\s|\\]+"[\s|,]*}/g, '"}') | ||
.replace(/\[[\s|\\]+"/g, '["') | ||
.replace(/[\s|\\]+"[\s|,]*\]/g, '"]') | ||
.replace(/,[\s|\\]+"/g, ',"') | ||
.replace(/[\s|\\]+"\s*,/g, '",') | ||
.replace(/:[\s|\\]+"/g, ':"') | ||
.replace(/[\s|\\]+"\s*:/g, '":') | ||
.replace(/[\s|'|"]+{/g, '{') | ||
.replace(/}[\s|'|"]+/g, '}') | ||
.replace(/[\s|'|"]+\[/g, '[') | ||
.replace(/\][\s|'|"]+/g, ']') | ||
.replace(/\][\s|,]+\]/g, ']]') | ||
.replace(/\}[\s|,]+\]/g, '}]') | ||
.replace(/\][\s|,]+\}/g, ']}') | ||
.replace(/\}[\s|,]+\}/g, '}}') | ||
.replace(/true[\s|,]+\}/g, 'true}') | ||
.replace(/false[\s|,]+\}/g, 'false}') | ||
.replace(/true[\s|,]+\]/g, 'true]') | ||
.replace(/false[\s|,]+\]/g, 'false]') | ||
; | ||
} | ||
encode(value, options) { | ||
@@ -23,2 +56,3 @@ options = options || {}; | ||
options.validType = "object"; | ||
options.clean && (value = this.#clean(value)); | ||
return this.respond(value, null, options) ?? JSON.stringify(value, this.#check()); | ||
@@ -35,9 +69,3 @@ } | ||
options.validType = "string"; | ||
if (typeof (value) === "string" && options.strict) { | ||
value = value | ||
.replace(/\\"/g, '"') | ||
.replace(/"{/g, '{') | ||
.replace(/}"/g, '}') | ||
.replace(/\\r|\r|\n|\\n/g, ""); | ||
} | ||
options.clean && (value = this.#clean(value)); | ||
return this.respond(value, null, options) ?? JSON.parse(value); | ||
@@ -44,0 +72,0 @@ } |
@@ -34,13 +34,32 @@ const target = require("../") | ||
\\"PAL\\":\\"PT | ||
PAL\\"}" | ||
PAL\\" , | ||
\\"content\\": \\"<tr class=\\"table er-hw\\" role=\\"row\\"> | ||
<span style=\\"color: rgb(0,51,102);\\"> '.' </tr>\\" | ||
, | ||
\\"P1\\": { \\"d\\": true , ,}, | ||
\\"P2\\": { \\"d\\": false , ,}, | ||
\\"P3\\": { \\"d\\": \\"1\\" , ,,}, | ||
\\"A1\\": [true , , ,], | ||
\\"A2\\": [false , , ,], | ||
\\"A3\\": [\\"1\\" , ,], | ||
\\"A3\\": [{}, {}, ,], ,, | ||
}" | ||
`; | ||
const resObj1 = target.decode(srtObj1, "json", { defaultValue: null, strict: true }); | ||
const resObj2 = target.decode(srtObj2, "json", { defaultValue: null, strict: true }); | ||
const srtObj4 = '"{ \\"ito\\": \\"adm\\"}"'; | ||
const srtObj6 = "'\"{\\\\\\\"W2F\\\\\":\\\\\"PILOT 'mito' \\\" W2F\\\\\" ,\\\\\"PAL\\\\\":\\\\\"PILOT PAL\\\\\"}\"'"; | ||
const resObj1 = target.decode(srtObj1, "json", { clean: true }); | ||
const resObj2 = target.decode(srtObj2, "json", { clean: true }); | ||
const resObj3 = target.decode(srtObj2, "json"); | ||
const resObj4 = target.decode(srtObj4, "json"); | ||
const resObj5 = target.decode(srtObj4, "json", { clean: true }); | ||
const resObj6 = target.decode(srtObj6, "json", { clean: true }); | ||
expect(resObj1).toBeInstanceOf(Object); | ||
expect(resObj2).toBeInstanceOf(Object); | ||
expect(resObj5).toBeInstanceOf(Object); | ||
expect(resObj6).toBeInstanceOf(Object); | ||
expect(resObj1.W2F).toBe("PIL W2F"); | ||
expect(resObj2.W2F).toBe("PIL W2F"); | ||
expect(resObj3).toBe(srtObj2); | ||
expect(typeof resObj4).toBe("string"); | ||
}); | ||
@@ -47,0 +66,0 @@ |
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
52919
970