Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including normalize-locale with all npm packages installed. Try it out:

var normalizeLocale = require("normalize-locale")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

normalize-locale v0.0.2

When dealing with location data, you sometimes want to enter 'Kenya' or 'Ken' or 'KE' and have that normalized for you. Right? Here is a solution!

normalize-locale

When dealing with location data, you sometimes want to enter 'Kenya' or 'Ken' or 'KE' and have that normalized for you. Right? Here is a solution!

Install

npm install --save normalize-locale

And then have fun :-)


var loc = require('normalize-locale');


console.log(loc.normalizeLocale('Kenya'));
console.log(loc.normalizeLocale('KEnyA'));
console.log(loc.normalizeLocale('ke'));
console.log(loc.normalizeLocale('KE'));
console.log(loc.normalizeLocale('KeN'));

//how about normalizing languages
console.log(loc.normalizeLanguage('SW'));
console.log(loc.normalizeLanguage('SWAHILI'));
console.log(loc.normalizeLanguage('SWa'));

//OK, suppose the people of Kenya also speak French too and it is important to capture this data?
console.log(loc.addLanguage('Kenya','French'));

//Cool, But we can also add a locale language in a single line of code
console.log(loc.normalizeLocale('KEnyA','German'));


/*
OUTPUT:

{ locale: 'ke', languages: [ 'en', 'sw' ] }
{ locale: 'ke', languages: [ 'en', 'sw' ] }
{ locale: 'ke', languages: [ 'en', 'sw' ] }
{ locale: 'ke', languages: [ 'en', 'sw' ] }
{ locale: 'ke', languages: [ 'en', 'sw' ] }
sw
sw
sw
{ locale: 'ke', languages: [ 'en', 'sw', 'fr' ] }
{ locale: 'ke', languages: [ 'en', 'sw', 'de' ] }

 */


Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free