10 Commits

11 changed files with 4226 additions and 5688 deletions
+43
View File
@@ -0,0 +1,43 @@
{
"@git.zone/cli": {
"projectType": "npm",
"module": {
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartfm",
"shortDescription": "frontmatter parser utilities",
"description": "A Node.js module for handling and processing frontmatter in markdown and text files, leveraging the gray-matter library for parsing and stringifying YAML or JSON formatted frontmatter.",
"npmPackagename": "@push.rocks/smartfm",
"license": "MIT",
"keywords": [
"frontmatter",
"markdown",
"text files",
"YAML",
"JSON",
"stringify",
"parse",
"commented sections",
"static site generator",
"CMS",
"content metadata",
"metadata management",
"gray-matter"
]
},
"release": {
"registries": [
"https://verdaccio.lossless.digital",
"https://registry.npmjs.org"
],
"accessLevel": "public"
}
},
"@git.zone/tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
},
"@ship.zone/szci": {
"npmGlobalTools": [],
"npmRegistryUrl": "registry.npmjs.org"
}
}
+33
View File
@@ -1,5 +1,38 @@
# Changelog # Changelog
## 2026-05-01 - 2.2.3 - fix(build)
modernize project configuration and test setup for current toolchain compatibility
- migrate npmextra metadata to scoped tool configuration and add .smartconfig.json
- update build, test, and formatting scripts alongside TypeScript compiler settings
- refresh development dependencies and gray-matter patch version
- rename the test entrypoint to test.node.ts and align imports with the new tstest tapbundle path
- add explicit return and parameter types to Smartfm methods to satisfy stricter TypeScript settings
## 2025-01-24 - 2.2.2 - fix(package)
Fix export path in package.json
- Corrected the export path from './dist/index.js' to './dist_ts/index.js' in package.json
## 2025-01-24 - 2.2.1 - fix(documentation)
Remove unnecessary markdown syntax from the README.
- Fixed minor formatting issue in the README file by removing extraneous markdown syntax.
## 2025-01-24 - 2.2.0 - feat(core)
Initial release of smartfm module for handling frontmatter
- Added Smartfm class to handle YAML and JSON frontmatter
- Implemented methods for parsing and stringifying frontmatter
- Included support for parseFromComments to handle commented out frontmatter
## 2025-01-24 - 2.1.2 - fix(documentation)
Updated readme.md to add comprehensive examples and advanced use cases.
- Added examples for initializing the Smartfm class with YAML and JSON frontmatter.
- Included detailed usage examples for parsing and stringifying frontmatter.
- Added complex scenarios and advanced use cases like using the module with static site generators and frontmatter validation.
## 2025-01-24 - 2.1.1 - fix(documentation) ## 2025-01-24 - 2.1.1 - fix(documentation)
Improved and updated README with detailed usage instructions Improved and updated README with detailed usage instructions
+19
View File
@@ -0,0 +1,19 @@
Copyright (c) 2026 Task Venture Capital GmbH <hello@task.vc>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+15 -7
View File
@@ -1,14 +1,11 @@
{ {
"npmci": { "@git.zone/cli": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"gitzone": {
"projectType": "npm", "projectType": "npm",
"module": { "module": {
"githost": "code.foss.global", "githost": "code.foss.global",
"gitscope": "push.rocks", "gitscope": "push.rocks",
"gitrepo": "smartfm", "gitrepo": "smartfm",
"shortDescription": "frontmatter parser utilities",
"description": "A Node.js module for handling and processing frontmatter in markdown and text files, leveraging the gray-matter library for parsing and stringifying YAML or JSON formatted frontmatter.", "description": "A Node.js module for handling and processing frontmatter in markdown and text files, leveraging the gray-matter library for parsing and stringifying YAML or JSON formatted frontmatter.",
"npmPackagename": "@push.rocks/smartfm", "npmPackagename": "@push.rocks/smartfm",
"license": "MIT", "license": "MIT",
@@ -27,9 +24,20 @@
"metadata management", "metadata management",
"gray-matter" "gray-matter"
] ]
},
"release": {
"registries": [
"https://verdaccio.lossless.digital",
"https://registry.npmjs.org"
],
"accessLevel": "public"
} }
}, },
"tsdoc": { "@git.zone/tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n" "legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
},
"@ship.zone/szci": {
"npmGlobalTools": [],
"npmRegistryUrl": "registry.npmjs.org"
} }
} }
+13 -11
View File
@@ -1,15 +1,16 @@
{ {
"name": "@push.rocks/smartfm", "name": "@push.rocks/smartfm",
"version": "2.1.1", "version": "2.2.3",
"private": false, "private": false,
"description": "A Node.js module for handling and processing frontmatter in markdown and text files, leveraging the gray-matter library for parsing and stringifying YAML or JSON formatted frontmatter.", "description": "A Node.js module for handling and processing frontmatter in markdown and text files, leveraging the gray-matter library for parsing and stringifying YAML or JSON formatted frontmatter.",
"exports": { "exports": {
".": "./dist/index.js" ".": "./dist_ts/index.js"
}, },
"type": "module", "type": "module",
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "tstest test/",
"build": "tsbuild tsfolders --allowimplicitany", "format": "gitzone format",
"build": "tsbuild tsfolders",
"buildDocs": "tsdoc" "buildDocs": "tsdoc"
}, },
"repository": { "repository": {
@@ -31,21 +32,20 @@
"metadata management", "metadata management",
"gray-matter" "gray-matter"
], ],
"author": "Lossless GmbH", "author": "Task Venture Capital GmbH <hello@task.vc>",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://code.foss.global/push.rocks/smartfm/issues" "url": "https://code.foss.global/push.rocks/smartfm/issues"
}, },
"homepage": "https://code.foss.global/push.rocks/smartfm#readme", "homepage": "https://code.foss.global/push.rocks/smartfm#readme",
"dependencies": { "dependencies": {
"gray-matter": "^4.0.2" "gray-matter": "^4.0.3"
}, },
"devDependencies": { "devDependencies": {
"@git.zone/tsbuild": "^2.1.17", "@git.zone/tsbuild": "^4.4.0",
"@git.zone/tsrun": "^1.2.8", "@git.zone/tsrun": "^2.0.3",
"@git.zone/tstest": "^1.0.24", "@git.zone/tstest": "^3.6.3",
"@push.rocks/tapbundle": "^5.5.6", "@types/node": "^25.6.0"
"@types/node": "^12.7.4"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",
@@ -56,6 +56,8 @@
"dist_ts_web/**/*", "dist_ts_web/**/*",
"assets/**/*", "assets/**/*",
"cli.js", "cli.js",
".smartconfig.json",
"license",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
] ]
+3884 -5657
View File
File diff suppressed because it is too large Load Diff
+208
View File
@@ -0,0 +1,208 @@
# @push.rocks/smartfm
The `@push.rocks/smartfm` module handles frontmatter data in markdown and other text files. The module allows easy parsing, stringification, and extraction of frontmatter data, using YAML or JSON format. It leverages the `gray-matter` library for advanced functionality with a simple API.
## Install
To use `@push.rocks/smartfm`, you first need to install it via npm. Make sure you have Node.js installed, and run the following command in your terminal:
```sh
npm install @push.rocks/smartfm
```
This will add the module as a dependency to your project.
## Usage
Once the module is installed, you can start using its capabilities by importing and initializing the `Smartfm` class in your TypeScript or JavaScript projects. The following sections provide comprehensive examples of the module's functionality:
### Importing the Module
To get started with the module, use the following import statement:
```typescript
import { Smartfm } from '@push.rocks/smartfm';
```
The module exports the `Smartfm` class, which you will use to manipulate frontmatter in your files.
### Initializing the `Smartfm` Class
The `Smartfm` class requires an options object to be passed during initialization. The options object specifies the type of frontmatter format you are working with, which can either be `'yaml'` or `'json'`. Here's how you can initialize the class:
```typescript
// Initialize with YAML frontmatter
let smartfm = new Smartfm({ fmType: 'yaml' });
// Initialize with JSON frontmatter
let smartfmJSON = new Smartfm({ fmType: 'json' });
```
The initialized objects can then be used to parse and stringify frontmatter in strings and text files.
### Parsing Frontmatter from Strings
To parse frontmatter data from a string that includes frontmatter, use the `parse` method. This function returns an object containing the parsed frontmatter data and the rest of the string:
```typescript
const sampleString = `---
title: Test Document
author: John Doe
---
This is the body content of the file.`;
let parsedContent = smartfm.parse(sampleString);
console.log(parsedContent.data); // Outputs the frontmatter data as a JavaScript object
console.log(parsedContent.content); // Outputs "This is the body content of the file."
```
The `parse` method will recognize and extract the frontmatter block, returning it as a JavaScript object while preserving the original content of the string.
### Stringifying a String with Frontmatter
If you have a string and frontmatter data that you want to combine into a correctly formatted frontmatter block in a string, you can use the `stringify` method:
```typescript
const bodyContent = "This is some markdown content.";
const frontmatterData = {
date: "2023-01-01",
tags: ["example", "frontmatter"]
};
let combinedString = smartfm.stringify(bodyContent, frontmatterData);
console.log(combinedString);
// Outputs a string with the frontmatter serialized at the top
```
This method appends the serialized frontmatter to the top of the given body content, making it ready for use in typical markdown or frontmatter-supported documents.
### Parsing Frontmatter from Commented Sections
Sometimes frontmatter data might be commented out. The `parseFromComments` method allows you to parse such data by providing a comment prefix:
```typescript
const commentedFile = `# ---
# title: Commented Example
# date: 2023-10-15
# ---
Actual file content here...`;
let parsedCommentedContent = smartfm.parseFromComments('# ', commentedFile);
console.log(parsedCommentedContent.data); // Outputs { title: "Commented Example", date: "2023-10-15" }
```
The `parseFromComments` method strips the comment prefixes before parsing the frontmatter, enabling easy extraction of data listed in commented sections.
### Using the Module for Complex Scenarios
Beyond these basic operations, the `@push.rocks/smartfm` module can be a crucial part of more complex workflows. For instance, integrating frontmatter management with static site generators, content management systems (CMS), or any situation where content metadata is necessary.
#### Example Scenario: A Static Site Generator
Imagine a static site generator that uses markdown files with frontmatter as data sources for pages. `@push.rocks/smartfm` can help read, extract, and manipulate these files programmatically:
```typescript
import fs from 'fs';
import path from 'path';
const contentDir = path.join(process.cwd(), 'content');
fs.readdir(contentDir, (err, files) => {
if (err) throw err;
files.forEach(file => {
const filePath = path.join(contentDir, file);
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) throw err;
const smartfmInstance = new Smartfm({ fmType: 'yaml' });
const parsedPage = smartfmInstance.parse(data);
console.log('Page Title:', parsedPage.data.title);
console.log('Markdown Content:', parsedPage.content);
// Optionally, modify and update frontmatter
parsedPage.data.title = 'Updated Title';
const updatedContent = smartfmInstance.stringify(parsedPage.content, parsedPage.data);
fs.writeFile(filePath, updatedContent, (err) => {
if (err) throw err;
console.log('File updated successfully.');
});
});
});
});
```
In this example, we read all markdown files from a directory, parse them to extract frontmatter data, optionally modify the frontmatter, and write the updated content back to the files.
### Advanced Use Cases
`@push.rocks/smartfm` is flexible enough to support advanced operations like validating frontmatter, applying transformations, and more. Here are a few ideas to explore:
#### Frontmatter Validation
You might want to validate the structure of frontmatter data against a schema before processing. Here's a conceptual idea using `@push.rocks/smartfm`:
```typescript
import Ajv from 'ajv';
const ajv = new Ajv();
const schema = {
type: 'object',
properties: {
title: { type: 'string' },
date: { type: 'string', format: 'date' }
},
required: ['title', 'date']
};
const validate = ajv.compile(schema);
const frontmatter = smartfm.parse(sampleString).data;
if (validate(frontmatter)) {
console.log('Frontmatter is valid.');
} else {
console.error('Frontmatter validation failed:', validate.errors);
}
```
Using a validation library like Ajv, you can ensure that the parsed frontmatter adheres to a required schema or format, enhancing data integrity in larger applications.
#### Transformed Output
Suppose you want to output the parsed markdown content in a transformed format, such as HTML. Heres how you could integrate a markdown parsing library:
```typescript
import marked from 'marked';
const parsedResult = smartfm.parse(sampleString);
const htmlContent = marked(parsedResult.content);
console.log('HTML Content:', htmlContent);
```
By combining `@push.rocks/smartfm` with a markdown parsing library like `marked`, you can convert markdown content into other formats while handling the associated frontmatter.
With these examples, you can see how `@push.rocks/smartfm` fits into various workflows involving frontmatter and text processing. The module's simplicity and effectiveness make it a suitable choice for projects that require clean handling of document metadata.
Feel free to explore and extend these examples based on your particular use case. Whether you are building a simple script, a web application, or an extensive content management system, `@push.rocks/smartfm` provides a robust foundation for frontmatter operations. Happy coding!
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
+2 -2
View File
@@ -1,4 +1,4 @@
import { tap, expect } from '@push.rocks/tapbundle'; import { tap, expect } from '@git.zone/tstest/tapbundle';
import * as smartfm from '../ts/index.js'; import * as smartfm from '../ts/index.js';
@@ -42,4 +42,4 @@ really
console.log(result); console.log(result);
}); });
tap.start(); export default tap.start();
+1 -1
View File
@@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartfm', name: '@push.rocks/smartfm',
version: '2.1.1', version: '2.2.3',
description: 'A Node.js module for handling and processing frontmatter in markdown and text files, leveraging the gray-matter library for parsing and stringifying YAML or JSON formatted frontmatter.' description: 'A Node.js module for handling and processing frontmatter in markdown and text files, leveraging the gray-matter library for parsing and stringifying YAML or JSON formatted frontmatter.'
} }
+4 -4
View File
@@ -19,22 +19,22 @@ export class Smartfm {
/** /**
* add frontmatter to a string * add frontmatter to a string
*/ */
stringify(bodyString: string, frontmatterData: any) { stringify(bodyString: string, frontmatterData: Record<string, unknown>): string {
return grayMatter.stringify(bodyString, frontmatterData); return grayMatter.stringify(bodyString, frontmatterData);
} }
/** /**
* parse a string that has frontmatter attached, YAML notation * parse a string that has frontmatter attached, YAML notation
*/ */
parse(stringToParse: string) { parse(stringToParse: string): grayMatter.GrayMatterFile<string> {
return grayMatter(stringToParse); return grayMatter(stringToParse);
} }
/** /**
* parse from comments * parse from comments
*/ */
parseFromComments(commentStart: string, stringToParse: string) { parseFromComments(commentStart: string, stringToParse: string): grayMatter.GrayMatterFile<string> {
const diffFunc = (diffMe, diffBy) => diffMe.split(diffBy).join(''); const diffFunc = (diffMe: string, diffBy: string): string => diffMe.split(diffBy).join('');
let lines = stringToParse.split('\n'); let lines = stringToParse.split('\n');
lines = lines.map((line) => { lines = lines.map((line) => {
return diffFunc(line, commentStart); return diffFunc(line, commentStart);
+4 -6
View File
@@ -6,12 +6,10 @@
"target": "ES2022", "target": "ES2022",
"module": "NodeNext", "module": "NodeNext",
"moduleResolution": "NodeNext", "moduleResolution": "NodeNext",
"noImplicitAny": true,
"esModuleInterop": true, "esModuleInterop": true,
"verbatimModuleSyntax": true, "verbatimModuleSyntax": true,
"baseUrl": ".", "types": ["node"]
"paths": {}
}, },
"exclude": [ "exclude": ["dist_*/**/*.d.ts"]
"dist_*/**/*.d.ts" }
]
}