@cronn/lib-file-snapshots 0.5.0 → 0.6.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/dist/index.d.ts +6 -1
- package/dist/index.js +10 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -128,4 +128,9 @@ declare class ValidationFileMatcher {
|
|
|
128
128
|
private writeFileSnapshots;
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
declare function isString(value: unknown): value is string;
|
|
132
|
+
declare function isArray(value: unknown): value is unknown[];
|
|
133
|
+
type PlainObject = Record<PropertyKey, unknown>;
|
|
134
|
+
declare function isPlainObject(value: unknown): value is PlainObject;
|
|
135
|
+
|
|
136
|
+
export { type JsonNormalizer, type JsonNormalizerContext, JsonSerializer, type PlainObject, type SnapshotSerializer, type TextNormalizer, TextSerializer, ValidationFileMatcher, isArray, isPlainObject, isString };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
// src/utils/guards.ts
|
|
2
|
+
function isString(value) {
|
|
3
|
+
return typeof value === "string";
|
|
4
|
+
}
|
|
2
5
|
function isArray(value) {
|
|
3
6
|
return Array.isArray(value);
|
|
4
7
|
}
|
|
@@ -37,7 +40,7 @@ var JsonSerializer = class {
|
|
|
37
40
|
if (customValue === void 0) {
|
|
38
41
|
return this.serializedValue("undefined");
|
|
39
42
|
}
|
|
40
|
-
if (customValue === null ||
|
|
43
|
+
if (customValue === null || isString(customValue) || typeof customValue === "boolean") {
|
|
41
44
|
const isRoot = context === void 0;
|
|
42
45
|
return isRoot ? this.serializedValue(typeof customValue, {
|
|
43
46
|
value: customValue
|
|
@@ -161,7 +164,7 @@ var JsonSerializer = class {
|
|
|
161
164
|
return { $type: type, ...additionalProps };
|
|
162
165
|
}
|
|
163
166
|
assertKeyType(key) {
|
|
164
|
-
if (!(
|
|
167
|
+
if (!isString(key)) {
|
|
165
168
|
throw new Error(`Key of type ${typeof key} cannot be normalized.`);
|
|
166
169
|
}
|
|
167
170
|
}
|
|
@@ -181,7 +184,7 @@ var TextSerializer = class {
|
|
|
181
184
|
this.normalizers = options.normalizers ?? [];
|
|
182
185
|
}
|
|
183
186
|
canSerialize(value) {
|
|
184
|
-
return
|
|
187
|
+
return isString(value);
|
|
185
188
|
}
|
|
186
189
|
serialize(value) {
|
|
187
190
|
if (!this.canSerialize(value)) {
|
|
@@ -292,5 +295,8 @@ does not match validation file '${validationFile}'`
|
|
|
292
295
|
export {
|
|
293
296
|
JsonSerializer,
|
|
294
297
|
TextSerializer,
|
|
295
|
-
ValidationFileMatcher
|
|
298
|
+
ValidationFileMatcher,
|
|
299
|
+
isArray,
|
|
300
|
+
isPlainObject,
|
|
301
|
+
isString
|
|
296
302
|
};
|