wordpress-header-comment
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

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: ???
 */
?>

Package Sidebar

Install

npm i wordpress-header-comment

Weekly Downloads

40

Version

1.1.1

License

MIT

Unpacked Size

5.74 kB

Total Files

4

Last publish

Collaborators

  • babakfp