Reference · Country code validation
isCountryCodefunction
Whether a value is one of the 250 codes exactly as ISO writes it: two capital letters ("JP", and "XK" for
Kosovo). Lower case is not a code here; country() in the main entry is the forgiving one.
Import it
import { isCountryCode } from "@johnmorrisdotca/kuni/codes";
Also exported from: @johnmorrisdotca/kuni
Definition
function isCountryCode(value: unknown): value is CountryCode
Parameters
| Name | Type | Description |
|---|---|---|
value | unknown | Anything. |
Returns
boolean
True for one of the 250 codes; false for anything else, a lower-case code included.
Examples
import { isCountryCode } from "@johnmorrisdotca/kuni/codes";
console.log(isCountryCode("JP")); // true
console.log(isCountryCode("jp")); // false
console.log(isCountryCode("XX")); // falsetrue
false
falseWhat it prints (run when this page was built)