UNPKG

caml-mkdn

Version:

Colon Attribute Markup Lanugage -- a YAML-like markup syntax for (semantic) attributes in markdown.

131 lines (126 loc) 4.53 kB
/* eslint-disable indent */ /* eslint-disable @typescript-eslint/no-namespace */ declare namespace RGX { const MARKER: { readonly BULLET: RegExp; readonly KEY_PRFX: RegExp; readonly COL: RegExp; }; // for whitespace handling... const MARKER_WS: { readonly KEY_PRFX: RegExp; readonly COL: RegExp; }; const VALID_CHARS: { readonly KEY: RegExp; readonly VAL: RegExp; }; const CAP_GRP: { readonly KEY: RegExp; readonly VAL: RegExp; }; const LINE: { readonly KEY: RegExp; readonly LIST_ITEM: RegExp; }; const CAML: RegExp; } // data interface CamlValData { type: string; string: string; value: null | boolean | number | bigint | Date | string; // | NaN; } // func // dump() interface CamlDumpOpts { format: "pretty" | "pad" | "none"; listFormat: "comma" | "mkdn"; prefix: boolean; } // load() interface CamlLoadPayload { data: any; content: string; } // scan() interface CamlScanResKey { key: [ string, number ]; } interface CamlScanResVal { type: string; val: [ string, number ]; } /****************************************************************************** from: https://github.com/eemeli/yaml licensing permission: Copyright Eemeli Aro <eemeli@gmail.com> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************************/ // 'val' as in, "i want to extract the value" and likely used in conjunction // with other regexes to interact with caml attributes declare const VAL: { readonly NULL: RegExp; readonly BOOL: RegExp; readonly INT: RegExp; readonly INT_HEX: RegExp; readonly INT_OCT: RegExp; readonly FLOAT: RegExp; readonly FLOAT_EXP: RegExp; readonly FLOAT_NAN: RegExp; readonly TIME_INT: RegExp; readonly TIME_FLOAT: RegExp; readonly TIMESTAMP: RegExp; readonly STRING: RegExp; }; // 'type' as in, "i want to determine the type of the value" and likely used in isolation // to narrowly determine the type of a given value, perhaps to 'rgx.test(str)' for example. declare const TYPE: { readonly NULL: RegExp; readonly BOOL: RegExp; readonly INT: RegExp; readonly INT_HEX: RegExp; readonly INT_OCT: RegExp; readonly FLOAT: RegExp; readonly FLOAT_EXP: RegExp; readonly FLOAT_NAN: RegExp; readonly TIME_INT: RegExp; readonly TIME_FLOAT: RegExp; readonly TIMESTAMP: RegExp; readonly STRING: RegExp; }; // from: https://github.com/eemeli/yaml/blob/27bd4faa79c4ff01410c8c6fcf8baa8586769320/src/schema/yaml-1.1/timestamp.ts#L6 declare function parseSexagesimal<B extends boolean>(str: string, asBigInt?: B): B extends true ? number | bigint : number; // from js-yaml: https://github.com/nodeca/js-yaml/blob/master/lib/type/timestamp.js#L29 declare function constructYamlTimestamp(data: any): Date; // todo: // - strict strings // - multiline strings declare function dump(attrs: any, opts?: CamlDumpOpts): string; declare function load(content: string): CamlLoadPayload; // todo: what if there's leading/trailing whitespace? (trimming beforehand, for now) declare function resolve(value: string): CamlValData; // scan -- useful for syntax highlights declare function scan(content: string): (CamlScanResKey | CamlScanResVal)[]; declare function scanUpdateAttr(content: string, key: string, newVal: string, type?: string): [ number, number, string ] | undefined; declare function updateAttr(content: string, key: string, newVal: string, type?: string): string | undefined; export { RGX, CamlValData, CamlDumpOpts, CamlLoadPayload, CamlScanResKey, CamlScanResVal, VAL, TYPE, parseSexagesimal, constructYamlTimestamp, dump, load, resolve, scan, scanUpdateAttr, updateAttr };