@cronn/lib-file-snapshots 0.15.0 → 0.17.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 CHANGED
@@ -67,10 +67,16 @@ interface TextSerializerOptions {
67
67
  * Custom normalizers to apply before serialization
68
68
  */
69
69
  normalizers?: Array<TextNormalizer>;
70
+ /**
71
+ * File extension used for storing the text file
72
+ *
73
+ * @default "txt"
74
+ */
75
+ fileExtension?: string;
70
76
  }
71
77
  type TextNormalizer = (value: string) => string;
72
78
  declare class TextSerializer implements SnapshotSerializer {
73
- readonly fileExtension = "txt";
79
+ readonly fileExtension: string;
74
80
  private readonly normalizers;
75
81
  constructor(options?: TextSerializerOptions);
76
82
  canSerialize(value: unknown): value is string;
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // src/utils/file.ts
2
2
  import fs from "fs";
3
+ import os from "os";
3
4
  import path from "path";
4
5
  var NEW_LINE_SEPARATOR = "\n";
5
6
  var EMOJI_REGEXP = /(?!(\*|#|\d))[\p{Extended_Pictographic}\p{Emoji_Component}]|[\u0030-\u0039]\ufe0f?[\u20e3]|[\u002A\u0023]?\ufe0f?[\u20e3]/gu;
@@ -7,7 +8,11 @@ function normalizeFileName(testName) {
7
8
  return testName.replaceAll(EMOJI_REGEXP, "").replaceAll(/[+*%~<>?!$#'"`|\\/()[\]{}]/g, "").replaceAll(/[\s.:,;]+/g, "_").replaceAll(/_{2,}/g, "_");
8
9
  }
9
10
  function readSnapshotFile(path4) {
10
- return fs.readFileSync(path4, { encoding: "utf8" });
11
+ const contents = fs.readFileSync(path4, { encoding: "utf8" });
12
+ if (os.EOL === NEW_LINE_SEPARATOR) {
13
+ return contents;
14
+ }
15
+ return contents.replace(new RegExp(os.EOL, "g"), NEW_LINE_SEPARATOR);
11
16
  }
12
17
  function writeSnapshotFile(file, data) {
13
18
  mkdirRecursive(path.dirname(file));
@@ -214,10 +219,11 @@ var JsonSerializer = class {
214
219
 
215
220
  // src/serializers/text-serializer.ts
216
221
  var TextSerializer = class {
217
- fileExtension = "txt";
222
+ fileExtension;
218
223
  normalizers;
219
224
  constructor(options = {}) {
220
225
  this.normalizers = options.normalizers ?? [];
226
+ this.fileExtension = options.fileExtension ?? "txt";
221
227
  }
222
228
  canSerialize(value) {
223
229
  return isString(value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cronn/lib-file-snapshots",
3
- "version": "0.15.0",
3
+ "version": "0.17.0",
4
4
  "description": "The library agnostic core for testing file snapshots",
5
5
  "keywords": [
6
6
  "file snapshots"
@@ -33,15 +33,15 @@
33
33
  ],
34
34
  "devDependencies": {
35
35
  "@trivago/prettier-plugin-sort-imports": "5.2.2",
36
- "@types/node": "22.18.1",
36
+ "@types/node": "22.18.11",
37
37
  "@vitest/coverage-istanbul": "3.2.4",
38
- "eslint": "9.35.0",
38
+ "eslint": "9.38.0",
39
39
  "eslint-config-prettier": "10.1.8",
40
- "eslint-plugin-unused-imports": "4.2.0",
40
+ "eslint-plugin-unused-imports": "4.3.0",
41
41
  "prettier": "3.6.2",
42
42
  "tsup": "8.5.0",
43
- "typescript": "5.9.2",
44
- "typescript-eslint": "8.42.0",
43
+ "typescript": "5.9.3",
44
+ "typescript-eslint": "8.46.1",
45
45
  "vitest": "3.2.4",
46
46
  "@cronn/shared-configs": "0.0.0"
47
47
  },