Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test = function(description) {
return query.test(description);
};
// If the query is all lowercase, make a case-insensitive match.
} else if (query.toLowerCase() === query) {
test = function(description) {
return -1 !== description.toLowerCase().indexOf(query);
};
} else {
test = function(description) {
return -1 !== description.indexOf(query);
};
}
return registry.filter(function(record) {
if (!record.Subtag && !all) {
return false;
}
return record.Description.some(test);
// Sort by matched description string length.
// This is a quick way to push precise matches towards the top.
}).sort(function(a, b) {
return Math.min.apply(Math, a.Description.filter(test).map(function(description) {
return description.length;
})) - Math.min.apply(Math, b.Description.filter(test).map(function(description) {
return description.length;
}));
}).map(function(record) {
if (record.Subtag) {
tags.date = function() {
return require('language-subtag-registry/data/json/meta')['File-Date'];
};
tags.languages = function(macrolanguage) {
var i, l, record, results = [];
macrolanguage = macrolanguage.toLowerCase();
if (!require('language-subtag-registry/data/json/macrolanguage')[macrolanguage]) {
throw new Error('\'' + macrolanguage + '\' is not a macrolanguage.');
}
for (i = 0, l = registry.length; i < l; i++) {
record = registry[i];
if (record.Macrolanguage === macrolanguage) {
results.push(new Subtag(record.Subtag, record.Type));
}
}
return results;
};