gray-matter-es 0.1.0 → 0.1.2

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 (67) hide show
  1. package/README.md +70 -0
  2. package/dist/index.d.mts +90 -6
  3. package/dist/index.mjs +2299 -23
  4. package/package.json +1 -1
  5. package/src/index.ts +1 -0
  6. package/dist/defaults.mjs +0 -19
  7. package/dist/defaults.mjs.map +0 -1
  8. package/dist/engines.d.mts +0 -8
  9. package/dist/engines.mjs +0 -63
  10. package/dist/engines.mjs.map +0 -1
  11. package/dist/excerpt.mjs +0 -26
  12. package/dist/excerpt.mjs.map +0 -1
  13. package/dist/index.mjs.map +0 -1
  14. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_chars.mjs +0 -45
  15. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_chars.mjs.map +0 -1
  16. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_dumper_state.mjs +0 -437
  17. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_dumper_state.mjs.map +0 -1
  18. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_loader_state.mjs +0 -909
  19. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_loader_state.mjs.map +0 -1
  20. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_schema.mjs +0 -115
  21. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_schema.mjs.map +0 -1
  22. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/binary.mjs +0 -89
  23. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/binary.mjs.map +0 -1
  24. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/bool.mjs +0 -35
  25. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/bool.mjs.map +0 -1
  26. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/float.mjs +0 -55
  27. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/float.mjs.map +0 -1
  28. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/int.mjs +0 -114
  29. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/int.mjs.map +0 -1
  30. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/map.mjs +0 -15
  31. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/map.mjs.map +0 -1
  32. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/merge.mjs +0 -11
  33. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/merge.mjs.map +0 -1
  34. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/nil.mjs +0 -20
  35. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/nil.mjs.map +0 -1
  36. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/omap.mjs +0 -28
  37. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/omap.mjs.map +0 -1
  38. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/pairs.mjs +0 -19
  39. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/pairs.mjs.map +0 -1
  40. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/regexp.mjs +0 -26
  41. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/regexp.mjs.map +0 -1
  42. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/seq.mjs +0 -11
  43. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/seq.mjs.map +0 -1
  44. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/set.mjs +0 -14
  45. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/set.mjs.map +0 -1
  46. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/str.mjs +0 -11
  47. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/str.mjs.map +0 -1
  48. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/timestamp.mjs +0 -54
  49. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/timestamp.mjs.map +0 -1
  50. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/undefined.mjs +0 -19
  51. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_type/undefined.mjs.map +0 -1
  52. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_utils.mjs +0 -14
  53. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/_utils.mjs.map +0 -1
  54. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/mod.mjs +0 -4
  55. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/parse.mjs +0 -50
  56. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/parse.mjs.map +0 -1
  57. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/stringify.mjs +0 -32
  58. package/dist/node_modules/.pnpm/@jsr_std__yaml@1.0.10/node_modules/@jsr/std__yaml/stringify.mjs.map +0 -1
  59. package/dist/parse.mjs +0 -13
  60. package/dist/parse.mjs.map +0 -1
  61. package/dist/stringify.mjs +0 -52
  62. package/dist/stringify.mjs.map +0 -1
  63. package/dist/to-file.mjs +0 -44
  64. package/dist/to-file.mjs.map +0 -1
  65. package/dist/types.d.mts +0 -85
  66. package/dist/utils.mjs +0 -60
  67. package/dist/utils.mjs.map +0 -1
package/README.md CHANGED
@@ -1,5 +1,8 @@
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
@@ -21,6 +24,8 @@ pnpm add gray-matter-es
21
24
 
22
25
  ```typescript
23
26
  import matter from "gray-matter-es";
27
+ // or
28
+ import { matter } from "gray-matter-es";
24
29
 
25
30
  // Parse front matter
26
31
  const file = matter("---\ntitle: Hello\n---\nThis is content");
@@ -124,6 +129,71 @@ Detect the language specified after the opening delimiter.
124
129
  - Removed `section-matter` support
125
130
  - TypeScript-first with strict types
126
131
 
132
+ ## Migration from gray-matter
133
+
134
+ ### Import Changes
135
+
136
+ ```diff
137
+ - const matter = require('gray-matter');
138
+ + import matter from 'gray-matter-es';
139
+ + // or
140
+ + import { matter } from 'gray-matter-es';
141
+ ```
142
+
143
+ ### Removed Features
144
+
145
+ #### JavaScript Front Matter Engine
146
+
147
+ The JavaScript engine has been removed for security reasons (it used `eval`). If you were using JavaScript front matter:
148
+
149
+ ```markdown
150
+ ---js
151
+ {
152
+ title: "Hello",
153
+ date: new Date()
154
+ }
155
+ ---
156
+ ```
157
+
158
+ You'll need to either:
159
+
160
+ 1. Convert to YAML or JSON front matter
161
+ 2. Register a custom engine with your own parser
162
+
163
+ #### Deprecated Options
164
+
165
+ The following deprecated options have been removed:
166
+
167
+ | Removed Option | Replacement |
168
+ | -------------- | ------------ |
169
+ | `lang` | `language` |
170
+ | `delims` | `delimiters` |
171
+ | `parsers` | `engines` |
172
+
173
+ ```diff
174
+ - matter(str, { lang: 'json', delims: '~~~' });
175
+ + matter(str, { language: 'json', delimiters: '~~~' });
176
+ ```
177
+
178
+ #### Section Matter
179
+
180
+ If you were using `section-matter` functionality, you'll need to handle it separately.
181
+
182
+ ### YAML Parser Differences
183
+
184
+ This library uses `@std/yaml` instead of `js-yaml`. In most cases, this is a drop-in replacement, but there may be edge cases with non-standard YAML.
185
+
186
+ ### CommonJS Users
187
+
188
+ If you're using CommonJS, you'll need to either:
189
+
190
+ 1. Migrate to ESM
191
+ 2. Use dynamic import:
192
+
193
+ ```javascript
194
+ const matter = await import("gray-matter-es").then((m) => m.default);
195
+ ```
196
+
127
197
  ## License
128
198
 
129
199
  MIT
package/dist/index.d.mts CHANGED
@@ -1,12 +1,96 @@
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 Buffer */
47
+ orig: Buffer;
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
+ /** File path (set by matter.read) */
57
+ path?: string;
58
+ /** Stringify the file back to a string */
59
+ stringify: (data?: Record<string, unknown>, options?: GrayMatterOptions) => string;
60
+ }
61
+ /**
62
+ * Input that can be passed to gray-matter
63
+ */
64
+ type GrayMatterInput = string | Buffer | {
65
+ content: string;
66
+ data?: Record<string, unknown>;
67
+ };
68
+ /**
69
+ * The matter function interface with static methods
70
+ */
71
+ interface MatterFunction {
72
+ (input: GrayMatterInput, options?: GrayMatterOptions): GrayMatterFile;
73
+ stringify: (file: GrayMatterFile | string, data?: Record<string, unknown>, options?: GrayMatterOptions) => string;
74
+ read: (filepath: string, options?: GrayMatterOptions) => GrayMatterFile;
75
+ test: (str: string, options?: GrayMatterOptions) => boolean;
76
+ language: (str: string, options?: GrayMatterOptions) => {
77
+ raw: string;
78
+ name: string;
79
+ };
80
+ clearCache: () => void;
81
+ cache: Map<string, GrayMatterFile>;
82
+ }
83
+ //#endregion
84
+ //#region src/engines.d.ts
85
+ /**
86
+ * Built-in language names
87
+ */
88
+ type BuiltinLanguage = "yaml" | "json";
89
+ //#endregion
4
90
  //#region src/index.d.ts
5
-
6
91
  /**
7
92
  * The matter function with all static methods
8
93
  */
9
94
  declare const matter: MatterFunction;
10
95
  //#endregion
11
- export { type BuiltinLanguage, type Engine, type GrayMatterFile, type GrayMatterInput, type GrayMatterOptions, type MatterFunction, type ResolvedOptions, matter as default };
12
- //# sourceMappingURL=index.d.mts.map
96
+ export { type BuiltinLanguage, type Engine, type GrayMatterFile, type GrayMatterInput, type GrayMatterOptions, type MatterFunction, type ResolvedOptions, matter as default, matter };