language-tags
Advanced tools
Comparing version 1.0.9 to 2.0.0
@@ -9,15 +9,22 @@ /** | ||
var Tag = require('./Tag.js'); | ||
var Subtag = require('./Subtag.js'); | ||
var index = require('language-subtag-registry/data/json/index.json'); | ||
var registry = require('language-subtag-registry/data/json/registry.json'); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _Tag = _interopRequireDefault(require("./Tag.js")); | ||
var _Subtag = _interopRequireDefault(require("./Subtag.js")); | ||
var _index = _interopRequireDefault(require("language-subtag-registry/data/json/index.json")); | ||
var _registry = _interopRequireDefault(require("language-subtag-registry/data/json/registry.json")); | ||
var _meta = _interopRequireDefault(require("language-subtag-registry/data/json/meta.json")); | ||
var _macrolanguage = _interopRequireDefault(require("language-subtag-registry/data/json/macrolanguage.json")); | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
var tags = function tags(tag) { | ||
return new Tag(tag); | ||
return new _Tag.default(tag); | ||
}; | ||
module.exports = tags; | ||
var _default = exports.default = tags; | ||
tags.check = function (tag) { | ||
return new Tag(tag).valid(); | ||
return new _Tag.default(tag).valid(); | ||
}; | ||
tags.types = function (subtag) { | ||
var types = index[subtag.toLowerCase()]; | ||
var types = _index.default[subtag.toLowerCase()]; | ||
if (!types) { | ||
@@ -37,3 +44,3 @@ return []; | ||
tags.types(subtag).forEach(function (type) { | ||
result.push(new Subtag(subtag, type)); | ||
result.push(new _Subtag.default(subtag, type)); | ||
}); | ||
@@ -65,3 +72,3 @@ }); | ||
} | ||
return registry.filter(function (record) { | ||
return _registry.default.filter(function (record) { | ||
if (!record.Subtag && !all) { | ||
@@ -82,5 +89,5 @@ return false; | ||
if (record.Subtag) { | ||
return new Subtag(record.Subtag, record.Type); | ||
return new _Subtag.default(record.Subtag, record.Type); | ||
} | ||
return new Tag(record.Tag); | ||
return new _Tag.default(record.Tag); | ||
}); | ||
@@ -94,9 +101,9 @@ }; | ||
macrolanguage = macrolanguage.toLowerCase(); | ||
if (!require('language-subtag-registry/data/json/macrolanguage.json')[macrolanguage]) { | ||
if (!_macrolanguage.default[macrolanguage]) { | ||
throw new Error('\'' + macrolanguage + '\' is not a macrolanguage.'); | ||
} | ||
for (i = 0, l = registry.length; i < l; i++) { | ||
record = registry[i]; | ||
for (i = 0, l = _registry.default.length; i < l; i++) { | ||
record = _registry.default[i]; | ||
if (record.Macrolanguage === macrolanguage) { | ||
results.push(new Subtag(record.Subtag, record.Type)); | ||
results.push(new _Subtag.default(record.Subtag, record.Type)); | ||
} | ||
@@ -113,5 +120,5 @@ } | ||
tags.type = function (subtag, type) { | ||
var types = index[subtag.toLowerCase()]; | ||
var types = typeof subtag === 'string' && _index.default[subtag.toLowerCase()]; | ||
if (types && types[type]) { | ||
return new Subtag(subtag, type); | ||
return new _Subtag.default(subtag, type); | ||
} | ||
@@ -121,3 +128,3 @@ return null; | ||
tags.date = function () { | ||
return require('language-subtag-registry/data/json/meta.json')['File-Date']; | ||
return _meta.default['File-Date']; | ||
}; |
@@ -9,12 +9,17 @@ /** | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } | ||
var index = require('language-subtag-registry/data/json/index.json'); | ||
var registry = require('language-subtag-registry/data/json/registry.json'); | ||
var Subtag = /*#__PURE__*/function () { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _index = _interopRequireDefault(require("language-subtag-registry/data/json/index.json")); | ||
var _registry = _interopRequireDefault(require("language-subtag-registry/data/json/registry.json")); | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } | ||
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } | ||
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } | ||
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } | ||
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } | ||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } | ||
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } | ||
var Subtag = exports.default = /*#__PURE__*/function () { | ||
/** | ||
@@ -38,3 +43,3 @@ * @param {string} subtag | ||
} | ||
types = index[subtag]; | ||
types = _index.default[subtag]; | ||
if (!types) { | ||
@@ -47,3 +52,3 @@ error(Subtag.ERR_NONEXISTENT, 'Non-existent subtag \'' + subtag + '\'.'); | ||
} | ||
record = registry[i]; | ||
record = _registry.default[i]; | ||
if (!record.Subtag) { | ||
@@ -58,3 +63,3 @@ error(Subtag.ERR_TAG, '\'' + subtag + '\' is a \'' + type + '\' tag.'); | ||
} | ||
_createClass(Subtag, [{ | ||
return _createClass(Subtag, [{ | ||
key: "type", | ||
@@ -132,6 +137,4 @@ value: function type() { | ||
}]); | ||
return Subtag; | ||
}(); | ||
_defineProperty(Subtag, "ERR_NONEXISTENT", 1); | ||
_defineProperty(Subtag, "ERR_TAG", 2); | ||
module.exports = Subtag; | ||
_defineProperty(Subtag, "ERR_TAG", 2); |
@@ -9,13 +9,18 @@ /** | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } | ||
var index = require('language-subtag-registry/data/json/index.json'); | ||
var registry = require('language-subtag-registry/data/json/registry.json'); | ||
var Subtag = require('./Subtag.js'); | ||
var Tag = /*#__PURE__*/function () { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _index = _interopRequireDefault(require("language-subtag-registry/data/json/index.json")); | ||
var _registry = _interopRequireDefault(require("language-subtag-registry/data/json/registry.json")); | ||
var _Subtag = _interopRequireDefault(require("./Subtag.js")); | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } | ||
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } | ||
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } | ||
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } | ||
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } | ||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } | ||
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } | ||
var Tag = exports.default = /*#__PURE__*/function () { | ||
/** @param {string} tag */ | ||
@@ -33,8 +38,8 @@ function Tag(tag) { | ||
// Check if the input tag is grandfathered or redundant. | ||
types = index[tag]; | ||
types = _index.default[tag]; | ||
if (types && (types.grandfathered || types.redundant)) { | ||
this.data.record = registry[types.grandfathered || types.redundant]; | ||
this.data.record = _registry.default[types.grandfathered || types.redundant]; | ||
} | ||
} | ||
_createClass(Tag, [{ | ||
return _createClass(Tag, [{ | ||
key: "preferred", | ||
@@ -74,5 +79,4 @@ value: function preferred() { | ||
} | ||
types = _index.default[code]; | ||
types = index[code]; | ||
// Check for non-existent tag. | ||
@@ -86,3 +90,3 @@ if (!types) { | ||
if (0 === i && undefined !== types.language) { | ||
subtags.push(new Subtag(code, 'language')); | ||
subtags.push(new _Subtag.default(code, 'language')); | ||
return; | ||
@@ -94,7 +98,7 @@ } | ||
if (types.region) { | ||
subtags.push(new Subtag(code, 'region')); | ||
subtags.push(new _Subtag.default(code, 'region')); | ||
// Error case: language subtag in the wrong place. | ||
} else if (types.language) { | ||
subtags.push(new Subtag(code, 'language')); | ||
subtags.push(new _Subtag.default(code, 'language')); | ||
} | ||
@@ -105,9 +109,9 @@ break; | ||
if (types.region) { | ||
subtags.push(new Subtag(code, 'region')); | ||
subtags.push(new _Subtag.default(code, 'region')); | ||
} else if (types.extlang) { | ||
subtags.push(new Subtag(code, 'extlang')); | ||
subtags.push(new _Subtag.default(code, 'extlang')); | ||
// Error case: language subtag in the wrong place. | ||
} else if (types.language) { | ||
subtags.push(new Subtag(code, 'language')); | ||
subtags.push(new _Subtag.default(code, 'language')); | ||
} | ||
@@ -118,5 +122,5 @@ break; | ||
if (types.variant) { | ||
subtags.push(new Subtag(code, 'variant')); | ||
subtags.push(new _Subtag.default(code, 'variant')); | ||
} else if (types.script) { | ||
subtags.push(new Subtag(code, 'script')); | ||
subtags.push(new _Subtag.default(code, 'script')); | ||
} | ||
@@ -127,3 +131,3 @@ break; | ||
if (types.variant) { | ||
subtags.push(new Subtag(code, 'variant')); | ||
subtags.push(new _Subtag.default(code, 'variant')); | ||
} | ||
@@ -252,3 +256,3 @@ break; | ||
} | ||
types = index[code]; | ||
types = _index.default[code]; | ||
if (!types) { | ||
@@ -394,3 +398,2 @@ error(Tag.ERR_UNKNOWN, code); | ||
}]); | ||
return Tag; | ||
}(); | ||
@@ -408,3 +411,2 @@ _defineProperty(Tag, "ERR_DEPRECATED", 1); | ||
_defineProperty(Tag, "ERR_SUBTAG_DEPRECATED", 11); | ||
_defineProperty(Tag, "ERR_EXTRA_LANGUAGE", 12); | ||
module.exports = Tag; | ||
_defineProperty(Tag, "ERR_EXTRA_LANGUAGE", 12); |
{ | ||
"name": "language-tags", | ||
"version": "1.0.9", | ||
"implements": [ | ||
"CommonJS/Modules/1.0" | ||
], | ||
"version": "2.0.0", | ||
"description": "Work with IANA language tags.", | ||
"main": "lib/index.js", | ||
"type": "module", | ||
"homepage": "https://github.com/mattcg/language-tags", | ||
@@ -23,4 +21,4 @@ "author": "Matthew Caruana Galizia <mattcg@gmail.com>", | ||
"build": "babel src -d lib", | ||
"lint": "eslint --ext=js,mjs .", | ||
"tests-only": "nyc mocha --recursive test", | ||
"lint": "eslint ./src ./test", | ||
"tests-only": "c8 mocha", | ||
"pretest": "npm run lint", | ||
@@ -44,7 +42,7 @@ "test": "npm run tests-only" | ||
"coveralls": "^3.1.1", | ||
"eslint": "^8.47.0", | ||
"mkdirp": "^0.5.6", | ||
"mocha": "^3.5.3", | ||
"nyc": "^10.3.2", | ||
"rimraf": "^2.7.1" | ||
"eslint": "^9.17.0", | ||
"mkdirp": "^3.0.1", | ||
"mocha": "^11.0.1", | ||
"c8": "^10.1.3", | ||
"rimraf": "^6.0.1" | ||
}, | ||
@@ -56,24 +54,3 @@ "files": [ | ||
"node": ">=0.10" | ||
}, | ||
"eslintConfig": { | ||
"parserOptions": { | ||
"ecmaVersion": 2022, | ||
"sourceType": "script" | ||
}, | ||
"env": { | ||
"node": true | ||
}, | ||
"ignorePatterns": [ | ||
"!.babelrc.js" | ||
], | ||
"overrides": [ | ||
{ | ||
"files": "test/**", | ||
"globals": { | ||
"suite": false, | ||
"test": false | ||
} | ||
} | ||
] | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33097
6
630
Yes