gray-matter-es 0.1.1 → 0.1.3

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.
Files changed (72) hide show
  1. package/README.md +9 -10
  2. package/dist/index.d.mts +87 -6
  3. package/dist/index.mjs +2299 -29
  4. package/package.json +1 -1
  5. package/src/excerpt.ts +1 -2
  6. package/src/index.ts +5 -17
  7. package/src/stringify.ts +7 -7
  8. package/src/to-file.ts +23 -25
  9. package/src/types.ts +6 -6
  10. package/src/utils.ts +21 -18
  11. package/dist/defaults.mjs +0 -19
  12. package/dist/defaults.mjs.map +0 -1
  13. package/dist/engines.d.mts +0 -8
  14. package/dist/engines.mjs +0 -63
  15. package/dist/engines.mjs.map +0 -1
  16. package/dist/excerpt.mjs +0 -26
  17. package/dist/excerpt.mjs.map +0 -1
  18. package/dist/index.mjs.map +0 -1
  19. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_chars.mjs +0 -45
  20. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_chars.mjs.map +0 -1
  21. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_dumper_state.mjs +0 -437
  22. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_dumper_state.mjs.map +0 -1
  23. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_loader_state.mjs +0 -909
  24. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_loader_state.mjs.map +0 -1
  25. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_schema.mjs +0 -115
  26. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_schema.mjs.map +0 -1
  27. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/binary.mjs +0 -89
  28. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/binary.mjs.map +0 -1
  29. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/bool.mjs +0 -35
  30. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/bool.mjs.map +0 -1
  31. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/float.mjs +0 -55
  32. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/float.mjs.map +0 -1
  33. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/int.mjs +0 -114
  34. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/int.mjs.map +0 -1
  35. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/map.mjs +0 -15
  36. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/map.mjs.map +0 -1
  37. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/merge.mjs +0 -11
  38. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/merge.mjs.map +0 -1
  39. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/nil.mjs +0 -20
  40. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/nil.mjs.map +0 -1
  41. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/omap.mjs +0 -28
  42. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/omap.mjs.map +0 -1
  43. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/pairs.mjs +0 -19
  44. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/pairs.mjs.map +0 -1
  45. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/regexp.mjs +0 -26
  46. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/regexp.mjs.map +0 -1
  47. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/seq.mjs +0 -11
  48. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/seq.mjs.map +0 -1
  49. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/set.mjs +0 -14
  50. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/set.mjs.map +0 -1
  51. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/str.mjs +0 -11
  52. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/str.mjs.map +0 -1
  53. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/timestamp.mjs +0 -54
  54. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/timestamp.mjs.map +0 -1
  55. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/undefined.mjs +0 -19
  56. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/undefined.mjs.map +0 -1
  57. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_utils.mjs +0 -14
  58. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_utils.mjs.map +0 -1
  59. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/mod.mjs +0 -4
  60. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/parse.mjs +0 -50
  61. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/parse.mjs.map +0 -1
  62. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/stringify.mjs +0 -32
  63. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/stringify.mjs.map +0 -1
  64. package/dist/parse.mjs +0 -13
  65. package/dist/parse.mjs.map +0 -1
  66. package/dist/stringify.mjs +0 -52
  67. package/dist/stringify.mjs.map +0 -1
  68. package/dist/to-file.mjs +0 -44
  69. package/dist/to-file.mjs.map +0 -1
  70. package/dist/types.d.mts +0 -85
  71. package/dist/utils.mjs +0 -60
  72. package/dist/utils.mjs.map +0 -1
package/README.md CHANGED
@@ -1,10 +1,14 @@
1
1
  # gray-matter-es
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/gray-matter-es?color=yellow)](https://npmjs.com/package/gray-matter-es)
4
+ [![npm downloads](https://img.shields.io/npm/dm/gray-matter-es?color=yellow)](https://npmjs.com/package/gray-matter-es)
5
+
3
6
  ESM-only [gray-matter](https://github.com/jonschlinkert/gray-matter) implementation.
4
7
 
5
8
  ## Features
6
9
 
7
10
  - 🚀 ESM-only, no CommonJS
11
+ - 🌐 Browser-compatible (no Node.js dependencies)
8
12
  - 📦 Zero runtime dependencies (YAML parser bundled from [@std/yaml](https://jsr.io/@std/yaml))
9
13
  - 🔷 Full TypeScript support with strict types
10
14
  - ✅ API compatible with gray-matter
@@ -36,9 +40,6 @@ const str = matter.stringify("content", { title: "Hello" });
36
40
  // ---
37
41
  // content
38
42
 
39
- // Read from file (Node.js)
40
- const fileFromDisk = matter.read("./post.md");
41
-
42
43
  // Test if string has front matter
43
44
  matter.test("---\ntitle: Hello\n---"); // true
44
45
 
@@ -75,11 +76,11 @@ console.log(file.excerpt); // 'excerpt\n'
75
76
 
76
77
  ### `matter(input, options?)`
77
78
 
78
- Parse front matter from a string or buffer.
79
+ Parse front matter from a string or Uint8Array.
79
80
 
80
81
  **Parameters:**
81
82
 
82
- - `input` - String, Buffer, or object with `content` property
83
+ - `input` - String, Uint8Array, or object with `content` property
83
84
  - `options` - Optional configuration
84
85
 
85
86
  **Returns:** `GrayMatterFile` object with:
@@ -87,7 +88,7 @@ Parse front matter from a string or buffer.
87
88
  - `data` - Parsed front matter data
88
89
  - `content` - Content after front matter
89
90
  - `excerpt` - Extracted excerpt (if enabled)
90
- - `orig` - Original input as Buffer
91
+ - `orig` - Original input as Uint8Array
91
92
  - `language` - Detected/specified language
92
93
  - `matter` - Raw front matter string
93
94
  - `isEmpty` - True if front matter block was empty
@@ -97,10 +98,6 @@ Parse front matter from a string or buffer.
97
98
 
98
99
  Stringify data to front matter and append content.
99
100
 
100
- ### `matter.read(filepath, options?)`
101
-
102
- Synchronously read and parse a file.
103
-
104
101
  ### `matter.test(str, options?)`
105
102
 
106
103
  Test if a string has front matter.
@@ -120,7 +117,9 @@ Detect the language specified after the opening delimiter.
120
117
  ## Differences from gray-matter
121
118
 
122
119
  - ESM-only (no CommonJS support)
120
+ - Browser-compatible (no Node.js dependencies)
123
121
  - Uses [`@std/yaml`](https://jsr.io/@std/yaml) instead of `js-yaml`
122
+ - Removed `matter.read()` (use your own file reading)
124
123
  - Removed JavaScript front matter engine (security: avoids `eval`)
125
124
  - Removed deprecated options (`lang`, `delims`, `parsers`)
126
125
  - Removed `section-matter` support
package/dist/index.d.mts CHANGED
@@ -1,12 +1,93 @@
1
- import { Engine, GrayMatterFile, GrayMatterInput, GrayMatterOptions, MatterFunction, ResolvedOptions } from "./types.mjs";
2
- import { BuiltinLanguage } from "./engines.mjs";
3
-
1
+ //#region src/types.d.ts
2
+ /**
3
+ * Engine interface for parsing and stringifying front matter
4
+ */
5
+ interface Engine {
6
+ parse: (str: string) => Record<string, unknown>;
7
+ stringify?: (data: Record<string, unknown>) => string;
8
+ }
9
+ /**
10
+ * Options for gray-matter
11
+ */
12
+ interface GrayMatterOptions {
13
+ /** Language to use for parsing (default: 'yaml') */
14
+ language?: "yaml" | "json";
15
+ /** Delimiters for front matter (default: '---') */
16
+ delimiters?: string | [string, string];
17
+ /**
18
+ * Extract an excerpt from the content.
19
+ * - `true`: use the default delimiter
20
+ * - `string`: use this string as the delimiter
21
+ * - `function`: custom excerpt function
22
+ */
23
+ excerpt?: boolean | string | ((file: GrayMatterFile, options: GrayMatterOptions) => void);
24
+ /** Separator for excerpt in file.data */
25
+ excerpt_separator?: string;
26
+ /** Data to merge with parsed data */
27
+ data?: Record<string, unknown>;
28
+ }
29
+ /**
30
+ * Resolved options with defaults applied
31
+ */
32
+ interface ResolvedOptions extends GrayMatterOptions {
33
+ delimiters: [string, string];
34
+ language: "yaml" | "json";
35
+ }
36
+ /**
37
+ * The file object returned by gray-matter
38
+ */
39
+ interface GrayMatterFile {
40
+ /** The parsed front matter data */
41
+ data: Record<string, unknown>;
42
+ /** The content after front matter */
43
+ content: string;
44
+ /** The extracted excerpt (if enabled) */
45
+ excerpt: string;
46
+ /** The original input as a Uint8Array */
47
+ orig: Uint8Array;
48
+ /** The detected/specified language */
49
+ language: string;
50
+ /** The raw front matter string (without delimiters) */
51
+ matter: string;
52
+ /** True if front matter block was empty */
53
+ isEmpty: boolean;
54
+ /** The original content if isEmpty is true */
55
+ empty?: string;
56
+ /** Stringify the file back to a string */
57
+ stringify: (data?: Record<string, unknown>, options?: GrayMatterOptions) => string;
58
+ }
59
+ /**
60
+ * Input that can be passed to gray-matter
61
+ */
62
+ type GrayMatterInput = string | Uint8Array | {
63
+ content: string;
64
+ data?: Record<string, unknown>;
65
+ };
66
+ /**
67
+ * The matter function interface with static methods
68
+ */
69
+ interface MatterFunction {
70
+ (input: GrayMatterInput, options?: GrayMatterOptions): GrayMatterFile;
71
+ stringify: (file: GrayMatterFile | string, data?: Record<string, unknown>, options?: GrayMatterOptions) => string;
72
+ test: (str: string, options?: GrayMatterOptions) => boolean;
73
+ language: (str: string, options?: GrayMatterOptions) => {
74
+ raw: string;
75
+ name: string;
76
+ };
77
+ clearCache: () => void;
78
+ cache: Map<string, GrayMatterFile>;
79
+ }
80
+ //#endregion
81
+ //#region src/engines.d.ts
82
+ /**
83
+ * Built-in language names
84
+ */
85
+ type BuiltinLanguage = "yaml" | "json";
86
+ //#endregion
4
87
  //#region src/index.d.ts
5
-
6
88
  /**
7
89
  * The matter function with all static methods
8
90
  */
9
91
  declare const matter: MatterFunction;
10
92
  //#endregion
11
- export { type BuiltinLanguage, type Engine, type GrayMatterFile, type GrayMatterInput, type GrayMatterOptions, type MatterFunction, type ResolvedOptions, matter as default, matter };
12
- //# sourceMappingURL=index.d.mts.map
93
+ export { type BuiltinLanguage, type Engine, type GrayMatterFile, type GrayMatterInput, type GrayMatterOptions, type MatterFunction, type ResolvedOptions, matter as default, matter };