UNPKG

extra-javascript-text.web

Version:

Utilities for processing JavaScript text{web}.

281 lines (279 loc) 10.6 kB
/** * String match function. * [📘](https://github.com/nodef/extra-javascript-text/wiki/StringMatchFunction) * @param full full string */ type StringMatchFunction = (full: string) => void; /** * Match string in javascript text. * [📘](https://github.com/nodef/extra-javascript-text/wiki/forEachString) * @param txt javascript text * @param fn match function */ declare function forEachString(txt: string, fn: StringMatchFunction): void; /** * Get strings in javascript text. * [📘](https://github.com/nodef/extra-javascript-text/wiki/strings) * @param txt javascript text * @returns strings */ declare function strings(txt: string): string[]; /** * String replace function. * [📘](https://github.com/nodef/extra-javascript-text/wiki/StringReplaceFunction) * @param full full string * @returns updated string */ type StringReplaceFunction = (full: string) => string; /** * Replace strings in javascript text. * [📘](https://github.com/nodef/extra-javascript-text/wiki/replaceStrings) * @param txt javascript text * @param fn replace function * @returns updated javascript text */ declare function replaceStrings(txt: string, fn: StringReplaceFunction): string; /** * Tag strings in javascript text and remove them. * [📘](https://github.com/nodef/extra-javascript-text/wiki/tagStrings) * @param txt javascript text * @returns [updated javascript text, tags] */ declare function tagStrings(txt: string): [string, Map<string, string>]; /** * Untag strings in javascript text by adding them back. * [📘](https://github.com/nodef/extra-javascript-text/wiki/untagStrings) * @param txt javascript text * @param tags tags * @returns updated javascript text */ declare function untagStrings(txt: string, tags: Map<string, string>): string; /** * Comment match function. * [📘](https://github.com/nodef/extra-javascript-text/wiki/CommentMatchFunction) * @param full full comment */ type CommentMatchFunction = (full: string) => void; /** * Match links in javascript text. * [📘](https://github.com/nodef/extra-javascript-text/wiki/forEachComment) * @param txt javascript text * @param fn match function */ declare function forEachComment(txt: string, fn: CommentMatchFunction): void; /** * Get comments in javascript text. * [📘](https://github.com/nodef/extra-javascript-text/wiki/comments) * @param txt javascript text * @returns comments */ declare function comments(txt: string): string[]; /** * Comment replace function. * [📘](https://github.com/nodef/extra-javascript-text/wiki/CommentReplaceFunction) * @param full full comment * @returns updated comment */ type CommentReplaceFunction = (full: string) => string; /** * Replace comments in javascript text. * [📘](https://github.com/nodef/extra-javascript-text/wiki/replaceComments) * @param txt javascript text * @param fn replace function * @returns updated javascript text */ declare function replaceComments(txt: string, fn: CommentReplaceFunction): string; /** * Tag comments in javascript text and remove them. * [📘](https://github.com/nodef/extra-javascript-text/wiki/tagComments) * @param txt javascript text * @returns [updated javascript text, tags] */ declare function tagComments(txt: string): [string, Map<string, string>]; /** * Untag comments in javascript text by adding them back. * [📘](https://github.com/nodef/extra-javascript-text/wiki/untagComments) * @param txt javascript text * @param tags tags * @returns updated javascript text */ declare function untagComments(txt: string, tags: Map<string, string>): string; /** * Remove comments from javascript text. * [📘](https://github.com/nodef/extra-javascript-text/wiki/uncomment) */ declare function uncomment(txt: string, empty?: boolean): string; /** * JSDoc symbol match function. * [📘](https://github.com/nodef/extra-javascript-text/wiki/JsdocSymbolMatchFunction) * @param full full jsdoc symbol match * @param jsdoc jsdoc attached to symbol * @param name symbol name * @param kind symbol kind * @param isExported symbol is exported? * @param isDefault symbol is default? */ type JsdocSymbolMatchFunction = (full: string, jsdoc: string, name: string, kind: string, isExported: boolean, isDefault: boolean) => void; /** * Match jsdoc symbols in javascript text. * [📘](https://github.com/nodef/extra-javascript-text/wiki/forEachJsdocSymbol) * @param txt javascript text * @param fn match function */ declare function forEachJsdocSymbol(txt: string, fn: JsdocSymbolMatchFunction): void; /** * JSDoc symbol. * [📘](https://github.com/nodef/extra-javascript-text/wiki/JsdocSymbol) */ interface JsdocSymbol { /** Full jsdoc symbol match. */ full: string; /** JSDoc attached to symbol. */ jsdoc: string; /** Symbol name. */ name: string; /** Symbol kind. */ kind: string; /** Symbol is exported? */ isExported: boolean; /** Symbol is default? */ isDefault: boolean; } /** * Get jsdoc symbols in javascript text. * [📘](https://github.com/nodef/extra-javascript-text/wiki/jsdocSymbols) * @param txt javascript text * @returns jsdoc symbols */ declare function jsdocSymbols(txt: string): JsdocSymbol[]; /** * Jsdoc symbol replace function. * [📘](https://github.com/nodef/extra-javascript-text/wiki/JsdocSymbolReplaceFunction) * @param full full jsdoc symbol match * @param jsdoc jsdoc attached to symbol * @param name symbol name * @param kind symbol kind * @param isExported symbol is exported? * @param isDefault symbol is default? * @returns updated jsdoc symbol */ type JsdocSymbolReplaceFunction = (full: string, jsdoc: string, name: string, kind: string, isExported: boolean, isDefault: boolean) => string; /** * Replace jsdoc symbols in javascript text. * [📘](https://github.com/nodef/extra-javascript-text/wiki/replaceJsdocSymbols) * @param txt javascript text * @param fn replace function * @returns updated javascript text */ declare function replaceJsdocSymbols(txt: string, fn: JsdocSymbolReplaceFunction): string; /** * Export symbol match function. * [📘](https://github.com/nodef/extra-javascript-text/wiki/ExportSymbolMatchFunction) * @param full full export symbol match * @param name symbol name * @param kind symbol kind * @param isDefault symbol is default? */ type ExportSymbolMatchFunction = (full: string, name: string, kind: string, isDefault: boolean) => void; /** * Match export symbols in javascript text. * [📘](https://github.com/nodef/extra-javascript-text/wiki/forEachExportSymbol) * @param txt javascript text * @param fn match function */ declare function forEachExportSymbol(txt: string, fn: ExportSymbolMatchFunction): void; /** * Export symbol. * [📘](https://github.com/nodef/extra-javascript-text/wiki/ExportSymbol) */ interface ExportSymbol { /** Full export symbol match. */ full: string; /** Symbol name. */ name: string; /** Symbol kind. */ kind: string; /** Symbol is default? */ isDefault: boolean; } /** * Get export symbols in javascript text. * [📘](https://github.com/nodef/extra-javascript-text/wiki/exportSymbols) * @param txt javascript text * @returns export symbols */ declare function exportSymbols(txt: string): ExportSymbol[]; /** * Export symbol replace function. * [📘](https://github.com/nodef/extra-javascript-text/wiki/ExportSymbolReplaceFunction) * @param full full export symbol match * @param name symbol name * @param kind symbol kind * @param isDefault symbol is default? * @returns updated export symbol */ type ExportSymbolReplaceFunction = (full: string, name: string, kind: string, isDefault: boolean) => string; /** * Replace export symbols in javascript text. * [📘](https://github.com/nodef/extra-javascript-text/wiki/replaceExportSymbols) * @param txt javascript text * @param fn replace function * @returns updated javascript text */ declare function replaceExportSymbols(txt: string, fn: ExportSymbolReplaceFunction): string; /** * Import symbol match function. * [📘](https://github.com/nodef/extra-javascript-text/wiki/ImportSymbolMatchFunction) * @param full full import symbol match * @param file import file */ type ImportSymbolMatchFunction = (full: string, file: string) => void; /** * Match import symbols in javascript text. * [📘](https://github.com/nodef/extra-javascript-text/wiki/forEachImportSymbol) * @param txt javascript text * @param fn match function */ declare function forEachImportSymbol(txt: string, fn: ImportSymbolMatchFunction): void; /** * Import symbol. * [📘](https://github.com/nodef/extra-javascript-text/wiki/ImportSymbol) */ interface ImportSymbol { /** Full import symbol match. */ full: string; /** Import file. */ file: string; } /** * Get import symbols in javascript text. * [📘](https://github.com/nodef/extra-javascript-text/wiki/importSymbols) * @param txt javascript text * @returns export symbols */ declare function importSymbols(txt: string): ImportSymbol[]; /** * Import symbol replace function. * [📘](https://github.com/nodef/extra-javascript-text/wiki/ImportSymbolReplaceFunction) * @param full full import symbol match * @param file import file * @returns updated import symbol */ type ImportSymbolReplaceFunction = (full: string, file: string) => string; /** * Replace import symbols in javascript text. * [📘](https://github.com/nodef/extra-javascript-text/wiki/replaceImportSymbols) * @param txt javascript text * @param fn replace function * @returns updated javascript text */ declare function replaceImportSymbols(txt: string, fn: ImportSymbolReplaceFunction): string; /** * Correct type declarations after generation. * [📘](https://github.com/nodef/extra-javascript-text/wiki/correctDeclarations) * @param txt javascript text * @param module module name * @returns corrected javascript text */ declare function correctDeclarations(txt: string, module?: string): string; export { CommentMatchFunction, CommentReplaceFunction, ExportSymbol, ExportSymbolMatchFunction, ExportSymbolReplaceFunction, ImportSymbol, ImportSymbolMatchFunction, ImportSymbolReplaceFunction, JsdocSymbol, JsdocSymbolMatchFunction, JsdocSymbolReplaceFunction, StringMatchFunction, StringReplaceFunction, comments, correctDeclarations, exportSymbols, forEachComment, forEachExportSymbol, forEachImportSymbol, forEachJsdocSymbol, forEachString, importSymbols, jsdocSymbols, replaceComments, replaceExportSymbols, replaceImportSymbols, replaceJsdocSymbols, replaceStrings, strings, tagComments, tagStrings, uncomment, untagComments, untagStrings };