lite-matter 0.0.1
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/.gitattributes +2 -0
- package/.github/workflows/publish.yml +32 -0
- package/LICENSE +21 -0
- package/README.md +85 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +25 -0
- package/package.json +44 -0
- package/src/index.ts +34 -0
- package/tsconfig.json +14 -0
package/.gitattributes
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: Publish to NPM
|
|
2
|
+
on:
|
|
3
|
+
release:
|
|
4
|
+
types: [published]
|
|
5
|
+
workflow_dispatch:
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
id-token: write
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
publish:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v6
|
|
16
|
+
|
|
17
|
+
- name: Setup Node.js
|
|
18
|
+
uses: actions/setup-node@v6
|
|
19
|
+
with:
|
|
20
|
+
node-version: '22'
|
|
21
|
+
registry-url: 'https://registry.npmjs.org'
|
|
22
|
+
|
|
23
|
+
- name: Install dependencies
|
|
24
|
+
run: npm install
|
|
25
|
+
|
|
26
|
+
- name: Build package
|
|
27
|
+
run: npm run build
|
|
28
|
+
|
|
29
|
+
- name: Publish to npm
|
|
30
|
+
run: npm publish --access public
|
|
31
|
+
env:
|
|
32
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present docmd.io
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# lite-matter
|
|
2
|
+
|
|
3
|
+
**The Minimalist, Zero-Bloat YAML Frontmatter Extractor for Modern JavaScript.**
|
|
4
|
+
|
|
5
|
+
`lite-matter` is a high-performance, single-pass frontmatter extraction engine. It provides the same metadata isolation interface as legacy libraries like `gray-matter` without the inclusion of heavy, non-standard dependencies or legacy string-handling wrappers.
|
|
6
|
+
|
|
7
|
+
## Technical Specifications
|
|
8
|
+
|
|
9
|
+
- **Runtime**: Node.js (ESM), Browser (Modern), Deno, Cloudflare Workers.
|
|
10
|
+
- **Language**: Core logic written in modern TypeScript.
|
|
11
|
+
- **Dependency**: Powered by the modern `yaml` parser for spec-compliant parsing.
|
|
12
|
+
- **Distribution**: Pure ES Module (ESM).
|
|
13
|
+
|
|
14
|
+
## The Problem: The Legacy Complexity Gap
|
|
15
|
+
|
|
16
|
+
Legacy libraries like `gray-matter` were built for an older era of the JavaScript ecosystem. They often include complex, non-standard frontmatter support (e.g., CoffeeScript, TOML, and CSV delimiters) and heavy string-processing logic that increases CPU and bundle overhead in modern static site generators and CMS engines.
|
|
17
|
+
|
|
18
|
+
`lite-matter` is a modern, laser-focused alternative. It is built strictly for the **standard triple-dash YAML frontmatter format** (the industry-standard across Markdown, GitHub, and major CMS architectures).
|
|
19
|
+
|
|
20
|
+
### Technical Limitations & Design Scope
|
|
21
|
+
|
|
22
|
+
To maintain its minimalism, `lite-matter` purposely restricts its feature set:
|
|
23
|
+
|
|
24
|
+
1. **Format Restriction**: Strictly supports YAML triple-dash (`---`) frontmatter. It does not support TOML (`+++`), CoffeeScript, or other legacy metadata formats found in `gray-matter`.
|
|
25
|
+
2. **No Delimiter Customization**: Delimiters are hardcoded to the industry-standard `---` to optimize regex isolation performance.
|
|
26
|
+
3. **Strict ESM**: Built specifically for modern ESM toolchains.
|
|
27
|
+
4. **No In-memory Cache**: For consistency, `lite-matter` performs a fresh parse on every invocation. If high-frequency parsing of the same file is required, results should be cached at the application layer.
|
|
28
|
+
|
|
29
|
+
* **Optimal Performance**: Uses a pinpoint regex scan to isolate the YAML block, passing it directly to the performance-optimized `yaml` library.
|
|
30
|
+
* **Reduced Footprint**: Does not bundle unnecessary non-standard parsers for legacy formats.
|
|
31
|
+
* **Secure & Robust**: Provides safe, fault-tolerant YAML parsing with clean error handling and graceful fallbacks.
|
|
32
|
+
* **Modern Support**: Written in TypeScript and exported as native ESM for a superior developer experience in modern toolchains.
|
|
33
|
+
* **Exact Drop-In Compatibility**: Supports the identical `matter(content)` API expected by millions of developers.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm install lite-matter
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Quick Start
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
import matter from 'lite-matter';
|
|
45
|
+
|
|
46
|
+
const markdown = `---
|
|
47
|
+
title: Understanding lite-matter
|
|
48
|
+
date: 2026-04-04
|
|
49
|
+
status: draft
|
|
50
|
+
---
|
|
51
|
+
# Content Start
|
|
52
|
+
This is the body of the markdown file.`;
|
|
53
|
+
|
|
54
|
+
const { data, content } = matter(markdown);
|
|
55
|
+
|
|
56
|
+
console.log(data);
|
|
57
|
+
// Output: { title: "Understanding lite-matter", date: "2026-04-04", status: "draft" }
|
|
58
|
+
|
|
59
|
+
console.log(content.trim());
|
|
60
|
+
// Output: "# Content Start\nThis is the body of the markdown file."
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Comparisons
|
|
64
|
+
|
|
65
|
+
| Feature | gray-matter | lite-matter |
|
|
66
|
+
| :--- | :--- | :--- |
|
|
67
|
+
| **Logic** | Multi-parser | **Pinpoint YAML** |
|
|
68
|
+
| **Parsing** | Bulky strings | **Single-pass scan** |
|
|
69
|
+
| **Standard** | Triple-dash (+++, TOML, etc.) | **Standard Triple-dash YAML** |
|
|
70
|
+
| **Weight (approx)**| ~100KB+ | **<1KB logic** |
|
|
71
|
+
|
|
72
|
+
## API Reference
|
|
73
|
+
|
|
74
|
+
### `matter(str)`
|
|
75
|
+
|
|
76
|
+
**Arguments:**
|
|
77
|
+
- `str` (string): The raw source string incorporating the frontmatter block.
|
|
78
|
+
|
|
79
|
+
**Returns:**
|
|
80
|
+
- `data` (object): A parsed JavaScript object from the YAML block.
|
|
81
|
+
- `content` (string): The remaining source string (stripped of frontmatter).
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
MIT - Developed under the docmd ecosystem by [Ghazi](https://mgks.dev).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface MatterResult {
|
|
2
|
+
data: Record<string, any>;
|
|
3
|
+
content: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Extracts and parses YAML frontmatter from a string.
|
|
7
|
+
* Mimics the API of `gray-matter` for easy drop-in replacement.
|
|
8
|
+
*/
|
|
9
|
+
export declare function matter(str: string): MatterResult;
|
|
10
|
+
export default matter;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { parse } from 'yaml';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts and parses YAML frontmatter from a string.
|
|
4
|
+
* Mimics the API of `gray-matter` for easy drop-in replacement.
|
|
5
|
+
*/
|
|
6
|
+
export function matter(str) {
|
|
7
|
+
// Regex matches frontmatter bounded by --- only at the very start of the string
|
|
8
|
+
const regex = /^(?:---[\r\n]+)([\s\S]*?)(?:[\r\n]+---(?:[\r\n]+|$))/;
|
|
9
|
+
const match = str.match(regex);
|
|
10
|
+
if (!match) {
|
|
11
|
+
return { data: {}, content: str };
|
|
12
|
+
}
|
|
13
|
+
const yamlStr = match[1];
|
|
14
|
+
const content = str.slice(match[0].length);
|
|
15
|
+
try {
|
|
16
|
+
const data = parse(yamlStr) || {};
|
|
17
|
+
return { data, content };
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
// Return empty data but successfully parse the rest of the text if YAML fails
|
|
21
|
+
return { data: {}, content: str };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// Fallback default export for total compatibility
|
|
25
|
+
export default matter;
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lite-matter",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Ultra lightweight, zero-bloat frontmatter extractor.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"yaml": "^2.4.2"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"typescript": "^5.0.0"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"frontmatter",
|
|
19
|
+
"gray-matter",
|
|
20
|
+
"yaml",
|
|
21
|
+
"markdown",
|
|
22
|
+
"minimal",
|
|
23
|
+
"typescript",
|
|
24
|
+
"javascript",
|
|
25
|
+
"nodejs",
|
|
26
|
+
"browser",
|
|
27
|
+
"docmd"
|
|
28
|
+
],
|
|
29
|
+
"author": {
|
|
30
|
+
"name": "Ghazi",
|
|
31
|
+
"url": "https://mgks.dev"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/docmd-io/docmd.git",
|
|
36
|
+
"directory": "lite-matter"
|
|
37
|
+
},
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/docmd-io/docmd/issues"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://docmd.io",
|
|
42
|
+
"funding": "https://github.com/sponsors/mgks",
|
|
43
|
+
"license": "MIT"
|
|
44
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { parse } from 'yaml';
|
|
2
|
+
|
|
3
|
+
export interface MatterResult {
|
|
4
|
+
data: Record<string, any>;
|
|
5
|
+
content: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Extracts and parses YAML frontmatter from a string.
|
|
10
|
+
* Mimics the API of `gray-matter` for easy drop-in replacement.
|
|
11
|
+
*/
|
|
12
|
+
export function matter(str: string): MatterResult {
|
|
13
|
+
// Regex matches frontmatter bounded by --- only at the very start of the string
|
|
14
|
+
const regex = /^(?:---[\r\n]+)([\s\S]*?)(?:[\r\n]+---(?:[\r\n]+|$))/;
|
|
15
|
+
const match = str.match(regex);
|
|
16
|
+
|
|
17
|
+
if (!match) {
|
|
18
|
+
return { data: {}, content: str };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const yamlStr = match[1];
|
|
22
|
+
const content = str.slice(match[0].length);
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const data = parse(yamlStr) || {};
|
|
26
|
+
return { data, content };
|
|
27
|
+
} catch (err) {
|
|
28
|
+
// Return empty data but successfully parse the rest of the text if YAML fails
|
|
29
|
+
return { data: {}, content: str };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Fallback default export for total compatibility
|
|
34
|
+
export default matter;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "Node16",
|
|
5
|
+
"moduleResolution": "node16",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"outDir": "dist",
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"skipLibCheck": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src/**/*"]
|
|
14
|
+
}
|