wordpress-header-comment
v1.1.1
Published
A simple utility to parse and stringify WordPress header comments.
Downloads
171
Maintainers
Readme
WordPress Header Comment
A simple utility to parse and stringify WordPress header comments.
Usage
npm i wordpress-header-comment
Parse
import { parse } from "wordpress-header-comment"
const comment = `/**
* Plugin Name: ...
* Version: ...
* Description: ...
*/`
parse(comment)
Result:
{
"Plugin Name": "...",
Version: "...",
Description: "..."
}
Stringify
import { stringify } from "wordpress-header-comment"
const headers = {
"Plugin Name": "...",
Version: "...",
Description: "...",
}
stringify(headers)
Result:
/**
* Plugin Name: ...
* Version: ...
* Description: ...
*/
Alignment
stringify(headers, { gap: 0 })
Result:
/**
* Plugin Name: ...
* Version: ...
* Description: ...
*/
Match
import { match, parse, stringify } from "wordpress-header-comment"
const content = `<?php
/**
* Plugin Name: ...
* Version: ...
* Description: ...
*/
?>`
const headers = parse(content)
headers["Plugin Name"] = "???"
headers["Version"] = "???"
headers["Description"] = "???"
const comment = stringify(headers)
const { before, after } = match(content)
const modifiedContent = before + comment + after
Result:
<?php
/**
* Plugin Name: ???
* Version: ???
* Description: ???
*/
?>