@keymanapp/common-types
Version:
Keyman Developer keyboard file types
112 lines • 4.34 kB
TypeScript
import { MATCH_HEX_ESCAPE, CONTAINS_QUAD_ESCAPE, MATCH_QUAD_ESCAPE } from './consts.js';
export { MATCH_HEX_ESCAPE, CONTAINS_QUAD_ESCAPE, MATCH_QUAD_ESCAPE };
/**
* xml2js will not place single-entry objects into arrays. Easiest way to fix
* this is to box them ourselves as needed. Ensures that o.x is an array.
*
* @param o Object with property to box
* @param x Name of element to box
*/
export declare function boxXmlArray(o: any, x: string): void;
export declare class UnescapeError extends Error {
}
/**
* Unescape one codepoint
* @param hex one codepoint in hex, such as '0127'
* @returns the unescaped codepoint
*/
export declare function unescapeOne(hex: string): string;
/**
* Unescape one single quad string such as \u0127 / \U00000000
* Throws exception if the string doesn't match MATCH_QUAD_ESCAPE
* Note this does not attempt to handle or reject surrogates.
* So, `\\uD838\\uDD09` will work but other combinations may not.
* @param s input string
* @returns output
*/
export declare function unescapeOneQuadString(s: string): string;
/** unscape multiple occurences of \u0127 style strings */
export declare function unescapeQuadString(s: string): string;
/**
* Unescapes a string according to UTS#18§1.1, see <https://www.unicode.org/reports/tr18/#Hex_notation>
* @param s escaped string
* @returns
*/
export declare function unescapeString(s: string): string;
/** 0000 … FFFF */
export declare function hexQuad(n: number): string;
/** 00000000 … FFFFFFFF */
export declare function hexOcts(n: number): string;
/** escape one char for regex in \uXXXX form */
export declare function escapeRegexChar(ch: string): string;
/**
* Escape a string (\uxxxx form) if there are any problematic codepoints
*/
export declare function escapeStringForRegex(s: string): string;
/**
* Unescapes a string according to UTS#18§1.1, see <https://www.unicode.org/reports/tr18/#Hex_notation>
* @param s escaped string
* @returns
*/
export declare function unescapeStringToRegex(s: string): string;
/** True if this string *could* be a UTF-32 single char */
export declare function isOneChar(value: string): boolean;
export declare function toOneChar(value: string): number;
export declare function describeCodepoint(ch: number): string;
export declare enum BadStringType {
pua = "PUA",
unassigned = "Unassigned",
illegal = "Illegal",
denormalized = "Denormalized"
}
/**
* @brief True if a lead surrogate
* \def Uni_IsSurrogate1
*/
export declare function Uni_IsSurrogate1(ch: number): boolean;
/**
* @brief True if a trail surrogate
* \def Uni_IsSurrogate2
*/
export declare function Uni_IsSurrogate2(ch: number): boolean;
/**
* @brief True if any surrogate
* \def UniIsSurrogate
*/
export declare function Uni_IsSurrogate(ch: number): boolean;
export declare function isValidUnicode(start: number, end?: number): boolean;
export declare function isPUA(ch: number): boolean;
/** @returns false if s is NEITHER NFC nor NFD. (Returns true for falsy) */
export declare function isNormalized(s: string): boolean;
declare class BadStringMap extends Map<BadStringType, Set<number>> {
toString(): string;
}
/** abstract class for analyzing and categorizing strings */
export declare abstract class StringAnalyzer {
/** add a string for analysis */
add(s: string): void;
/**
* subclass interface
* @param c single codepoint to analyze (string)
* @param ch single codepoint to analyze (scalar)
*/
protected abstract analyzeCodePoint(c: string, ch: number): BadStringType;
/** internal interface for the result of an analysis */
protected addProblem(ch: number, type: BadStringType): void;
/** get the results of the analysis */
analyze(): BadStringMap;
/** internal map */
private m;
}
/** analyze a string looking for bad unicode */
export declare class BadStringAnalyzer extends StringAnalyzer {
/** analyze one codepoint */
protected analyzeCodePoint(c: string, ch: number): BadStringType;
/** export analyzer function */
static getProblem(ch: number): BadStringType.pua | BadStringType.illegal;
}
/** Analyzer that checks if something isn't NFD */
export declare class NFDAnalyzer extends StringAnalyzer {
protected analyzeCodePoint(c: string, ch: number): BadStringType;
}
//# sourceMappingURL=util.d.ts.map