Skip to content

Commit

Permalink
fix meikidd#7 getCode() with not supported language name
Browse files Browse the repository at this point in the history
  • Loading branch information
meikidd committed Dec 28, 2016
1 parent 9f5f522 commit b36b512
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
13 changes: 5 additions & 8 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ var ISO6391 = function ISO6391() {
(0, _classCallCheck3.default)(this, ISO6391);
};

ISO6391.getLanguages = function (codes) {
ISO6391.getLanguages = function () {
var codes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
return (0, _entries2.default)(_data2.default).filter(function (_ref) {
var _ref2 = (0, _slicedToArray3.default)(_ref, 2),
code = _ref2[0],
Expand Down Expand Up @@ -77,15 +78,11 @@ ISO6391.getAllNativeNames = function () {
};

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];

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

return code === undefined ? '' : code;
};
Expand Down
10 changes: 7 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'babel-polyfill';
import LANGUAGES_LIST from './data';

export default class ISO6391 {
static getLanguages = (codes) => (
static getLanguages = (codes = []) => (
Object.entries(LANGUAGES_LIST)
.filter(([code, language]) => codes.includes(code))
.map(([code, language]) => ({ ...language, code }))
Expand All @@ -17,8 +17,12 @@ export default class ISO6391 {
static getAllNativeNames = () => Object.values(LANGUAGES_LIST).map(l => l.nativeName)

static getCode = (name) => {
const [code] = Object.entries(LANGUAGES_LIST)
.find(([code, language]) => language.name.toLowerCase() === name.toLowerCase() || language.nativeName.toLowerCase() === name.toLowerCase())

const code = Object.keys(LANGUAGES_LIST)
.find((code) => {
const language = LANGUAGES_LIST[code]
return language.name.toLowerCase() === name.toLowerCase() || language.nativeName.toLowerCase() === name.toLowerCase()
})

return code === undefined ? '' : code
}
Expand Down

0 comments on commit b36b512

Please sign in to comment.