@sinclair/typebox 0.26.3 → 0.26.4
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/compiler/compiler.d.ts +0 -3
- package/compiler/compiler.js +39 -37
- package/package.json +1 -1
package/compiler/compiler.d.ts
CHANGED
|
@@ -14,9 +14,6 @@ export declare class TypeCheck<T extends Types.TSchema> {
|
|
|
14
14
|
/** Returns true if the value matches the compiled type. */
|
|
15
15
|
Check(value: unknown): value is Types.Static<T>;
|
|
16
16
|
}
|
|
17
|
-
export declare namespace MemberExpression {
|
|
18
|
-
function Encode(object: string, key: string): string;
|
|
19
|
-
}
|
|
20
17
|
export declare class TypeCompilerUnknownTypeError extends Error {
|
|
21
18
|
readonly schema: Types.TSchema;
|
|
22
19
|
constructor(schema: Types.TSchema);
|
package/compiler/compiler.js
CHANGED
|
@@ -27,7 +27,7 @@ THE SOFTWARE.
|
|
|
27
27
|
|
|
28
28
|
---------------------------------------------------------------------------*/
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.TypeCompiler = exports.TypeCompilerTypeGuardError = exports.TypeCompilerDereferenceError = exports.TypeCompilerUnknownTypeError = exports.
|
|
30
|
+
exports.TypeCompiler = exports.TypeCompilerTypeGuardError = exports.TypeCompilerDereferenceError = exports.TypeCompilerUnknownTypeError = exports.TypeCheck = void 0;
|
|
31
31
|
const Types = require("../typebox");
|
|
32
32
|
const index_1 = require("../errors/index");
|
|
33
33
|
const index_2 = require("../system/index");
|
|
@@ -65,20 +65,49 @@ var Character;
|
|
|
65
65
|
return code === 36;
|
|
66
66
|
}
|
|
67
67
|
Character.DollarSign = DollarSign;
|
|
68
|
-
function
|
|
68
|
+
function IsUnderscore(code) {
|
|
69
69
|
return code === 95;
|
|
70
70
|
}
|
|
71
|
-
Character.
|
|
72
|
-
function
|
|
73
|
-
return code >=
|
|
71
|
+
Character.IsUnderscore = IsUnderscore;
|
|
72
|
+
function IsAlpha(code) {
|
|
73
|
+
return (code >= 64 && code <= 90) || (code >= 97 && code <= 122);
|
|
74
74
|
}
|
|
75
|
-
Character.
|
|
76
|
-
function
|
|
77
|
-
return
|
|
75
|
+
Character.IsAlpha = IsAlpha;
|
|
76
|
+
function IsNumeric(code) {
|
|
77
|
+
return code >= 48 && code <= 57;
|
|
78
78
|
}
|
|
79
|
-
Character.
|
|
79
|
+
Character.IsNumeric = IsNumeric;
|
|
80
80
|
})(Character || (Character = {}));
|
|
81
81
|
// -------------------------------------------------------------------
|
|
82
|
+
// MemberExpression
|
|
83
|
+
// -------------------------------------------------------------------
|
|
84
|
+
var MemberExpression;
|
|
85
|
+
(function (MemberExpression) {
|
|
86
|
+
function IsFirstCharacterNumeric(value) {
|
|
87
|
+
if (value.length === 0)
|
|
88
|
+
return false;
|
|
89
|
+
return Character.IsNumeric(value.charCodeAt(0));
|
|
90
|
+
}
|
|
91
|
+
function IsAccessor(value) {
|
|
92
|
+
if (IsFirstCharacterNumeric(value))
|
|
93
|
+
return false;
|
|
94
|
+
for (let i = 0; i < value.length; i++) {
|
|
95
|
+
const code = value.charCodeAt(i);
|
|
96
|
+
const check = Character.IsAlpha(code) || Character.IsNumeric(code) || Character.DollarSign(code) || Character.IsUnderscore(code);
|
|
97
|
+
if (!check)
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
function EscapeHyphen(key) {
|
|
103
|
+
return key.replace(/'/g, "\\'");
|
|
104
|
+
}
|
|
105
|
+
function Encode(object, key) {
|
|
106
|
+
return IsAccessor(key) ? `${object}.${key}` : `${object}['${EscapeHyphen(key)}']`;
|
|
107
|
+
}
|
|
108
|
+
MemberExpression.Encode = Encode;
|
|
109
|
+
})(MemberExpression || (MemberExpression = {}));
|
|
110
|
+
// -------------------------------------------------------------------
|
|
82
111
|
// Identifier
|
|
83
112
|
// -------------------------------------------------------------------
|
|
84
113
|
var Identifier;
|
|
@@ -87,7 +116,7 @@ var Identifier;
|
|
|
87
116
|
const buffer = [];
|
|
88
117
|
for (let i = 0; i < $id.length; i++) {
|
|
89
118
|
const code = $id.charCodeAt(i);
|
|
90
|
-
if (Character.
|
|
119
|
+
if (Character.IsNumeric(code) || Character.IsAlpha(code)) {
|
|
91
120
|
buffer.push($id.charAt(i));
|
|
92
121
|
}
|
|
93
122
|
else {
|
|
@@ -99,33 +128,6 @@ var Identifier;
|
|
|
99
128
|
Identifier.Encode = Encode;
|
|
100
129
|
})(Identifier || (Identifier = {}));
|
|
101
130
|
// -------------------------------------------------------------------
|
|
102
|
-
// MemberExpression
|
|
103
|
-
// -------------------------------------------------------------------
|
|
104
|
-
var MemberExpression;
|
|
105
|
-
(function (MemberExpression) {
|
|
106
|
-
function Check(propertyName) {
|
|
107
|
-
if (propertyName.length === 0)
|
|
108
|
-
return false;
|
|
109
|
-
{
|
|
110
|
-
const code = propertyName.charCodeAt(0);
|
|
111
|
-
if (!(Character.DollarSign(code) || Character.Underscore(code) || Character.Alpha(code))) {
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
for (let i = 1; i < propertyName.length; i++) {
|
|
116
|
-
const code = propertyName.charCodeAt(i);
|
|
117
|
-
if (!(Character.DollarSign(code) || Character.Underscore(code) || Character.Alpha(code) || Character.Numeric(code))) {
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return true;
|
|
122
|
-
}
|
|
123
|
-
function Encode(object, key) {
|
|
124
|
-
return !Check(key) ? `${object}['${key}']` : `${object}.${key}`;
|
|
125
|
-
}
|
|
126
|
-
MemberExpression.Encode = Encode;
|
|
127
|
-
})(MemberExpression = exports.MemberExpression || (exports.MemberExpression = {}));
|
|
128
|
-
// -------------------------------------------------------------------
|
|
129
131
|
// TypeCompiler
|
|
130
132
|
// -------------------------------------------------------------------
|
|
131
133
|
class TypeCompilerUnknownTypeError extends Error {
|