@clipboard-health/usa-states

中文文档
1.7.15发布于 2026/11/05MITTypeScriptCommonJS近 30 天下载 1.6万

Canonical US state and territory list, StateCode and StateName types, and name/code normalizers.

原始使用文档
文档目录6 节
  1. Table of contents
  2. Install
  3. Usage
  4. State timezones
  5. Ordered choices and geographic exceptions
  6. Local development commands

@clipboard-health/usa-states

Canonical US state and territory list, StateCode and StateName types, and name/code normalizers.

Table of contents

Install

npm install @clipboard-health/usa-states

Usage

import {
  isStateCode,
  type StateCode,
  type StateName,
  toStateCode,
  toStateCodeSet,
  toStateName,
  US_STATES,
} from "@clipboard-health/usa-states";

US_STATES.find((state) => state.code === "CA");
// => { name: "California", code: "CA" }

function parseStateCode(value: string): StateCode | undefined {
  return isStateCode(value) ? value : undefined;
}

// Normalize a state name or code (case- and whitespace-insensitive) to a `StateCode`.
toStateCode({ value: "  california " });
// => "CA"
toStateCode({ value: "Atlantis" });
// => undefined

// Normalize a list of names or codes to a `Set<StateCode>`, dropping unknown values.
toStateCodeSet({ values: ["California", "ny", "Atlantis"] });
// => Set { "CA", "NY" }

// Normalize a state name or code (case- and whitespace-insensitive) to a canonical `StateName`.
toStateName({ value: "  california " });
// => "California"
toStateName({ value: "ca" });
// => "California"
toStateName({ value: "Atlantis" });
// => undefined

interface LabelInput {
  name: StateName;
}

function toLabel(input: LabelInput): string {
  const { name } = input;

  return `State: ${name}`;
}

Prefer storing StateCode and resolving to StateName only for display; codes are the stable representation to compare across services. Both normalizers return undefined for unrecognized input — treat that as a validation failure rather than falling back to the raw value, otherwise unnormalized input reaches storage.

State timezones

STATE_TIME_ZONES provides a frozen, nonempty list of representative IANA timezone names for each supported StateCode. getStateTimeZones normalizes a state using toStateCode and returns the complete ordered array. Callers decide which entry to use. Existing state names/codes and US_STATES objects are unchanged.

import { getStateTimeZones, STATE_TIME_ZONES } from "@clipboard-health/usa-states";

STATE_TIME_ZONES.WA;
// => ["America/Los_Angeles"]
STATE_TIME_ZONES.TN;
// => ["America/New_York", "America/Chicago"]

getStateTimeZones({ state: "  tennessee " });
// => ["America/New_York", "America/Chicago"]

getStateTimeZones({ state: "Any" });
// => []
getStateTimeZones({});
// => []

The helper accepts state?: string and returns a frozen readonly string[] directly. An omitted, blank, Any, or unrecognized state returns a frozen empty array. With exactOptionalPropertyTypes, callers should omit state when the source value is nullish instead of explicitly passing null or undefined. This package supplies timezone metadata; consumers handle selection, formatting, and conversion with an explicit timezone.

Ordered choices and geographic exceptions

The first entry prefers the timezone whose local calendar day ends earliest in UTC under current timezone rules. The ordering is fixed; zones can tie, and historical ordering can differ. Arizona's entries tie during standard time. The order expresses this preference rather than population or capital-city coverage. Use the documented order and IANA rules instead of sorting by today's UTC offset or substituting fixed PST/EST offsets.

The lists represent current standard-time/DST regimes, rather than every historical IANA location or alias. Consult date-specific timezone rules when historical ordering matters.

The 14 states spanning federal standard-time zones, plus Arizona's separate DST case, are:

StatePreferred IANA zoneOther representative zoneGeographic basis
AlaskaAmerica/AnchorageAmerica/AdakAlaska and western Aleutians
ArizonaAmerica/DenverAmerica/PhoenixNavajo DST observance and most of Arizona without DST
FloridaAmerica/New_YorkAmerica/ChicagoEastern and western Panhandle
IdahoAmerica/BoiseAmerica/Los_AngelesSouthern Mountain and northern Pacific
IndianaAmerica/Indiana/IndianapolisAmerica/ChicagoEastern and Central counties
KansasAmerica/ChicagoAmerica/DenverCentral and western Mountain counties
KentuckyAmerica/New_YorkAmerica/ChicagoEastern and Central areas
MichiganAmerica/DetroitAmerica/MenomineeEastern and western Upper Peninsula
NebraskaAmerica/ChicagoAmerica/DenverCentral and western Mountain areas
NevadaAmerica/DenverAmerica/Los_AngelesWest Wendover's Mountain exception and Pacific remainder
North DakotaAmerica/ChicagoAmerica/DenverCentral and southwestern Mountain areas
OregonAmerica/BoiseAmerica/Los_AngelesMountain portion of Malheur County and Pacific remainder
South DakotaAmerica/ChicagoAmerica/DenverCentral and western Mountain areas
TennesseeAmerica/New_YorkAmerica/ChicagoEastern and Central areas
TexasAmerica/ChicagoAmerica/DenverCentral and far-west Mountain areas

All eight non-state entries in the existing list are included. Micronesia uses ["Pacific/Pohnpei", "Pacific/Chuuk"]: Pohnpei represents the earlier UTC+11 group (including Kosrae under current rules), while Chuuk represents the UTC+10 group (including Yap). The Marshall Islands use Pacific/Majuro for their current UTC+12 regime, including Kwajalein. These representative choices do not reconstruct the islands' differing historical rules. The existing supported list also includes the freely associated states; this metadata does not redefine their political status.

Geography and timezone identifiers reviewed September 24, 2026:

Local development commands

See package.json scripts for a list of commands.

版本与发布记录

@clipboard-health/usa-states 共发布 42 个版本,首次发布于 2026/07/29;过去 12 个月发布了 42 个版本。

版本发布日期距今
1.7.15latest2026/11/054 天前
1.7.142026/11/055 天前
1.7.132026/11/045 天前
1.7.122026/10/3110 天前
1.7.112026/10/2812 天前
1.7.102026/10/2813 天前

关于 @clipboard-health/usa-states 的常见问题

@clipboard-health/usa-states 是什么?

Canonical US state and territory list, StateCode and StateName types, and name/code normalizers.

如何安装 @clipboard-health/usa-states?

在项目目录运行 npm install @clipboard-health/usa-states,或使用 pnpm add / yarn add / bun add。

@clipboard-health/usa-states 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@clipboard-health/usa-states 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@clipboard-health/usa-states 可以商用吗?

@clipboard-health/usa-states 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@clipboard-health/usa-states 的下载量有多少?

根据 npm 官方下载统计,@clipboard-health/usa-states 在 2026/10/10 – 2026/11/08 这 30 天内被下载 15,800 次,日均约 527 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@clipboard-health/usa-states 还在维护吗?

最新版本 1.7.15 发布于 2026/11/05(4 天前);至今共发布 42 个版本,其中过去 12 个月发布了 42 个;首次发布于 2026/07/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。