@cronn/lib-file-snapshots 0.12.0 → 0.13.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 +7 -0
- package/dist/index.js +13 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -30,6 +30,12 @@ interface JsonSerializerOptions {
|
|
|
30
30
|
* Custom normalizers to apply before serialization
|
|
31
31
|
*/
|
|
32
32
|
normalizers?: Array<JsonNormalizer>;
|
|
33
|
+
/**
|
|
34
|
+
* Indentation size in spaces
|
|
35
|
+
*
|
|
36
|
+
* @default 2
|
|
37
|
+
*/
|
|
38
|
+
indentSize?: number;
|
|
33
39
|
}
|
|
34
40
|
type JsonNormalizer = (value: unknown, context: JsonNormalizerContext) => unknown;
|
|
35
41
|
interface JsonNormalizerContext {
|
|
@@ -40,6 +46,7 @@ declare class JsonSerializer implements SnapshotSerializer {
|
|
|
40
46
|
readonly fileExtension = "json";
|
|
41
47
|
private readonly includeUndefinedObjectProperties;
|
|
42
48
|
private readonly normalizers;
|
|
49
|
+
private readonly indentSize;
|
|
43
50
|
constructor(options?: JsonSerializerOptions);
|
|
44
51
|
canSerialize(_value: unknown): boolean;
|
|
45
52
|
serialize(value: unknown): string;
|
package/dist/index.js
CHANGED
|
@@ -41,21 +41,33 @@ function isPlainObject(value) {
|
|
|
41
41
|
return proto === null || proto === Object.prototype;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
// src/utils/validators.ts
|
|
45
|
+
function isPositiveInteger(value) {
|
|
46
|
+
return Number.isInteger(value) && value > 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
44
49
|
// src/serializers/json-serializer.ts
|
|
45
50
|
var JsonSerializer = class {
|
|
46
51
|
fileExtension = "json";
|
|
47
52
|
includeUndefinedObjectProperties;
|
|
48
53
|
normalizers;
|
|
54
|
+
indentSize;
|
|
49
55
|
constructor(options = {}) {
|
|
56
|
+
if (options.indentSize !== void 0 && !isPositiveInteger(options.indentSize)) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
"Invalid option indentSize: value must be a positive integer."
|
|
59
|
+
);
|
|
60
|
+
}
|
|
50
61
|
this.includeUndefinedObjectProperties = options.includeUndefinedObjectProperties ?? false;
|
|
51
62
|
this.normalizers = options.normalizers ?? [];
|
|
63
|
+
this.indentSize = options.indentSize ?? 2;
|
|
52
64
|
}
|
|
53
65
|
canSerialize(_value) {
|
|
54
66
|
return true;
|
|
55
67
|
}
|
|
56
68
|
serialize(value) {
|
|
57
69
|
const jsonValue = this.normalizeValueRecursive(value);
|
|
58
|
-
const jsonString = JSON.stringify(jsonValue, void 0,
|
|
70
|
+
const jsonString = JSON.stringify(jsonValue, void 0, this.indentSize);
|
|
59
71
|
return addTrailingNewLine(jsonString);
|
|
60
72
|
}
|
|
61
73
|
normalizeValueRecursive(value, context) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cronn/lib-file-snapshots",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "The library agnostic core for testing file snapshots",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"file snapshots"
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
],
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@trivago/prettier-plugin-sort-imports": "5.2.2",
|
|
36
|
-
"@types/node": "22.
|
|
36
|
+
"@types/node": "22.17.1",
|
|
37
37
|
"@vitest/coverage-istanbul": "3.2.4",
|
|
38
38
|
"eslint": "9.32.0",
|
|
39
39
|
"eslint-config-prettier": "10.1.8",
|