name-tools 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,80 @@
1
+ /**
2
+ * GenderDB - Efficient gender probability lookup using a binary trie structure.
3
+ *
4
+ * This class provides O(k) name lookup where k is the length of the name.
5
+ * It uses a compact binary format with implicit child pointers for minimal memory usage.
6
+ *
7
+ * Binary format:
8
+ * - Header: 8 bytes (Magic 'GNDR' + node count)
9
+ * - Nodes: 4 bytes each (packed char, flags, sibling pointer)
10
+ * - Probs: 1 byte each (gender probability 1-255)
11
+ */
12
+ interface GenderResult {
13
+ /** Probability that the name is male (0.0 = female, 1.0 = male) */
14
+ maleProbability: number;
15
+ /** Raw probability value from database (1-255) */
16
+ rawValue: number;
17
+ /** Whether the name was found in the database */
18
+ found: true;
19
+ }
20
+ interface GenderNotFound {
21
+ found: false;
22
+ }
23
+ type GenderLookupResult = GenderResult | GenderNotFound;
24
+ /**
25
+ * Gender probability database using optimized binary trie storage.
26
+ */
27
+ declare class GenderDB {
28
+ private nodes;
29
+ private probs;
30
+ private readonly nodeCount;
31
+ /**
32
+ * Create a GenderDB instance from a binary ArrayBuffer.
33
+ * @param buffer - ArrayBuffer containing the binary trie data
34
+ */
35
+ constructor(buffer: ArrayBuffer);
36
+ /**
37
+ * Get the number of nodes in the trie.
38
+ */
39
+ get size(): number;
40
+ /**
41
+ * Look up the male probability for a given name.
42
+ *
43
+ * @param name - The first name to look up (case-insensitive)
44
+ * @returns GenderLookupResult with probability if found, or { found: false }
45
+ */
46
+ lookup(name: string): GenderLookupResult;
47
+ /**
48
+ * Convenience method to get male probability as a number.
49
+ * Returns null if name not found.
50
+ *
51
+ * @param name - The first name to look up
52
+ * @returns Male probability (0.0-1.0) or null if not found
53
+ */
54
+ getMaleProbability(name: string): number | null;
55
+ /**
56
+ * Convenience method to get female probability as a number.
57
+ * Returns null if name not found.
58
+ *
59
+ * @param name - The first name to look up
60
+ * @returns Female probability (0.0-1.0) or null if not found
61
+ */
62
+ getFemaleProbability(name: string): number | null;
63
+ /**
64
+ * Make an informed guess about the likely gender based on probability threshold.
65
+ *
66
+ * @param name - The first name to look up
67
+ * @param threshold - Confidence threshold for guessing (default 0.8, meaning 80% confidence required)
68
+ * @returns 'male', 'female', 'unknown', or null if name not found in database
69
+ */
70
+ guessGender(name: string, threshold?: number): 'male' | 'female' | 'unknown' | null;
71
+ /**
72
+ * Check if a name exists in the database.
73
+ *
74
+ * @param name - The first name to check
75
+ * @returns true if the name exists in the database
76
+ */
77
+ has(name: string): boolean;
78
+ }
79
+
80
+ export { GenderDB as G, type GenderResult as a, type GenderNotFound as b, type GenderLookupResult as c };
@@ -0,0 +1,80 @@
1
+ /**
2
+ * GenderDB - Efficient gender probability lookup using a binary trie structure.
3
+ *
4
+ * This class provides O(k) name lookup where k is the length of the name.
5
+ * It uses a compact binary format with implicit child pointers for minimal memory usage.
6
+ *
7
+ * Binary format:
8
+ * - Header: 8 bytes (Magic 'GNDR' + node count)
9
+ * - Nodes: 4 bytes each (packed char, flags, sibling pointer)
10
+ * - Probs: 1 byte each (gender probability 1-255)
11
+ */
12
+ interface GenderResult {
13
+ /** Probability that the name is male (0.0 = female, 1.0 = male) */
14
+ maleProbability: number;
15
+ /** Raw probability value from database (1-255) */
16
+ rawValue: number;
17
+ /** Whether the name was found in the database */
18
+ found: true;
19
+ }
20
+ interface GenderNotFound {
21
+ found: false;
22
+ }
23
+ type GenderLookupResult = GenderResult | GenderNotFound;
24
+ /**
25
+ * Gender probability database using optimized binary trie storage.
26
+ */
27
+ declare class GenderDB {
28
+ private nodes;
29
+ private probs;
30
+ private readonly nodeCount;
31
+ /**
32
+ * Create a GenderDB instance from a binary ArrayBuffer.
33
+ * @param buffer - ArrayBuffer containing the binary trie data
34
+ */
35
+ constructor(buffer: ArrayBuffer);
36
+ /**
37
+ * Get the number of nodes in the trie.
38
+ */
39
+ get size(): number;
40
+ /**
41
+ * Look up the male probability for a given name.
42
+ *
43
+ * @param name - The first name to look up (case-insensitive)
44
+ * @returns GenderLookupResult with probability if found, or { found: false }
45
+ */
46
+ lookup(name: string): GenderLookupResult;
47
+ /**
48
+ * Convenience method to get male probability as a number.
49
+ * Returns null if name not found.
50
+ *
51
+ * @param name - The first name to look up
52
+ * @returns Male probability (0.0-1.0) or null if not found
53
+ */
54
+ getMaleProbability(name: string): number | null;
55
+ /**
56
+ * Convenience method to get female probability as a number.
57
+ * Returns null if name not found.
58
+ *
59
+ * @param name - The first name to look up
60
+ * @returns Female probability (0.0-1.0) or null if not found
61
+ */
62
+ getFemaleProbability(name: string): number | null;
63
+ /**
64
+ * Make an informed guess about the likely gender based on probability threshold.
65
+ *
66
+ * @param name - The first name to look up
67
+ * @param threshold - Confidence threshold for guessing (default 0.8, meaning 80% confidence required)
68
+ * @returns 'male', 'female', 'unknown', or null if name not found in database
69
+ */
70
+ guessGender(name: string, threshold?: number): 'male' | 'female' | 'unknown' | null;
71
+ /**
72
+ * Check if a name exists in the database.
73
+ *
74
+ * @param name - The first name to check
75
+ * @returns true if the name exists in the database
76
+ */
77
+ has(name: string): boolean;
78
+ }
79
+
80
+ export { GenderDB as G, type GenderResult as a, type GenderNotFound as b, type GenderLookupResult as c };
@@ -0,0 +1,31 @@
1
+ import { G as GenderDB } from './GenderDB-Co_GybwH.mjs';
2
+ export { c as GenderLookupResult, b as GenderNotFound, a as GenderResult } from './GenderDB-Co_GybwH.mjs';
3
+
4
+ /**
5
+ * Full gender probability dataset (100% of names meeting minimum threshold).
6
+ *
7
+ * This is the largest dataset with all names that have at least 10 occurrences
8
+ * across all years in the SSA database.
9
+ *
10
+ * Import this for maximum coverage at the cost of larger bundle size.
11
+ *
12
+ * Usage:
13
+ * ```typescript
14
+ * import { createGenderDB } from 'name-tools/gender/all';
15
+ * const db = createGenderDB();
16
+ * const prob = db.getMaleProbability('Ashley');
17
+ * ```
18
+ */
19
+
20
+ /**
21
+ * Create a GenderDB instance with the full dataset.
22
+ *
23
+ * @param options.shared - If true (default), returns a shared singleton instance.
24
+ * If false, creates a new instance each time.
25
+ * @returns GenderDB instance
26
+ */
27
+ declare function createGenderDB(options?: {
28
+ shared?: boolean;
29
+ }): GenderDB;
30
+
31
+ export { GenderDB, createGenderDB };
@@ -0,0 +1,31 @@
1
+ import { G as GenderDB } from './GenderDB-Co_GybwH.js';
2
+ export { c as GenderLookupResult, b as GenderNotFound, a as GenderResult } from './GenderDB-Co_GybwH.js';
3
+
4
+ /**
5
+ * Full gender probability dataset (100% of names meeting minimum threshold).
6
+ *
7
+ * This is the largest dataset with all names that have at least 10 occurrences
8
+ * across all years in the SSA database.
9
+ *
10
+ * Import this for maximum coverage at the cost of larger bundle size.
11
+ *
12
+ * Usage:
13
+ * ```typescript
14
+ * import { createGenderDB } from 'name-tools/gender/all';
15
+ * const db = createGenderDB();
16
+ * const prob = db.getMaleProbability('Ashley');
17
+ * ```
18
+ */
19
+
20
+ /**
21
+ * Create a GenderDB instance with the full dataset.
22
+ *
23
+ * @param options.shared - If true (default), returns a shared singleton instance.
24
+ * If false, creates a new instance each time.
25
+ * @returns GenderDB instance
26
+ */
27
+ declare function createGenderDB(options?: {
28
+ shared?: boolean;
29
+ }): GenderDB;
30
+
31
+ export { GenderDB, createGenderDB };