docschema
Version:
Schema declaration and validation library using JsDoc comments
189 lines (188 loc) • 5.77 kB
TypeScript
/**
* @param {string} path
* @returns {string}
*/
export function dirname(path: string): string;
/**
* @see https://stackoverflow.com/questions/17575790/environment-detection-node-js-or-browser
* @returns {boolean}
*/
export function isBrowserEnvironment(): boolean;
export namespace isBrowserEnvironment {
let isIt: undefined | boolean;
}
/**
* @param {Object<any, any>} object
* @returns {boolean}
*/
export function isObjectEmpty(object: any): boolean;
/**
* Using binary search, find first element that is greater or
* equal to the given target.
*
* @param {number[]} arr Sorted array
* @param {number} target
* @returns {number}
*/
export function binarySearchFirstGTE(arr: number[], target: number): number;
/**
* @param {string} inputString
* The 'start' symbol of the input string should be the opening
* bracket. The closing bracket is automatically determined.
*
* For example:
* ``
* {textInside{}} textOutside
* ``
* The output value for this example would be 13.
* @param {number} [start]
* The position where the opening quote is.
* @returns {number} The position of the found bracket,
* or 0 if not found
*/
export function findClosingBracketPosition(inputString: string, start?: number): number;
/**
* @param {string} inputString
* The 'start' symbol of the input string should be the
* opening quote.
* @param {number} [start]
* The position where the opening quote is.
* @returns {number}
* The position of the closing quote after 'start',
* or 0 if the string doesn't start with a quote,
* or 0 if no closing quote found.
*/
export function findClosingQuotePosition(inputString: string, start?: number): number;
export namespace findClosingQuotePosition {
let quotes: Set<string>;
}
/**
* Find the position of the first EOL symbol (\n).
* If not found, return the position of the end.
*
* @param {string} inputString
* @param {number} [start]
* @returns {number}
* The position of the next \n after 'start', or -1 if not found
*/
export function findEOL(inputString: string, start?: number): number;
/**
* Remove // in the beginning or in the middle of the string
*
* @param {string} description
* @returns {string}
*/
export function flattenMultilineDescription(description: string): string;
/**
* @param {string} openingBracket (, [, < or {
* @returns {string}
*/
export function closingBracketOf(openingBracket: string): string;
/**
* Splits the type expression using custom separator.
* The split is aware of chunks of code (brackets, quotes,
* comments) and treats them as whole entities.
*
* @param {string} typeExpression
* @param {Set<string>} [separators] One or more separators
* @returns {string[]} An array with minimum 1 element.
*/
export function splitTypeExpression(typeExpression: string, separators?: Set<string>): string[];
/**
* In JsDoc comments, single-line comments in object literals are
* considered descriptions. One such description can be made of
* multiple lines of single-line descriptions.
*
* When the input JsDoc expression has multiple lines and starts
* with a single-line comment (//...), that comment is a JsDoc
* description and is isolated from the rest of the expression.
*
* The returned value is a tuple with 2 values, where the
* isolated description is at index 0 and the rest is at index 1.
* Both values are trimmed.
*
* @param {string} expression
* @returns {[string, string]}
* @throws {SyntaxError}
*/
export function isolateFrontDescription(expression: string): [string, string];
/**
* @param {string} expression
* A trimmed JsDoc expression, containing type and
* (optionally) a description.
* The description can have multiple lines, where
* each line starts with //.
* @returns {[string, string]}
* For example, if the expression is "number // description",
* the output will be ['number', 'description'].
* If the expression is "{number} // description",
* the output will be ['{number}', 'description'].
*/
export function isolateEndDescription(expression: string): [string, string];
/**
* @see https://gist.github.com/creationix/7435851#gistcomment-3698888
*
* @param {...string} segments
* @returns {string}
*/
export function joinPath(...segments: string[]): string;
export namespace joinPath {
/**
* @param {string[]} parts
* @param {string} segment
* @returns {string[]}
*/
function reducer(parts: string[], segment: string): string[];
}
/**
* If the input value is a string, wrap it into "" quotes,
* otherwise turn it into a string and return it
*
* @param {*} value
* @param {string} quote
* @returns {string}
*/
export function enquoteString(value: any, quote?: string): string;
/**
* If the input value is a string, remove the wrapping quotes,
* otherwise turn it into a string and return it
*
* @param {*} value
* @returns {string}
*/
export function dequoteString(value: any): string;
/**
* Removes ( and ) braces, if they are the first and
* the last symbols of the trimmed input string
*
* @param {string} str
* @returns {string}
*/
export function removeWrappingBraces(str: string): string;
/**
* @param {any[]} object
* @param {number} [maxSymbols]
* @returns {string}
* @throws {TypeError}
*/
export function objectStringify(object: any[], maxSymbols?: number): string;
/**
* Trim each value of the chopped commend (array)
*
* @param {string[]} array
*/
export function trimArrayElements(array: string[]): void;
/**
* Search for simple ES imports and return the file names.
*
* @example
* `
* import './fileOne.js'
* import './fileTwo.js'
* `
* This returns [ './fileOne.js', './fileTwo.js' ]
*
* @param {string} code
* @returns {string[]}
*/
export function extractSimpleImports(code: string): string[];