1.1.0 • Published 2 years ago

userscript-header-format v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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;
1.1.0

2 years ago

1.0.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago