{"name":"language-tags","version":"2.1.0","description":"Work with IANA language tags.","main":"lib/index.js","type":"module","homepage":"https://github.com/mattcg/language-tags","author":{"name":"Matthew Caruana Galizia","email":"mattcg@gmail.com"},"repository":{"type":"git","url":"git://github.com/mattcg/language-tags.git"},"bugs":{"url":"https://github.com/mattcg/language-tags/issues"},"license":"MIT","scripts":{"pretest":"eslint ./lib ./test","test":"c8 mocha","tests-only":"c8 mocha"},"keywords":["iana","bcp47","subtags","rfc5646","m17n","multilingualization"],"dependencies":{"language-subtag-registry":"^0.3.20"},"devDependencies":{"coveralls":"^3.1.1","eslint":"^9.17.0","mocha":"^11.0.1","c8":"^10.1.3"},"engines":{"node":">=22"},"_id":"language-tags@2.1.0","gitHead":"4c323c99010dde58261dc80ce4407e8206b1ff79","_nodeVersion":"23.11.0","_npmVersion":"11.3.0","dist":{"integrity":"sha512-D4CgpyCt+61f6z2jHjJS1OmZPviAWM57iJ9OKdFFWSNgS7Udj9QVWqyGs/cveVNF57XpZmhSvMdVIV5mjLA7Vg==","shasum":"004eb97cf1c4eef7c5d84b2a43f6e67081447732","tarball":"http://registry-npm.ywwl.com/language-tags/download/language-tags-2.1.0.tgz","fileCount":6,"unpackedSize":25713,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQD91fL9gQU/0rhVkuZqY9y4T9ccEbvr6uxdWEPfNqejuQIhAN7bReSlgMqUfcreq6RhteetkGvS6Vp6qAmLlV/r30MA"}],"size":7803,"noattachment":false,"key":"/language-tags/-/language-tags-2.1.0.tgz"},"_npmUser":{"name":"mcg","email":"mattcg@gmail.com"},"directories":{},"maintainers":[{"name":"mcg","email":"mattcg@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/language-tags_2.1.0_1747144294214_0.9867432397052047"},"_hasShrinkwrap":false,"readme":"# IANA Language Tags for JavaScript #\n\n[![Build Status](https://github.com/mattcg/language-tags/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/mattcg/language-tags/actions/workflows/tests.yml)\n[![Coverage Status](https://coveralls.io/repos/mattcg/language-tags/badge.png)](https://coveralls.io/r/mattcg/language-tags)\n\nBased on [BCP 47](https://www.rfc-editor.org/info/bcp47) ([RFC 5646](https://www.rfc-editor.org/rfc/rfc5646.html)) and the latest [IANA language subtag registry](http://www.iana.org/assignments/language-subtag-registry).\n\nThis project will be updated as the standards change.\n\n## JSON data ##\n\nSee the [language-subtag-registry](https://github.com/mattcg/language-subtag-registry) project for the underlying JSON data.\n\n## API ##\n\n```js\nimport {tags, check, subtags, filter, search, languages, language, region, type, date} from 'language-tags'\n```\n\nNote that all lookups and checks for tags and subtags are case insensitive. For formatting according to common conventions, see `tag.format`.\n\n### tags(tag) ###\n\nCheck whether a hyphen-separated tag is valid and well-formed. Always returns a `Tag`, which can be checked using the `valid` method.\n\n### check(tag) ###\n\nShortcut for `tags(tag).valid()`. Return `true` if the tag is valid, `false` otherwise. For meaningful error output see `tag.errors()`.\n\n### subtags(subtag), subtags(subtags) ###\n\nLook up one or more subtags. Returns an array of `Subtag` objects. Returns an empty array if all of the subtags are non-existent.\n\nCalling `subtags('mt')` will return an array with two `Subtag` objects: one for Malta (the 'region' type subtag) and one for Maltese (the 'language' type subtag).\n\n```\n> subtags('mt');\n[Subtag, Subtag]\n> subtags('bumblebee');\n[]\n```\n\nTo get or check a single subtag by type use `language(subtag)`, `region(subtag)` or `type(subtag, type)`.\n\n### filter(subtags) ###\n\nThe opposite of `subtags(subtags)`. Returns an array of codes that are not registered subtags, otherwise returns an empty array.\n\n```\n> filter(['en', 'Aargh']);\n['Aargh']\n```\n\n### search(description, [all]) ###\n\nSearch for tags and subtags by description. Supports either a RegExp object or a string for `description`. Returns an array of `Subtag` and `Tag` objects or an empty array if no results were found.\n\nNote that `Tag` objects in the results represent 'grandfathered' or 'redundant' tags. These are excluded by default. Set the `all` parameter to `true` to include them.\n\nSearch is case-insensitive if `description` is a string.\n\n### languages(macrolanguage) ###\n\nReturns an array of `Subtag` objects representing all the 'language' type subtags belonging to the given 'macrolanguage' type subtag.\n\nThrows an error if `macrolanguage` is not a macrolanguage.\n\n```\n> languages('zh');\n[Subtag, Subtag...]\n> languages('en');\nError: 'en' is not a valid macrolanguage.\n```\n\n### language(subtag) ###\n\nConvenience method to get a single 'language' type subtag. Can be used to validate an input value as a language subtag. Returns a `Subtag` object or `null`.\n\n```\n> language('en');\nSubtag\n> language('us');\nnull\n```\n\n### region(subtag) ###\n\nAs above, but with 'region' type subtags.\n\n```\n> region('mt');\nSubtag\n> region('en');\nnull\n```\n\n### type(subtag, type) ###\n\nGet a subtag by type. Returns the subtag matching `type` as a `Subtag` object otherwise returns `null`.\n\nA `type` consists of one of the following strings: 'language', 'extlang', 'script', 'region' or 'variant'. To get a 'grandfathered' or 'redundant' type tag use `tags(tag)`.\n\n```\n> type('zh', 'macrolanguage');\nSubtag\n> type('zh', 'script');\nnull\n```\n\n### date() ###\n\nReturns the file date for the underlying data, as a string.\n\n```\n> date();\n'2004-06-28'\n```\n\n### Subtag ###\n\n#### subtag.type() ####\n\nGet the subtag type (either 'language', 'extlang', 'script', 'region' or 'variant'). See [RFC 5646 section 2.2](http://tools.ietf.org/html/rfc5646#section-2.2) for type definitions.\n\n#### subtag.descriptions() ####\n\nReturns an array of description strings (a subtag may have more than one description).\n\n```\n> language('ro').descriptions();\n['Romanian', 'Moldavian', 'Moldovan']\n```\n\n#### subtag.preferred() ####\n\nReturns a preferred subtag as a `Subtag` object if the subtag is deprecated. For example, `ro` is preferred over deprecated `mo`.\n\n```\n> language('mo').preferred();\nSubtag\n```\n\n#### subtag.script() ####\n\nFor subtags of type 'language' or 'extlang', returns a `Subtag` object representing the language's default script. See [RFC 5646 section 3.1.9](http://tools.ietf.org/html/rfc5646#section-3.1.9) for a definition of 'Suppress-Script'.\n\n#### subtag.scope() ####\n\nReturns the subtag scope as a string, or `null` if the subtag has no scope.\n\nTip: if the subtag represents a macrolanguage, you can use `languages(macrolanguage)` to get a list of all the macrolanguage's individual languages.\n\n```\n> language('zh').scope();\n'macrolanguage'\n> language('nah').scope();\n'collection'\n```\n\n#### subtag.deprecated() ####\n\nReturns a date string reflecting the deprecation date if the subtag is deprecated, otherwise returns `null`.\n\n```\n> language('ja').deprecated();\n'2008-11-22'\n```\n\n#### subtag.added() ####\n\nReturns a date string reflecting the date the subtag was added to the registry.\n\n```\n> language('ja').added();\n'2005-10-16'\n```\n\n#### subtag.comments() ####\n\nReturns an array of comments, if any, otherwise returns an empty array.\n\n```\n> language('nmf').comments();\n['see ntx']\n```\n\n#### subtag.format() ####\n\nReturn the subtag code formatted according to the case conventions defined in [RFC 5646 section 2.1.1](http://tools.ietf.org/html/rfc5646#section-2.1.1).\n\n- language codes are made lowercase ('mn' for Mongolian)\n- script codes are made lowercase with the initial letter capitalized ('Cyrl' for Cyrillic)\n- country codes are capitalized ('MN' for Mongolia)\n\n### Tag ###\n\n#### tag.preferred() ####\n\nIf the tag is listed as 'deprecated' or 'redundant' it might have a preferred value. This method returns a `Tag` object if so.\n\n```\n> tags('zh-cmn-Hant').preferred();\nTag\n```\n\n#### tag.type() ####\n\nReturns `grandfathered` if the tag is grandfathered, `redundant` if the tag is redundant, and `tag` if neither. For a definition of grandfathered and redundant tags, see [RFC 5646 section 2.2.8](http://tools.ietf.org/html/rfc5646#section-2.2.8).\n\n#### tag.subtags() ####\n\nReturns an array of subtags making up the tag, as `Subtag` objects.\n\n#### tag.language(), tag.region(), tag.script() ####\n\nShortcuts for `tag.find('language')`, `tag.find('region')` and `tag.find('script')`.\n\n#### tag.find(type) ####\n\nFind a subtag of the given type from those making up the tag.\n\n#### tag.valid() ####\n\nReturns `true` if the tag is valid, `false` otherwise.\n\n#### tag.errors() ####\n\nReturns an array of `Error` objects if the tag is invalid. The `message` property of each is readable and helpful enough for UI output. The `code` property can be checked against the `Tag.ERR_*` constants. Each error will also have either a `subtag` or `tag` property with the code of the offending tag.\n\n#### tag.format() ####\n\nFormat a tag according to the case conventions defined in [RFC 5646 section 2.1.1](http://tools.ietf.org/html/rfc5646#section-2.1.1).\n\n```\n> tags('en-gb').format();\n'en-GB'\n```\n\n#### tag.deprecated() ####\n\nFor grandfathered or redundant tags, returns a date string reflecting the deprecation date if the tag is deprecated.\n\n```\n> tags('zh-cmn-Hant').deprecated();\n'2009-07-29'\n```\n\n#### tag.added() ####\n\nFor grandfathered or redundant tags, returns a date string reflecting the date the tag was added to the registry.\n\n#### tag.descriptions() ####\n\nReturns an array of tag descriptions for grandfathered or redundant tags, otherwise returns an empty array.\n\n## Resources ##\n\n- [Python version by the Flanders Heritage Agency](https://github.com/OnroerendErfgoed/language-tags)\n- [Language Subtag Lookup tool by Richard Ishida](http://rishida.net/utils/subtags/)\n- [W3C Internationalization Checker](http://validator.w3.org/i18n-checker/)\n- [RFC 5646](http://tools.ietf.org/html/rfc5646)\n\n## Credits and collaboration ##\n\nCopyright (c) 2013, [Matthew Caruana Galizia](http://twitter.com/mcaruanagalizia).\n\nThe software part of this project is licensed under an [MIT licence](http://mattcg.mit-license.org/).\n\nComments, feedback and suggestions are welcome. Please feel free to raise an issue or pull request. Enjoy.\n","publish_time":1747144294431,"_cnpm_publish_time":1747144294431,"dist-tags":{"latest":"2.1.0"}}