forked from meikidd/iso-639-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request meikidd#2 from nickhsu/master
using es6 and refectoring
- Loading branch information
Showing
9 changed files
with
2,082 additions
and
445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"plugins": [ | ||
"transform-runtime" | ||
], | ||
"presets": [ | ||
"es2015", | ||
"stage-0" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
node_modules | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.