ascertain 0.9.7 → 0.10.0
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 +2 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +21 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,6 +52,7 @@ const data = {
|
|
|
52
52
|
parsedBoolean: as.boolean('false'),
|
|
53
53
|
parsedArray: as.array('1,2,3,4,5', ','),
|
|
54
54
|
parsedJSON: as.json('{ "number": 1 }'),
|
|
55
|
+
parsedBase64: as.base64('dGVzdA=='),
|
|
55
56
|
};
|
|
56
57
|
|
|
57
58
|
// create data schema
|
|
@@ -82,6 +83,7 @@ const schema: Schema<typeof data> = {
|
|
|
82
83
|
parsedJSON: {
|
|
83
84
|
number: 1,
|
|
84
85
|
},
|
|
86
|
+
parsedBase64: String,
|
|
85
87
|
};
|
|
86
88
|
|
|
87
89
|
// validate
|
package/build/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ interface As {
|
|
|
18
18
|
boolean: (value: string | undefined) => boolean,
|
|
19
19
|
array: (value: string | undefined, delimiter: string | RegExp) => string[];
|
|
20
20
|
json: <T>(value: string | undefined) => T;
|
|
21
|
+
base64: (value: string | undefined) => string | undefined;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export const as: As;
|
package/build/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.or = exports.optional = exports.default = exports.ascertain = exports.as = exports.and = exports.$values = exports.$keys = void 0;
|
|
6
|
+
exports.toggle = exports.or = exports.optional = exports.default = exports.ascertain = exports.as = exports.and = exports.$values = exports.$keys = void 0;
|
|
7
7
|
|
|
8
8
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
9
9
|
|
|
@@ -106,6 +106,11 @@ var $keys = Symbol.for('@@keys');
|
|
|
106
106
|
exports.$keys = $keys;
|
|
107
107
|
var $values = Symbol.for('@@values');
|
|
108
108
|
exports.$values = $values;
|
|
109
|
+
var fromBase64 = typeof Buffer === 'undefined' ? function (value) {
|
|
110
|
+
return atob(value);
|
|
111
|
+
} : function (value) {
|
|
112
|
+
return Buffer.from(value, 'base64').toString('utf-8');
|
|
113
|
+
};
|
|
109
114
|
var as = {
|
|
110
115
|
number: function number(value) {
|
|
111
116
|
var result = parseFloat(value);
|
|
@@ -123,10 +128,25 @@ var as = {
|
|
|
123
128
|
} catch (e) {
|
|
124
129
|
return undefined;
|
|
125
130
|
}
|
|
131
|
+
},
|
|
132
|
+
base64: function base64(value) {
|
|
133
|
+
try {
|
|
134
|
+
return fromBase64(value);
|
|
135
|
+
} catch (e) {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
126
138
|
}
|
|
127
139
|
};
|
|
128
140
|
exports.as = as;
|
|
129
141
|
|
|
142
|
+
var toggle = function toggle(key, cases, defaultKey) {
|
|
143
|
+
var _ref, _cases$key;
|
|
144
|
+
|
|
145
|
+
return (_ref = (_cases$key = cases[key]) !== null && _cases$key !== void 0 ? _cases$key : cases[defaultKey]) !== null && _ref !== void 0 ? _ref : undefined;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
exports.toggle = toggle;
|
|
149
|
+
|
|
130
150
|
function certain(target, schema, path, optional) {
|
|
131
151
|
if (schema === null || typeof schema === 'undefined') {
|
|
132
152
|
return new AssertError(schema, 'any value', path, 'schema value');
|