@sinclair/typebox-codegen
Advanced tools
@@ -5,3 +5,3 @@ export declare namespace MemberExpressionEncoder { | ||
| export declare namespace PropertyEncoder { | ||
| function Encode(value: string): string; | ||
| function Encode(key: string): string; | ||
| } |
@@ -43,3 +43,3 @@ "use strict"; | ||
| function IsAlpha(code) { | ||
| return (code >= 64 && code <= 90) || (code >= 97 && code <= 122); | ||
| return (code >= 65 && code <= 90) || (code >= 97 && code <= 122); | ||
| } | ||
@@ -91,3 +91,3 @@ Character.IsAlpha = IsAlpha; | ||
| } | ||
| function IsSafeProperty(value) { | ||
| function IsAccessor(value) { | ||
| if (IsFirstCharacterNumeric(value)) | ||
@@ -103,9 +103,9 @@ return false; | ||
| } | ||
| function Quoted(value) { | ||
| return `'${value}'`; | ||
| function EscapeHyphen(key) { | ||
| return key.replace(/'/g, "\\'"); | ||
| } | ||
| function Encode(value) { | ||
| return IsSafeProperty(value) ? value : Quoted(value); | ||
| function Encode(key) { | ||
| return IsAccessor(key) ? `${key}` : `'${EscapeHyphen(key)}'`; | ||
| } | ||
| PropertyEncoder.Encode = Encode; | ||
| })(PropertyEncoder || (exports.PropertyEncoder = PropertyEncoder = {})); |
@@ -29,56 +29,5 @@ "use strict"; | ||
| exports.ModelToTypeScript = void 0; | ||
| const formatter_1 = require("../common/formatter"); | ||
| const index_1 = require("../common/index"); | ||
| const compiler_1 = require("@sinclair/typebox/compiler"); | ||
| const Types = require("@sinclair/typebox"); | ||
| // ------------------------------------------------------------------ | ||
| // Character | ||
| // ------------------------------------------------------------------ | ||
| var Character; | ||
| (function (Character) { | ||
| function DollarSign(code) { | ||
| return code === 36; | ||
| } | ||
| Character.DollarSign = DollarSign; | ||
| function IsUnderscore(code) { | ||
| return code === 95; | ||
| } | ||
| Character.IsUnderscore = IsUnderscore; | ||
| function IsAlpha(code) { | ||
| return (code >= 65 && code <= 90) || (code >= 97 && code <= 122); | ||
| } | ||
| Character.IsAlpha = IsAlpha; | ||
| function IsNumeric(code) { | ||
| return code >= 48 && code <= 57; | ||
| } | ||
| Character.IsNumeric = IsNumeric; | ||
| })(Character || (Character = {})); | ||
| // ------------------------------------------------------------------ | ||
| // PropertyKey | ||
| // ------------------------------------------------------------------ | ||
| var PropertyKey; | ||
| (function (PropertyKey) { | ||
| function IsFirstCharacterNumeric(value) { | ||
| if (value.length === 0) | ||
| return false; | ||
| return Character.IsNumeric(value.charCodeAt(0)); | ||
| } | ||
| function IsAccessor(value) { | ||
| if (IsFirstCharacterNumeric(value)) | ||
| return false; | ||
| for (let i = 0; i < value.length; i++) { | ||
| const code = value.charCodeAt(i); | ||
| const check = Character.IsAlpha(code) || Character.IsNumeric(code) || Character.DollarSign(code) || Character.IsUnderscore(code); | ||
| if (!check) | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| function EscapeHyphen(key) { | ||
| return key.replace(/'/g, "\\'"); | ||
| } | ||
| function Encode(key) { | ||
| return IsAccessor(key) ? `${key}` : `'${EscapeHyphen(key)}'`; | ||
| } | ||
| PropertyKey.Encode = Encode; | ||
| })(PropertyKey || (PropertyKey = {})); | ||
| var ModelToTypeScript; | ||
@@ -146,3 +95,3 @@ (function (ModelToTypeScript) { | ||
| optional ? `${key}?: ${Visit(property)}` : | ||
| `${PropertyKey.Encode(key)}: ${Visit(property)}`); | ||
| `${index_1.PropertyEncoder.Encode(key)}: ${Visit(property)}`); | ||
| }).join(',\n'); | ||
@@ -273,5 +222,5 @@ return `{\n${properties}\n}`; | ||
| const output = [...definitions]; | ||
| return formatter_1.Formatter.Format(output.join('\n\n')); | ||
| return index_1.Formatter.Format(output.join('\n\n')); | ||
| } | ||
| ModelToTypeScript.Generate = Generate; | ||
| })(ModelToTypeScript || (exports.ModelToTypeScript = ModelToTypeScript = {})); |
+1
-1
| { | ||
| "name": "@sinclair/typebox-codegen", | ||
| "version": "0.10.0", | ||
| "version": "0.10.1", | ||
| "description": "Code Generation Tools for TypeBox", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
150380
-1.14%3270
-1.54%