Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions types/d3-sankey/d3-sankey-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,19 @@ 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
// ---------------------------------------------------------------------------

// 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
Expand Down
12 changes: 6 additions & 6 deletions types/d3-sankey/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,26 +341,26 @@ export interface SankeyLayout<Data, N extends SankeyExtraProperties, L extends S
/**
* Returns the node comparison function which defaults to undefined.
*/
nodeSort(): ((a: SankeyNode<N, L>, b: SankeyNode<N, L>) => number) | undefined;
nodeSort(): ((a: SankeyNode<N, L>, b: SankeyNode<N, L>) => 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<N, L>, b: SankeyNode<N, L>) => number | undefined | null): this;
nodeSort(compare: ((a: SankeyNode<N, L>, b: SankeyNode<N, L>) => number) | undefined | null): this;

/**
* Returns the link comparison function which defaults to undefined.
*/
linkSort(): ((a: SankeyLink<N, L>, b: SankeyLink<N, L>) => number) | undefined;
linkSort(): ((a: SankeyLink<N, L>, b: SankeyLink<N, L>) => 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<N, L>, b: SankeyLink<N, L>) => number | undefined | null): this;
linkSort(compare: ((a: SankeyLink<N, L>, b: SankeyLink<N, L>) => number) | undefined | null): this;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions types/unicode-name/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!**/*.d.ts
!**/*.d.cts
!**/*.d.mts
!**/*.d.*.ts
139 changes: 139 additions & 0 deletions types/unicode-name/index.d.ts
Original file line number Diff line number Diff line change
@@ -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:
* <type-hex>, e.g. <control-0009> for the tab character or
* <noncharacter-FFFFF> 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;
25 changes: 25 additions & 0 deletions types/unicode-name/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
19 changes: 19 additions & 0 deletions types/unicode-name/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
36 changes: 36 additions & 0 deletions types/unicode-name/unicode-name-tests.ts
Original file line number Diff line number Diff line change
@@ -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