Skip to content

lerarosalene/userscript-header-format

Repository files navigation

Userscript header formatter

release npm

Tool to format userscript headers from js.

Usage:

import UserscriptHeader from "userscript-header-formatter";

const header = UserscriptHeader.fromObject({
  name: "My cool userscript",
  namespace: "https://example.com",
  version: "0.1.0",
  description: "very cool indeed",
  author: "me",
  match: [
    "https://github.com/*",
    "https://gitlab.com/*"
  ]
}).toString();

Header, generated from this code will be:

// ==UserScript==
// @name         My cool userscript
// @namespace    https://example.com
// @version      0.1.0
// @description  very cool indeed
// @author       me
// @match        https://github.com/*
// @match        https://gitlab.com/*
// ==/UserScript==

Api declarations

type Value = string | number;

interface Field {
  name: string;
  value: Value;
}

interface HeaderDescriptor {
  [index: string]: Value | Array<Value>;
}

declare class Header {
  constructor(fields: Field[]);
  static fromObject(object: HeaderDescriptor): Header;
  toString(): string;
}

export default Header;

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks