name-to-gender 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Michael Cummings
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # name-to-gender
2
+
3
+ Guess the gender of a first name from US Social Security birth data. Returns a
4
+ **probability** and the **raw birth counts** behind every guess, not just a
5
+ label. TypeScript-first, ESM + CJS, **zero runtime dependencies**.
6
+
7
+ ```ts
8
+ import { guessGender } from "name-to-gender";
9
+
10
+ guessGender("Adam");
11
+ // {
12
+ // gender: "male",
13
+ // probability: 0.996,
14
+ // counts: { male: 523494, female: 2002 },
15
+ // name: "adam"
16
+ // }
17
+ ```
18
+
19
+ ## Why another one?
20
+
21
+ The existing name-gender packages are either inaccurate or unmaintained. Many of
22
+ them tag common male names like Adam and Chris as female, and none of the actively-maintained ones return a confidence score you can threshold on.
23
+
24
+ | package | data | last updated | confidence | types |
25
+ | ---------------------------- | ------------- | ------------ | ---------- | ------- |
26
+ | `gender` | US Census | 2013 | yes | no |
27
+ | `gender-guess` | SSA 1930–2013 | 2014 | yes | no |
28
+ | `gender-detection` | mixed | 2018 | **no** | no |
29
+ | `gender-detection-from-name` | mixed | 2025 | **no** | no |
30
+ | **`name-to-gender`** | **US SSA** | **fresh** | **yes** | **yes** |
31
+
32
+ ## Install
33
+
34
+ ```sh
35
+ npm install name-to-gender
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ### `guessGender(name, options?)`
41
+
42
+ ```ts
43
+ import { guessGender } from "name-to-gender";
44
+
45
+ guessGender("Mary");
46
+ // { gender: "female", probability: 0.995, counts: { male: 7732, female: 1467208 }, name: "mary" }
47
+
48
+ // Messy input is handled: full names, casing, accents, and punctuation.
49
+ guessGender(" José Martinez ").gender; // "male" (uses the first token, folds accents)
50
+ guessGender("::Jenni♥fer::").name; // "jennifer"
51
+
52
+ // Names not in the dataset return "unknown" with a zero probability.
53
+ guessGender("Xyzzy");
54
+ // { gender: "unknown", probability: 0, counts: { male: 0, female: 0 }, name: "xyzzy" }
55
+ ```
56
+
57
+ #### Thresholding unisex names
58
+
59
+ Some names are unisex. Pass `minProbability` to treat low-confidence
60
+ guesses as `"unknown"` while still seeing the underlying numbers:
61
+
62
+ ```ts
63
+ guessGender("Casey"); // gender: "male" (≈59% male)
64
+ guessGender("Casey", { minProbability: 0.9 }); // gender: "unknown", probability: 0.59, counts: {...}
65
+ ```
66
+
67
+ ### `isMale(name, options?)` / `isFemale(name, options?)`
68
+
69
+ Convenience booleans. Both return `false` for unknown or below-threshold names.
70
+
71
+ ```ts
72
+ import { isMale, isFemale } from "name-to-gender";
73
+
74
+ isMale("Ryan"); // true
75
+ isFemale("Ryan"); // false
76
+ ```
77
+
78
+ ### Result shape
79
+
80
+ ```ts
81
+ interface GenderGuess {
82
+ gender: "male" | "female" | "unknown";
83
+ probability: number; // P(gender), in [0.5, 1]; 0 when unknown
84
+ counts: { male: number; female: number };
85
+ name: string | null; // the normalized name that was looked up
86
+ }
87
+ ```
88
+
89
+ ## How it works
90
+
91
+ `name-to-gender` is **data-driven, not rule-based**. It normalizes the input to
92
+ a first-name token, looks it up in a table of all-time US births by name and
93
+ sex, and reports the majority sex along with its share. There are no `"ends in
94
+ -a → female"` heuristics, which is exactly what makes the older packages fail on
95
+ names like Adam and Joshua.
96
+
97
+ The dataset is built from the public-domain
98
+ [US Social Security Administration baby-names data](https://www.ssa.gov/oact/babynames/).
99
+ It works best for US/English-context names. See
100
+ [`CONTRIBUTING.md`](./CONTRIBUTING.md) for how to regenerate it from the latest
101
+ SSA release.
102
+
103
+ ## License
104
+
105
+ MIT © Michael Cummings