us-state-flag-icons 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.
Files changed (295) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/LICENSE +21 -0
  3. package/README.md +248 -0
  4. package/flags.css +65 -0
  5. package/index.cjs +21 -0
  6. package/index.d.cts +15 -0
  7. package/index.d.ts +15 -0
  8. package/index.js +21 -0
  9. package/package.json +556 -0
  10. package/react/AK.d.ts +11 -0
  11. package/react/AK.js +81 -0
  12. package/react/AL.d.ts +11 -0
  13. package/react/AL.js +21 -0
  14. package/react/AR.d.ts +11 -0
  15. package/react/AR.js +200 -0
  16. package/react/AS.d.ts +11 -0
  17. package/react/AS.js +213 -0
  18. package/react/AZ.d.ts +11 -0
  19. package/react/AZ.js +31 -0
  20. package/react/CA.d.ts +11 -0
  21. package/react/CA.js +61 -0
  22. package/react/CO.d.ts +11 -0
  23. package/react/CO.js +28 -0
  24. package/react/CT.d.ts +11 -0
  25. package/react/CT.js +1184 -0
  26. package/react/DC.d.ts +11 -0
  27. package/react/DC.js +51 -0
  28. package/react/DE.d.ts +11 -0
  29. package/react/DE.js +1520 -0
  30. package/react/FL.d.ts +11 -0
  31. package/react/FL.js +232 -0
  32. package/react/GA.d.ts +11 -0
  33. package/react/GA.js +427 -0
  34. package/react/GU.d.ts +11 -0
  35. package/react/GU.js +128 -0
  36. package/react/HI.d.ts +11 -0
  37. package/react/HI.js +47 -0
  38. package/react/IA.d.ts +11 -0
  39. package/react/IA.js +52 -0
  40. package/react/ID.d.ts +11 -0
  41. package/react/ID.js +277 -0
  42. package/react/IL.d.ts +11 -0
  43. package/react/IL.js +547 -0
  44. package/react/IN.d.ts +11 -0
  45. package/react/IN.js +80 -0
  46. package/react/KS.d.ts +11 -0
  47. package/react/KS.js +1714 -0
  48. package/react/KY.d.ts +11 -0
  49. package/react/KY.js +639 -0
  50. package/react/LA.d.ts +11 -0
  51. package/react/LA.js +380 -0
  52. package/react/MA.d.ts +11 -0
  53. package/react/MA.js +121 -0
  54. package/react/MD.d.ts +11 -0
  55. package/react/MD.js +54 -0
  56. package/react/ME.d.ts +11 -0
  57. package/react/ME.js +2156 -0
  58. package/react/MI.d.ts +11 -0
  59. package/react/MI.js +409 -0
  60. package/react/MN.d.ts +11 -0
  61. package/react/MN.js +41 -0
  62. package/react/MO.d.ts +11 -0
  63. package/react/MO.js +2206 -0
  64. package/react/MP.d.ts +11 -0
  65. package/react/MP.js +1734 -0
  66. package/react/MS.d.ts +11 -0
  67. package/react/MS.js +35 -0
  68. package/react/MT.d.ts +11 -0
  69. package/react/MT.js +296 -0
  70. package/react/NC.d.ts +11 -0
  71. package/react/NC.js +537 -0
  72. package/react/ND.d.ts +11 -0
  73. package/react/ND.js +1371 -0
  74. package/react/NE.d.ts +11 -0
  75. package/react/NE.js +3316 -0
  76. package/react/NH.d.ts +11 -0
  77. package/react/NH.js +1337 -0
  78. package/react/NJ.d.ts +11 -0
  79. package/react/NJ.js +2537 -0
  80. package/react/NM.d.ts +11 -0
  81. package/react/NM.js +29 -0
  82. package/react/NV.d.ts +11 -0
  83. package/react/NV.js +183 -0
  84. package/react/NY.d.ts +11 -0
  85. package/react/NY.js +5853 -0
  86. package/react/OH.d.ts +11 -0
  87. package/react/OH.js +99 -0
  88. package/react/OK.d.ts +11 -0
  89. package/react/OK.js +1136 -0
  90. package/react/OR.d.ts +11 -0
  91. package/react/OR.js +39 -0
  92. package/react/PA.d.ts +11 -0
  93. package/react/PA.js +96 -0
  94. package/react/PR.d.ts +11 -0
  95. package/react/PR.js +25 -0
  96. package/react/RI.d.ts +11 -0
  97. package/react/RI.js +97 -0
  98. package/react/SC.d.ts +11 -0
  99. package/react/SC.js +50 -0
  100. package/react/SD.d.ts +11 -0
  101. package/react/SD.js +150 -0
  102. package/react/TN.d.ts +11 -0
  103. package/react/TN.js +66 -0
  104. package/react/TX.d.ts +11 -0
  105. package/react/TX.js +48 -0
  106. package/react/UT.d.ts +11 -0
  107. package/react/UT.js +37 -0
  108. package/react/VA.d.ts +11 -0
  109. package/react/VA.js +450 -0
  110. package/react/VI.d.ts +11 -0
  111. package/react/VI.js +331 -0
  112. package/react/VT.d.ts +11 -0
  113. package/react/VT.js +560 -0
  114. package/react/WA.d.ts +11 -0
  115. package/react/WA.js +506 -0
  116. package/react/WI.d.ts +11 -0
  117. package/react/WI.js +324 -0
  118. package/react/WV.d.ts +11 -0
  119. package/react/WV.js +3838 -0
  120. package/react/WY.d.ts +11 -0
  121. package/react/WY.js +78 -0
  122. package/react/index.d.ts +64 -0
  123. package/react/index.js +56 -0
  124. package/source/states.json +562 -0
  125. package/source/states.json.js +1 -0
  126. package/string/AK.d.ts +2 -0
  127. package/string/AK.js +1 -0
  128. package/string/AL.d.ts +2 -0
  129. package/string/AL.js +1 -0
  130. package/string/AR.d.ts +2 -0
  131. package/string/AR.js +1 -0
  132. package/string/AS.d.ts +2 -0
  133. package/string/AS.js +1 -0
  134. package/string/AZ.d.ts +2 -0
  135. package/string/AZ.js +1 -0
  136. package/string/CA.d.ts +2 -0
  137. package/string/CA.js +1 -0
  138. package/string/CO.d.ts +2 -0
  139. package/string/CO.js +1 -0
  140. package/string/CT.d.ts +2 -0
  141. package/string/CT.js +1 -0
  142. package/string/DC.d.ts +2 -0
  143. package/string/DC.js +1 -0
  144. package/string/DE.d.ts +2 -0
  145. package/string/DE.js +1 -0
  146. package/string/FL.d.ts +2 -0
  147. package/string/FL.js +1 -0
  148. package/string/GA.d.ts +2 -0
  149. package/string/GA.js +1 -0
  150. package/string/GU.d.ts +2 -0
  151. package/string/GU.js +1 -0
  152. package/string/HI.d.ts +2 -0
  153. package/string/HI.js +1 -0
  154. package/string/IA.d.ts +2 -0
  155. package/string/IA.js +1 -0
  156. package/string/ID.d.ts +2 -0
  157. package/string/ID.js +1 -0
  158. package/string/IL.d.ts +2 -0
  159. package/string/IL.js +1 -0
  160. package/string/IN.d.ts +2 -0
  161. package/string/IN.js +1 -0
  162. package/string/KS.d.ts +2 -0
  163. package/string/KS.js +1 -0
  164. package/string/KY.d.ts +2 -0
  165. package/string/KY.js +1 -0
  166. package/string/LA.d.ts +2 -0
  167. package/string/LA.js +1 -0
  168. package/string/MA.d.ts +2 -0
  169. package/string/MA.js +1 -0
  170. package/string/MD.d.ts +2 -0
  171. package/string/MD.js +1 -0
  172. package/string/ME.d.ts +2 -0
  173. package/string/ME.js +1 -0
  174. package/string/MI.d.ts +2 -0
  175. package/string/MI.js +1 -0
  176. package/string/MN.d.ts +2 -0
  177. package/string/MN.js +1 -0
  178. package/string/MO.d.ts +2 -0
  179. package/string/MO.js +1 -0
  180. package/string/MP.d.ts +2 -0
  181. package/string/MP.js +1 -0
  182. package/string/MS.d.ts +2 -0
  183. package/string/MS.js +1 -0
  184. package/string/MT.d.ts +2 -0
  185. package/string/MT.js +1 -0
  186. package/string/NC.d.ts +2 -0
  187. package/string/NC.js +1 -0
  188. package/string/ND.d.ts +2 -0
  189. package/string/ND.js +1 -0
  190. package/string/NE.d.ts +2 -0
  191. package/string/NE.js +1 -0
  192. package/string/NH.d.ts +2 -0
  193. package/string/NH.js +1 -0
  194. package/string/NJ.d.ts +2 -0
  195. package/string/NJ.js +1 -0
  196. package/string/NM.d.ts +2 -0
  197. package/string/NM.js +1 -0
  198. package/string/NV.d.ts +2 -0
  199. package/string/NV.js +1 -0
  200. package/string/NY.d.ts +2 -0
  201. package/string/NY.js +1 -0
  202. package/string/OH.d.ts +2 -0
  203. package/string/OH.js +1 -0
  204. package/string/OK.d.ts +2 -0
  205. package/string/OK.js +1 -0
  206. package/string/OR.d.ts +2 -0
  207. package/string/OR.js +1 -0
  208. package/string/PA.d.ts +2 -0
  209. package/string/PA.js +1 -0
  210. package/string/PR.d.ts +2 -0
  211. package/string/PR.js +1 -0
  212. package/string/RI.d.ts +2 -0
  213. package/string/RI.js +1 -0
  214. package/string/SC.d.ts +2 -0
  215. package/string/SC.js +1 -0
  216. package/string/SD.d.ts +2 -0
  217. package/string/SD.js +1 -0
  218. package/string/TN.d.ts +2 -0
  219. package/string/TN.js +1 -0
  220. package/string/TX.d.ts +2 -0
  221. package/string/TX.js +1 -0
  222. package/string/UT.d.ts +2 -0
  223. package/string/UT.js +1 -0
  224. package/string/VA.d.ts +2 -0
  225. package/string/VA.js +1 -0
  226. package/string/VI.d.ts +2 -0
  227. package/string/VI.js +1 -0
  228. package/string/VT.d.ts +2 -0
  229. package/string/VT.js +1 -0
  230. package/string/WA.d.ts +2 -0
  231. package/string/WA.js +1 -0
  232. package/string/WI.d.ts +2 -0
  233. package/string/WI.js +1 -0
  234. package/string/WV.d.ts +2 -0
  235. package/string/WV.js +1 -0
  236. package/string/WY.d.ts +2 -0
  237. package/string/WY.js +1 -0
  238. package/string/index.d.ts +56 -0
  239. package/string/index.js +56 -0
  240. package/svg/AK.svg +1 -0
  241. package/svg/AL.svg +1 -0
  242. package/svg/AR.svg +1 -0
  243. package/svg/AS.svg +1 -0
  244. package/svg/AZ.svg +1 -0
  245. package/svg/CA.svg +1 -0
  246. package/svg/CO.svg +1 -0
  247. package/svg/CT.svg +1 -0
  248. package/svg/DC.svg +1 -0
  249. package/svg/DE.svg +1 -0
  250. package/svg/FL.svg +1 -0
  251. package/svg/GA.svg +1 -0
  252. package/svg/GU.svg +1 -0
  253. package/svg/HI.svg +1 -0
  254. package/svg/IA.svg +1 -0
  255. package/svg/ID.svg +1 -0
  256. package/svg/IL.svg +1 -0
  257. package/svg/IN.svg +1 -0
  258. package/svg/KS.svg +1 -0
  259. package/svg/KY.svg +1 -0
  260. package/svg/LA.svg +1 -0
  261. package/svg/MA.svg +1 -0
  262. package/svg/MD.svg +1 -0
  263. package/svg/ME.svg +1 -0
  264. package/svg/MI.svg +1 -0
  265. package/svg/MN.svg +1 -0
  266. package/svg/MO.svg +1 -0
  267. package/svg/MP.svg +1 -0
  268. package/svg/MS.svg +1 -0
  269. package/svg/MT.svg +1 -0
  270. package/svg/NC.svg +1 -0
  271. package/svg/ND.svg +1 -0
  272. package/svg/NE.svg +1 -0
  273. package/svg/NH.svg +1 -0
  274. package/svg/NJ.svg +1 -0
  275. package/svg/NM.svg +1 -0
  276. package/svg/NV.svg +1 -0
  277. package/svg/NY.svg +1 -0
  278. package/svg/OH.svg +1 -0
  279. package/svg/OK.svg +1 -0
  280. package/svg/OR.svg +1 -0
  281. package/svg/PA.svg +1 -0
  282. package/svg/PR.svg +1 -0
  283. package/svg/RI.svg +1 -0
  284. package/svg/SC.svg +1 -0
  285. package/svg/SD.svg +1 -0
  286. package/svg/TN.svg +1 -0
  287. package/svg/TX.svg +1 -0
  288. package/svg/UT.svg +1 -0
  289. package/svg/VA.svg +1 -0
  290. package/svg/VI.svg +1 -0
  291. package/svg/VT.svg +1 -0
  292. package/svg/WA.svg +1 -0
  293. package/svg/WI.svg +1 -0
  294. package/svg/WV.svg +1 -0
  295. package/svg/WY.svg +1 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0
4
+
5
+ - Initial release: SVG, React, string, and CSS flags for the 50 US states, DC,
6
+ and the inhabited territories.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mo-Ibra
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,248 @@
1
+ # us-state-flag-icons
2
+
3
+ [![npm version](https://img.shields.io/npm/v/us-state-flag-icons.svg)](https://www.npmjs.com/package/us-state-flag-icons)
4
+ [![npm downloads](https://img.shields.io/npm/dm/us-state-flag-icons.svg)](https://www.npmjs.com/package/us-state-flag-icons)
5
+
6
+ Vector flags for the 50 US states, the District of Columbia, and the inhabited
7
+ territories, available as plain SVG files, React components, JS strings, and CSS
8
+ classes.
9
+
10
+ - Covers all 50 states plus `DC`, `PR`, `GU`, `VI`, `AS`, and `MP`.
11
+ - Preserves each flag's **native aspect ratio** (state flags are not all the
12
+ same shape — Ohio is a swallowtail pennant).
13
+ - React components render an accessible `<title>` automatically.
14
+ - Tiny core API (`hasState`, `states`, `getStateName`).
15
+
16
+ > There is no Unicode/emoji equivalent for US state flags, so unlike
17
+ > `country-flag-icons` this package has no `/unicode` subpackage.
18
+
19
+ ## Install
20
+
21
+ ```
22
+ npm install us-state-flag-icons
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ### SVG files
28
+
29
+ The optimized SVGs live in the `svg/` folder of the package:
30
+
31
+ ```html
32
+ <img
33
+ alt="California"
34
+ src="https://unpkg.com/us-state-flag-icons/svg/CA.svg"
35
+ height="40"/>
36
+ ```
37
+
38
+ Or import the file path through your bundler:
39
+
40
+ ```js
41
+ import caFlagUrl from 'us-state-flag-icons/svg/CA.svg'
42
+ ```
43
+
44
+ Because flags have different aspect ratios, set only **one** of `width`/`height`
45
+ (and let the SVG scale) to avoid distortion.
46
+
47
+ ### CSS
48
+
49
+ ```js
50
+ import 'us-state-flag-icons/flags.css'
51
+ ```
52
+
53
+ ```html
54
+ <span class="flag:CA"></span>
55
+ ```
56
+
57
+ The icon height is controlled by the `--StateFlagIcon-height` CSS variable
58
+ (default `1em`), so it also follows `font-size`:
59
+
60
+ ```css
61
+ /* Global flag height. */
62
+ [class*=' flag:'],
63
+ [class^='flag:'] {
64
+ --StateFlagIcon-height: 24px;
65
+ }
66
+
67
+ /* Or per flag. */
68
+ .flag\:CA {
69
+ font-size: 24px;
70
+ }
71
+ ```
72
+
73
+ ### React
74
+
75
+ ```jsx
76
+ import { CA, TX } from 'us-state-flag-icons/react'
77
+
78
+ <CA title="California"/>
79
+ <TX title="Texas" className="my-flag"/>
80
+ ```
81
+
82
+ Every flag is also available as a per-flag default import (useful if your
83
+ bundler does not support tree-shaking):
84
+
85
+ ```jsx
86
+ import CA from 'us-state-flag-icons/react/CA'
87
+
88
+ <CA title="California"/>
89
+ ```
90
+
91
+ Passing `title` renders a `<title>` element (and `aria-labelledby`) for
92
+ accessibility. `react` is an optional peer dependency — only install it if you
93
+ use the `/react` subpackage.
94
+
95
+ ### String
96
+
97
+ ```js
98
+ import { CA } from 'us-state-flag-icons/string'
99
+
100
+ // Or the per-flag default import:
101
+ import CA from 'us-state-flag-icons/string/CA'
102
+
103
+ console.log(CA) // > '<svg xmlns="http://www.w3.org/2000/svg" ...</svg>'
104
+ ```
105
+
106
+ ## API
107
+
108
+ The core entry point is available as both ESM and CommonJS.
109
+
110
+ ```js
111
+ import { hasState, states, getStateName, stateData } from 'us-state-flag-icons'
112
+
113
+ hasState('CA') // => true
114
+ hasState('ZZ') // => false
115
+
116
+ states // => ['AK', 'AL', 'AZ', ...]
117
+
118
+ getStateName('CA') // => 'California'
119
+ getStateName('ZZ') // => undefined
120
+
121
+ stateData[0]
122
+ // => {
123
+ // code: 'AK',
124
+ // name: 'Alaska',
125
+ // width: 1416, height: 1000, aspectRatio: 1.416,
126
+ // viewBox: '0 0 1416 1000',
127
+ // license: 'Public domain',
128
+ // source: 'https://commons.wikimedia.org/wiki/File:Flag_of_Alaska.svg'
129
+ // }
130
+ ```
131
+
132
+ ### `hasState(code: string): boolean`
133
+
134
+ Whether a flag exists for a two-letter code.
135
+
136
+ ### `states: string[]`
137
+
138
+ All supported codes.
139
+
140
+ ### `getStateName(code: string): string | undefined`
141
+
142
+ The display name for a code.
143
+
144
+ ### `stateData: State[]`
145
+
146
+ The full dataset, one record per flag.
147
+
148
+ ## Aspect ratios
149
+
150
+ Unlike national flags, US state flags are **not** a uniform shape. The library
151
+ keeps each flag's native ratio and exposes it via `stateData`, so the React
152
+ components, the CSS classes, and the SVGs all scale correctly.
153
+
154
+ | Flag | Ratio | Note |
155
+ | --- | --- | --- |
156
+ | `AL`, `CA`, `TX` | 3:2 | standard |
157
+ | `OH` | 26:16 | swallowtail (non-rectangular) |
158
+ | `HI`, `NY`, `DC`, `AS`, `MP` | 2:1 | |
159
+ | `RI` | ~1.14:1 | nearly square |
160
+ | `PA` | 1.37:1 | |
161
+
162
+ There are 16 distinct aspect ratios in total.
163
+
164
+ ## Package size
165
+
166
+ The artwork is detailed (many flags contain a state seal), so the published
167
+ package is several megabytes. For comparison, `country-flag-icons` ships
168
+ simplified, hand-drawn flags at roughly 1 KB each. If package size is critical,
169
+ that simplified approach is the alternative.
170
+
171
+ The React and string subpackages are **ES modules only**; the core API also
172
+ provides a CommonJS build.
173
+
174
+ ## Licensing
175
+
176
+ - **Code:** [MIT](./LICENSE).
177
+ - **Flag artwork:** sourced from Wikimedia Commons. Almost all of it is public
178
+ domain; per-flag provenance, author, and license are recorded in
179
+ [`flags/credits.json`](./flags/credits.json). No attribution is required, but
180
+ check that file before redistribution.
181
+
182
+ ## Development
183
+
184
+ ```
185
+ npm install
186
+
187
+ # Re-download/re-curate the source SVGs (only needed to add or refresh a flag).
188
+ npm run fetch-flags
189
+
190
+ npm run build
191
+ ```
192
+
193
+ | Script | Description |
194
+ | --- | --- |
195
+ | `npm run fetch-flags` | Download + normalize the source SVGs and license metadata |
196
+ | `npm run generate-states` | Build `source/states.json` from the flags + credits |
197
+ | `npm run build` | Generate all distributable assets and the `exports` map |
198
+ | `npm test` | Unit tests (API, generated assets, React rendering) |
199
+ | `npm run test:package` | Pack the tarball, install it in a temp project, run ESM/CJS/React consumers |
200
+ | `npm run lint:package` | Validate the package with [`publint`](https://publint.dev) |
201
+ | `npm run check:types` | Validate type resolution with [Are The Types Wrong](https://arethetypeswrong.github.io) |
202
+
203
+ ### Build pipeline
204
+
205
+ ```
206
+ flags/ hand-curated source SVGs (+ credits.json)
207
+ │ optimize-flags
208
+ ▼
209
+ svg/ optimized, scalable SVGs
210
+ ├─ generate-string-flags → string/
211
+ ├─ generate-react-flags → react/
212
+ ├─ generate-css → flags.css
213
+ └─ create-flags-zip → flags.zip
214
+ source/states.json generated dataset (from flags + credits)
215
+ └─ update-package-exports → package.json "exports"/"files"
216
+ ```
217
+
218
+ ## Publishing
219
+
220
+ `npm publish` runs a full gate via `prepublishOnly`:
221
+
222
+ ```
223
+ build → unit tests → publint → Are The Types Wrong → install-the-tarball package test
224
+ ```
225
+
226
+ Before the first publish, set `repository`, `homepage`, and `bugs` in
227
+ `package.json`, and make sure the package name is available on npm.
228
+
229
+ ### Previewing the tarball
230
+
231
+ To see exactly what would be uploaded, without publishing:
232
+
233
+ ```
234
+ npm publish --dry-run --ignore-scripts
235
+ ```
236
+
237
+ `--ignore-scripts` is required because the gate itself runs `npm pack`, which
238
+ npm suppresses while it is in dry-run mode. Use `npm run prepublishOnly` to
239
+ exercise the full gate.
240
+
241
+ ### GitHub Actions
242
+
243
+ `.github/workflows/ci.yml` runs the gate on push/PR.
244
+ `.github/workflows/publish.yml` publishes on GitHub release; add an `NPM_TOKEN`
245
+ repository secret (or configure
246
+ [npm trusted publishing](https://docs.npmjs.com/trusted-publishers)) for it to
247
+ work.
248
+