UNPKG

escape-unicode

Version:
81 lines 3.42 kB
/** * A function that returns whether the specified Unicode `code` point should be converted to a Unicode escape. * * @param code The Unicode code unit to be checked. * @param char The Unicode character to be checked. * @return A truthy value if `code` should be converted to a Unicode escape. */ export type Filter = (code: number, char: string) => unknown; /** * Returns a {@link Filter} composed of the specified `filters` that returns `true` only if any of the `filters` * provided return a truthy value. * * @example * const filter = composeFilter(isNotAscii, (code) => code === 0x0020); * escapeUnicode("I ♥ Unicode!", { filter }); * //=> "I\\u0020\\u2665\\u0020Unicode!" * @param filters The {@link Filter} functions to be composed. * @return A {@link Filter} composed of multiple `filters`. */ export declare const composeFilter: (...filters: Filter[]) => Filter; /** * A {@link Filter} that returns whether the specified Unicode `code` point is valid in ASCII encoding. * * ASCII covers code points 0x00-0x7F (0-127). * * @param code The Unicode code unit to be checked. * @return A truthy value if the code point is valid in ASCII encoding and should be converted to a Unicode escape. */ export declare const isAscii: Filter; /** * A {@link Filter} that returns whether the specified Unicode `code` point is **not** valid in ASCII encoding. * * ASCII covers code points 0x00-0x7F (0-127). * * @param code The Unicode code unit to be checked. * @return A truthy value if the code point is **not** valid in ASCII encoding and should be converted to a Unicode * escape. */ export declare const isNotAscii: Filter; /** * A {@link Filter} that returns whether the specified Unicode `code` point is in the Basic Multilingual Plane (BMP). * * BMP covers code points 0x0000-0xFFFF (0-65535) and represents characters that can be encoded in a single UTF-16 code * unit. * * @param code The Unicode code unit to be checked. * @return A truthy value if the code point is in the BMP and should be converted to a Unicode escape. */ export declare const isBmp: Filter; /** * A {@link Filter} that returns whether the specified Unicode `code` point is **not** in the Basic Multilingual Plane * (BMP). * * BMP covers code points 0x0000-0xFFFF (0-65535) and represents characters that can be encoded in a single UTF-16 code * unit. * * @param code The Unicode code unit to be checked. * @return A truthy value if the code point is **not** in the BMP and should be converted to a Unicode escape. */ export declare const isNotBmp: Filter; /** * A {@link Filter} that returns whether the specified Unicode `code` point is valid in Latin-1 (ISO 8859-1) encoding. * * Latin-1 covers code points 0x00-0xFF (0-255). * * @param code The Unicode code unit to be checked. * @return A truthy value if the code point is valid in Latin-1 encoding and should be converted to a Unicode escape. */ export declare const isLatin1: Filter; /** * A {@link Filter} that returns whether the specified Unicode `code` point is **not** valid in Latin-1 (ISO 8859-1) * encoding. * * Latin-1 covers code points 0x00-0xFF (0-255). * * @param code The Unicode code unit to be checked. * @return A truthy value if the code point is **not** valid in Latin-1 encoding and should be converted to a Unicode * escape. */ export declare const isNotLatin1: Filter; //# sourceMappingURL=filter.d.ts.map