diff --git a/types/d3-sankey/d3-sankey-tests.ts b/types/d3-sankey/d3-sankey-tests.ts index abc289c572750f..4f50bd53791f7d 100644 --- a/types/d3-sankey/d3-sankey-tests.ts +++ b/types/d3-sankey/d3-sankey-tests.ts @@ -278,8 +278,9 @@ num = slgDAG.iterations(); // test multiple definitions slgDAG = slgDAG.nodeSort((node: SNode) => (node.index === 0 ? 1 : -1)); -slgDAG = slgDAG.nodeSort(() => undefined); -slgDAG = slgDAG.nodeSort((node: SNode) => (node.name === "test" ? null : undefined)); +slgDAG = slgDAG.nodeSort(undefined); +slgDAG = slgDAG.nodeSort(null); +slgDAG = slgDAG.nodeSort((node: SNode) => (node.name === "test" ? 0 : -1)); // --------------------------------------------------------------------------- // LinkSort @@ -287,8 +288,9 @@ slgDAG = slgDAG.nodeSort((node: SNode) => (node.name === "test" ? null : undefin // test multiple definitions slgDAG = slgDAG.linkSort((link: SLink) => (link.index === 0 ? 1 : -1)); -slgDAG = slgDAG.linkSort(() => undefined); -slgDAG = slgDAG.linkSort((link: SLink) => (link.source > link.target ? null : undefined)); +slgDAG = slgDAG.linkSort(undefined); +slgDAG = slgDAG.linkSort(null); +slgDAG = slgDAG.linkSort((link: SLink) => (link.source > link.target ? 0 : -1)); // --------------------------------------------------------------------------- // Node Id diff --git a/types/d3-sankey/index.d.ts b/types/d3-sankey/index.d.ts index 616605b78850db..fd28491b4d37c3 100644 --- a/types/d3-sankey/index.d.ts +++ b/types/d3-sankey/index.d.ts @@ -341,26 +341,26 @@ export interface SankeyLayout, b: SankeyNode) => number) | undefined; + nodeSort(): ((a: SankeyNode, b: SankeyNode) => number) | undefined | null; /** * Set the node comparison function and return this Sankey layout generator. * - * @param compare Node comparison function. + * @param compare Node comparison function. If `null`, the order is fixed by the input. */ - nodeSort(compare: (a: SankeyNode, b: SankeyNode) => number | undefined | null): this; + nodeSort(compare: ((a: SankeyNode, b: SankeyNode) => number) | undefined | null): this; /** * Returns the link comparison function which defaults to undefined. */ - linkSort(): ((a: SankeyLink, b: SankeyLink) => number) | undefined; + linkSort(): ((a: SankeyLink, b: SankeyLink) => number) | undefined | null; /** * Set the link comparison function and return this Sankey layout generator. * - * @param compare Link comparison function. + * @param compare Link comparison function. If `null`, the order is fixed by the input. */ - linkSort(compare: (a: SankeyLink, b: SankeyLink) => number | undefined | null): this; + linkSort(compare: ((a: SankeyLink, b: SankeyLink) => number) | undefined | null): this; } /** diff --git a/types/unicode-name/.npmignore b/types/unicode-name/.npmignore new file mode 100644 index 00000000000000..93e307400a5456 --- /dev/null +++ b/types/unicode-name/.npmignore @@ -0,0 +1,5 @@ +* +!**/*.d.ts +!**/*.d.cts +!**/*.d.mts +!**/*.d.*.ts diff --git a/types/unicode-name/index.d.ts b/types/unicode-name/index.d.ts new file mode 100644 index 00000000000000..c9d3334e679c07 --- /dev/null +++ b/types/unicode-name/index.d.ts @@ -0,0 +1,139 @@ +/** + * Aliases assigned to a Unicode codepoint, organized by category. + */ +export interface UnicodeAliases { + /** Correction aliases */ + correction?: string[]; + /** Control character aliases */ + control?: string[]; + /** Figment aliases */ + figment?: string[]; + /** Alternate name aliases */ + alternate?: string[]; + /** Abbreviation aliases */ + abbreviation?: string[]; +} + +/** + * Returns the name that has been assigned to a Unicode codepoint. + * + * Please note: + * Some common codepoints do not have a name (e.g. C0 control characters like \n) + * + * Also see: + * - unicodeCorrectName(char) - Checks if there is a corrected name first, if not, + * fallbacks to this method + * - unicodeReadableName(char) - Displays correct name or an applicable alias + * + * @param char Single character string or codepoint + * @returns Name of character or undefined + */ +export function unicodeBaseName(char: string | number): string | undefined; + +/** + * Returns the name that has been assigned to a Unicode codepoint, but if the codepoint + * has a correction alias, use this instead. + * + * Please note: + * Some common codepoints do not have a name (e.g. C0 control characters like \n) + * + * Also see: + * - unicodeReadableName(char) - Displays correct name or an applicable alias + * + * @param char Single character string or codepoint + * @returns Corrected name of character or undefined + */ +export function unicodeCorrectName(char: string | number): string | undefined; + +/** + * Returns the aliases that have been assigned to a Unicode codepoint. + * + * Aliases can be of these categories (multiple aliases possible): + * + * - correction + * - control + * - figment + * - alternate + * - abbreviation + * + * @param char Single character string or codepoint + * @returns Object containing aliases for this Unicode codepoint + */ +export function unicodeAliases(char: string | number): UnicodeAliases | undefined; + +/** + * Determine the basic type of codepoints. Required to be able to get the + * Unicode label of a codepoint. This can be one of: + * + * - Graphic + * - Format + * - Control + * - Private-use + * - Surrogate + * - Noncharacter + * - Reserved + * + * @param char Single character string or codepoint + * @returns Codepoint type + */ +export function unicodeType(char: string | number): string | undefined; + +/** + * Returns a label of a codepoint in the following format: + * , e.g. for the tab character or + * for U+FFFFF + * + * It is only assigned to codepoints of a type other than + * "Graphic" or "Format" + * + * @param char Single character string or codepoint + * @returns A generic label for this codepoint + */ +export function unicodeLabel(char: string | number): string | undefined; + +/** + * Returns the best readable representation of a codepoint. + * + * 1) It is the corrected name of a the codepoint (if one exists) + * 2) or it is an appropriate aliase (if one exists) + * 3) or it is the codepoint label + * + * @param char Single character string or codepoint + * @returns Unicode name, alias, or label for this character + */ +export function unicodeReadableName(char: string | number): string | undefined; + +/** + * Returns the name of a character that is made of a codepoint sequence (= more than + * one codepoint involved), if one exists. + * + * @param char Single character string made of multiple codepoints + * @returns Unicode sequence name + */ +export function unicodeSequenceName(char: string): string | undefined; + +/** + * Returns the name of a character that is made of a codepoint sequence (= more than + * one codepoint involved), if one exists. + * + * Differently from unicodeSequenceName(char), it will only consider Emoji ZWJ sequences + * that are fully qualified, meaning they all required variation selectors (VS16) in place + * + * @param char Single character string made of multiple codepoints + * @returns Unicode sequence name + */ +export function unicodeQualifiedSequenceName(char: string): string | undefined; + +/** + * Returns the best name for the Unicode character (codepoint or codepoint sequence). + * + * At first, it will check if the codepoint sequence has a name, e.g. for + * Emoji that are build up using multiple codepoints using unicodeSequenceName(char) + * + * If none is found, will use the unicodeReadableName(char) function to retrieve + * the best name for that codepoint. + * + * @param char Single character string or codepoint + * @returns Name of character + */ +export function unicodeName(char: string | number): string | undefined; diff --git a/types/unicode-name/package.json b/types/unicode-name/package.json new file mode 100644 index 00000000000000..c9b1be87bea36a --- /dev/null +++ b/types/unicode-name/package.json @@ -0,0 +1,25 @@ +{ + "private": true, + "name": "@types/unicode-name", + "version": "1.1.9999", + "projects": [ + "https://github.com/janlelis/unicode-name.js" + ], + "type": "module", + "exports": { + ".": { + "types": { + "default": "./index.d.ts" + } + } + }, + "devDependencies": { + "@types/unicode-name": "workspace:." + }, + "owners": [ + { + "name": "John Clow", + "githubUsername": "gamrix" + } + ] +} diff --git a/types/unicode-name/tsconfig.json b/types/unicode-name/tsconfig.json new file mode 100644 index 00000000000000..016242a72daf02 --- /dev/null +++ b/types/unicode-name/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "node16", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "unicode-name-tests.ts" + ] +} diff --git a/types/unicode-name/unicode-name-tests.ts b/types/unicode-name/unicode-name-tests.ts new file mode 100644 index 00000000000000..ad8ff2dac65da3 --- /dev/null +++ b/types/unicode-name/unicode-name-tests.ts @@ -0,0 +1,36 @@ +import { + unicodeAliases, + unicodeBaseName, + unicodeCorrectName, + unicodeLabel, + unicodeName, + unicodeQualifiedSequenceName, + unicodeReadableName, + unicodeSequenceName, + unicodeType, +} from "unicode-name"; + +// Test string parameter +unicodeName("A"); // $ExpectType string | undefined +unicodeBaseName("🚡"); // $ExpectType string | undefined +unicodeCorrectName("Ƣ"); // $ExpectType string | undefined + +// Test number parameter +unicodeName(65); // $ExpectType string | undefined +unicodeBaseName(48); // $ExpectType string | undefined + +// Test aliases interface +const aliases = unicodeAliases("\0"); +if (aliases) { + aliases.control; // $ExpectType string[] | undefined + aliases.abbreviation; // $ExpectType string[] | undefined +} + +// Test other functions +unicodeType("A"); // $ExpectType string | undefined +unicodeLabel("\0"); // $ExpectType string | undefined +unicodeReadableName("A"); // $ExpectType string | undefined + +// Test sequence functions (string only) +unicodeSequenceName("🇺🇳"); // $ExpectType string | undefined +unicodeQualifiedSequenceName("‼︎"); // $ExpectType string | undefined