{"name":"language-tags","version":"2.0.1","keywords":["iana","bcp47","subtags","rfc5646","m17n","multilingualization"],"author":{"name":"Matthew Caruana Galizia","email":"mattcg@gmail.com"},"license":"MIT","_id":"language-tags@2.0.1","maintainers":[{"name":"mcg","email":"mattcg@gmail.com"}],"homepage":"https://github.com/mattcg/language-tags","bugs":{"url":"https://github.com/mattcg/language-tags/issues"},"dist":{"shasum":"cabb67b76c93aabc2a9496a326623adc3ed6ab02","tarball":"http://registry-npm.ywwl.com/language-tags/download/language-tags-2.0.1.tgz","fileCount":6,"integrity":"sha512-SzHyV6XDLTS7TSQipSaywM+QOB9PqiNhd/nWPgVwzpZqfeoIMee+Avj4F82QP6m/hMtIvUCS8UEFIlBV5vq7Gw==","signatures":[{"sig":"MEYCIQDjrid/odPc0RhUGCosdX85o6GYr81DGyG2IhdhFS1CBwIhALlfmwRQujALQYg6ydc+6+gS79gT7WLlERbBk9utDG4w","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":25497,"size":7687,"noattachment":false,"key":"/language-tags/-/language-tags-2.0.1.tgz"},"main":"lib/index.js","type":"module","engines":{"node":">=22"},"gitHead":"d6fd038ba6034f254c0637371d5e000db2db91d3","scripts":{"lint":"eslint ./lib ./test","test":"c8 mocha"},"_npmUser":{"name":"mcg","email":"mattcg@gmail.com"},"repository":{"url":"git://github.com/mattcg/language-tags.git","type":"git"},"_npmVersion":"10.9.2","description":"Work with IANA language tags.","directories":{},"_nodeVersion":"23.4.0","dependencies":{"language-subtag-registry":"^0.3.20"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^10.1.3","mocha":"^11.0.1","eslint":"^9.17.0","coveralls":"^3.1.1"},"_npmOperationalInternal":{"tmp":"tmp/language-tags_2.0.1_1734362835167_0.20575638576096877","host":"s3://npm-registry-packages-npm-production"},"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":1734362835390,"_cnpm_publish_time":1734362835390,"dist-tags":{"latest":"2.1.0"}}