Skip to content

Commit

Permalink
improve:
Browse files Browse the repository at this point in the history
1. remove useless dependencies
2. add yarn.lock file
3. format code
  • Loading branch information
meikidd committed Dec 7, 2017
1 parent dc5075d commit 4335c24
Show file tree
Hide file tree
Showing 8 changed files with 2,158 additions and 340 deletions.
4 changes: 2 additions & 2 deletions build/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ var LANGUAGES_LIST = {
},
gn: {
name: 'Guaraní',
nativeName: 'Avañe\'ẽ'
nativeName: "Avañe'ẽ"
},
gu: {
name: 'Gujarati',
Expand Down Expand Up @@ -586,7 +586,7 @@ var LANGUAGES_LIST = {
},
sm: {
name: 'Samoan',
nativeName: 'gagana fa\'a Samoa'
nativeName: "gagana fa'a Samoa"
},
sn: {
name: 'Shona',
Expand Down
139 changes: 69 additions & 70 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,86 +12,85 @@ 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 _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

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

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 () {
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],
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 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();
});

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

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

ISO6391.validate = function (code) {
return _data2.default[code] !== undefined;
};
var ISO6391 = function () {
function ISO6391() {
(0, _classCallCheck3.default)(this, ISO6391);
}

(0, _createClass3.default)(ISO6391, null, [{
key: 'getLanguages',
value: function getLanguages() {
var codes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];

return codes.map(function (code) {
return {
code: code,
name: ISO6391.getName(code),
nativeName: ISO6391.getNativeName(code)
};
});
}
}, {
key: 'getName',
value: function getName(code) {
return ISO6391.validate(code) ? _data2.default[code].name : '';
}
}, {
key: 'getAllNames',
value: function getAllNames() {
return (0, _values2.default)(_data2.default).map(function (l) {
return l.name;
});
}
}, {
key: 'getNativeName',
value: function getNativeName(code) {
return ISO6391.validate(code) ? _data2.default[code].nativeName : '';
}
}, {
key: 'getAllNativeNames',
value: function getAllNativeNames() {
return (0, _values2.default)(_data2.default).map(function (l) {
return l.nativeName;
});
}
}, {
key: 'getCode',
value: function getCode(name) {
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();
});
return code || '';
}
}, {
key: 'getAllCodes',
value: function getAllCodes() {
return (0, _keys2.default)(_data2.default);
}
}, {
key: 'validate',
value: function validate(code) {
return _data2.default[code] !== undefined;
}
}]);
return ISO6391;
}();

exports.default = ISO6391;
module.exports = exports['default'];
29 changes: 13 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,37 @@
"main": "build/index.js",
"scripts": {
"build": "babel src --out-dir build",
"test": "mocha --require babel-core/register"
"test": "mocha"
},
"repository": {
"type": "git",
"url": "git+https://github.com/meikidd/iso-639-1.git"
},
"keywords": [
"ISO",
"ISO-639",
"ISO-639-1",
"iso",
"iso-639",
"iso-639-1",
"language",
"language code"
"language code",
"locale",
"locale code"
],
"author": "meikidd <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/meikidd/iso-639-1/issues"
},
"devDependencies": {
"babel": "~6.5.2",
"babel-cli": "^6.18.0",
"babel-core": "^6.18.2",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-es2015": "^6.18.0",
"babel-preset-stage-0": "^6.16.0",
"mocha": "^3.1.2"
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"mocha": "^4.0.1"
},
"homepage": "https://github.com/meikidd/iso-639-1#readme",
"engines": {
"node": ">=6.0"
},
"dependencies": {
"babel-polyfill": "^6.16.0",
"babel-runtime": "^6.18.0"
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ console.log(ISO6391.getCode('中文')) // 'zh'
console.log(ISO6391.getAllCodes()) //['aa','ab',...,'zu']
console.log(ISO6391.validate('en')) // true
console.log(ISO6391.validate('xxx')) // false
console.log(ISO6391.validate('xx')) // false
console.log(ISO6391.getLanguages(['en', 'zh']))
// [{code:'en',name:'English',nativeName:'English'},{code:'zh',name:'Chinese',nativeName:'中文'}]
Expand Down
Loading

0 comments on commit 4335c24

Please sign in to comment.