generated-signature 0.1.0 → 0.1.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/README.md CHANGED
@@ -91,7 +91,7 @@ export class AutoGenerated {
91
91
  }
92
92
  ```
93
93
 
94
- - **Signature token**: `@generated-signature v1:` followed by 32 lowercase hex characters. It must appear exactly once, anywhere in the file. `sign()` inserts it as the first line (after a shebang or XML declaration) unless the text already has one, so a generator with its own header can place it there with [`signatureToken()`](#signaturetoken).
94
+ - **Signature token**: `@generated-signature v1:` followed by 32 lowercase hex characters. It must appear exactly once, anywhere in the file. `sign()` inserts it as the first line (after a shebang, an XML declaration, or Markdown front matter) unless the text already has one, so a generator with its own header can place it there with [`signatureToken()`](#signaturetoken).
95
95
  - **Manual sections**: a line containing `@manual-start <id>` and a later line containing `@manual-end <id>`. Ids are letters, digits, `_`, `.` and `-`, unique per file. Sections do not nest. The marker must be at the start of the line or after whitespace.
96
96
  - **Hash**: SHA-256 (first 128 bits) of the file with `\r\n` normalized to `\n`, the token's hash replaced by zeros, and every section body removed. The marker lines are hashed, so adding, removing or renaming a section is detected. `v1` versions this algorithm.
97
97
 
@@ -51,6 +51,11 @@ const insertHeader = (text, options)=>{
51
51
  const firstLineEnd = text.indexOf('\n');
52
52
  return firstLineEnd === -1 ? text + lineBreak + header : text.slice(0, firstLineEnd + 1) + header + text.slice(firstLineEnd + 1);
53
53
  }
54
+ const frontMatter = style.start === '<!--' ? /^---\r?\n(?:[^\n]*\n)*?---\r?(?:\n|$)/u.exec(text) : null;
55
+ if (frontMatter) {
56
+ const [fenced] = frontMatter;
57
+ return fenced.endsWith('\n') ? fenced + header + text.slice(fenced.length) : fenced + lineBreak + header;
58
+ }
54
59
  return header + text;
55
60
  };
56
61
  export const sign = (text, options)=>{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generated-signature",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Sign generated files so hand edits are detected, while keeping manual sections editable",
5
5
  "engines": {
6
6
  "node": ">=24"