Skip to content

Commit

Permalink
using es6 and refectoring
Browse files Browse the repository at this point in the history
  • Loading branch information
nickhsu committed Nov 11, 2016
1 parent 489bfac commit 6e31a2f
Show file tree
Hide file tree
Showing 9 changed files with 2,082 additions and 445 deletions.
9 changes: 9 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"plugins": [
"transform-runtime"
],
"presets": [
"es2015",
"stage-0"
]
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
/.idea
8 changes: 3 additions & 5 deletions build/data.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
'use strict';

Object.defineProperty(exports, '__esModule', {
Object.defineProperty(exports, "__esModule", {
value: true
});
var CODE_LIST = ['aa', 'ab', 'ae', 'af', 'ak', 'am', 'an', 'ar', 'as', 'av', 'ay', 'az', 'ba', 'be', 'bg', 'bh', 'bi', 'bm', 'bn', 'bo', 'br', 'bs', 'ca', 'ce', 'ch', 'co', 'cr', 'cs', 'cu', 'cv', 'cy', 'da', 'de', 'dv', 'dz', 'ee', 'el', 'en', 'eo', 'es', 'et', 'eu', 'fa', 'ff', 'fi', 'fj', 'fo', 'fr', 'fy', 'ga', 'gd', 'gl', 'gn', 'gu', 'gv', 'ha', 'he', 'hi', 'ho', 'hr', 'ht', 'hu', 'hy', 'hz', 'ia', 'id', 'ie', 'ig', 'ii', 'ik', 'io', 'is', 'it', 'iu', 'ja', 'jv', 'ka', 'kg', 'ki', 'kj', 'kk', 'kl', 'km', 'kn', 'ko', 'kr', 'ks', 'ku', 'kv', 'kw', 'ky', 'la', 'lb', 'lg', 'li', 'ln', 'lo', 'lt', 'lu', 'lv', 'mg', 'mh', 'mi', 'mk', 'ml', 'mn', 'mr', 'ms', 'mt', 'my', 'na', 'nb', 'nd', 'ne', 'ng', 'nl', 'nn', 'no', 'nr', 'nv', 'ny', 'oc', 'oj', 'om', 'or', 'os', 'pa', 'pi', 'pl', 'ps', 'pt', 'qu', 'rm', 'rn', 'ro', 'ru', 'rw', 'sa', 'sc', 'sd', 'se', 'sg', 'si', 'sk', 'sl', 'sm', 'sn', 'so', 'sq', 'sr', 'ss', 'st', 'su', 'sv', 'sw', 'ta', 'te', 'tg', 'th', 'ti', 'tk', 'tl', 'tn', 'to', 'tr', 'ts', 'tt', 'tw', 'ty', 'ug', 'uk', 'ur', 'uz', 've', 'vi', 'vo', 'wa', 'wo', 'xh', 'yi', 'yo', 'za', 'zh', 'zu'];

exports.CODE_LIST = CODE_LIST;
var LANGUAGES_LIST = {
aa: {
name: 'Afar',
Expand Down Expand Up @@ -744,4 +741,5 @@ var LANGUAGES_LIST = {
nativeName: 'isiZulu'
}
};
exports.LANGUAGES_LIST = LANGUAGES_LIST;

exports.default = LANGUAGES_LIST;
174 changes: 89 additions & 85 deletions build/index.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,99 @@
'use strict';

Object.defineProperty(exports, '__esModule', {
Object.defineProperty(exports, "__esModule", {
value: true
});

var _createClass = (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, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _keys = require('babel-runtime/core-js/object/keys');

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
var _keys2 = _interopRequireDefault(_keys);

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _values = require('babel-runtime/core-js/object/values');

var _values2 = _interopRequireDefault(_values);

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');

var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);

var _entries = require('babel-runtime/core-js/object/entries');

var _entries2 = _interopRequireDefault(_entries);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _data = require('./data');

var DATA = _interopRequireWildcard(_data);

var ISO6391 = (function () {
function ISO6391() {
_classCallCheck(this, ISO6391);
}

_createClass(ISO6391, null, [{
key: 'getLanguages',
value: function getLanguages(codes) {
var list = [];
for (var i = 0; i < codes.length; i++) {
list.push({
code: codes[i],
name: ISO6391.getName(codes[i]),
nativeName: ISO6391.getNativeName(codes[i])
});
}
return list;
}
}, {
key: 'getName',
value: function getName(code) {
if (!ISO6391.validate(code)) return '';
return DATA.LANGUAGES_LIST[code].name;
}
}, {
key: 'getAllNames',
value: function getAllNames() {
var list = [];
for (var code in DATA.LANGUAGES_LIST) {
list.push(DATA.LANGUAGES_LIST[code].name);
}
return list;
}
}, {
key: 'getNativeName',
value: function getNativeName(code) {
if (!ISO6391.validate(code)) return '';
return DATA.LANGUAGES_LIST[code].nativeName;
}
}, {
key: 'getAllNativeNames',
value: function getAllNativeNames() {
var list = [];
for (var code in DATA.LANGUAGES_LIST) {
list.push(DATA.LANGUAGES_LIST[code].nativeName);
}
return list;
}
}, {
key: 'getCode',
value: function getCode(name) {
for (var i = 0; i < DATA.CODE_LIST.length; i++) {
var code = DATA.CODE_LIST[i];
var language = DATA.LANGUAGES_LIST[code];
if (language.name === name || language.nativeName === name) return code;
}
return '';
}
}, {
key: 'getAllCodes',
value: function getAllCodes() {
return DATA.CODE_LIST;
}
}, {
key: 'validate',
value: function validate(code) {
if (DATA.CODE_LIST.indexOf(code) === -1) {
return false;
} else {
return true;
}
}
}]);

return ISO6391;
})();

exports['default'] = ISO6391;
module.exports = exports['default'];
var _data2 = _interopRequireDefault(_data);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var ISO6391 = function ISO6391() {
(0, _classCallCheck3.default)(this, ISO6391);
};

ISO6391.getLanguages = function (codes) {
return (0, _entries2.default)(_data2.default).filter(function (_ref) {
var _ref2 = (0, _slicedToArray3.default)(_ref, 2),
code = _ref2[0],
language = _ref2[1];

return codes.includes(code);
}).map(function (_ref3) {
var _ref4 = (0, _slicedToArray3.default)(_ref3, 2),
code = _ref4[0],
language = _ref4[1];

return (0, _extends3.default)({}, language, { code: code });
});
};

ISO6391.getName = function (code) {
return ISO6391.validate(code) ? _data2.default[code].name : '';
};

ISO6391.getAllNames = function () {
return (0, _values2.default)(_data2.default).map(function (l) {
return l.name;
});
};

ISO6391.getNativeName = function (code) {
return ISO6391.validate(code) ? _data2.default[code].nativeName : '';
};

ISO6391.getAllNativeNames = function () {
return (0, _values2.default)(_data2.default).map(function (l) {
return l.nativeName;
});
};

ISO6391.getCode = function (name) {
var _Object$entries$find = (0, _entries2.default)(_data2.default).find(function (_ref5) {
var _ref6 = (0, _slicedToArray3.default)(_ref5, 2),
code = _ref6[0],
language = _ref6[1];

return language.name === name || language.nativeName === name;
}),
_Object$entries$find2 = (0, _slicedToArray3.default)(_Object$entries$find, 1),
code = _Object$entries$find2[0];

return code === undefined ? '' : code;
};

ISO6391.getAllCodes = function () {
return (0, _keys2.default)(_data2.default);
};

ISO6391.validate = function (code) {
return _data2.default[code] !== undefined;
};

exports.default = ISO6391;
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "build/index.js",
"scripts": {
"build": "babel src --out-dir build",
"test": "mocha"
"test": "mocha --require babel-core/register"
},
"repository": {
"type": "git",
Expand All @@ -24,8 +24,15 @@
"url": "https://github.com/meikidd/iso-639-1/issues"
},
"devDependencies": {
"babel": "~5.8.12",
"mocha": "*"
"babel": "~6.5.2",
"babel-cli": "^6.18.0",
"babel-core": "^6.18.2",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-polyfill": "^6.16.0",
"babel-preset-es2015": "^6.18.0",
"babel-preset-stage-0": "^6.16.0",
"babel-runtime": "^6.18.0",
"mocha": "^3.1.2"
},
"homepage": "https://github.com/meikidd/iso-639-1#readme"
}
Loading

0 comments on commit 6e31a2f

Please sign in to comment.