How to use language-subtag-registry - 3 common examples

To help you get started, we’ve selected a few language-subtag-registry examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mattcg / language-tags / lib / index.js View on Github external
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) {
github mattcg / language-tags / lib / index.js View on Github external
tags.date = function() {
	return require('language-subtag-registry/data/json/meta')['File-Date'];
};
github mattcg / language-tags / lib / index.js View on Github external
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;
};

language-subtag-registry

Full BCP 47 language subtag data from the official IANA repository, in JSON format with multiple indices.

CC0-1.0
Latest version published 2 years ago

Package Health Score

67 / 100
Full package analysis