UNPKG

tntd

Version:

tntd是基于 TNT Design 设计体系的 React UI 组件库,主要用于研发企业级中后台产品。

95 lines (94 loc) 5.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.titleHandle = exports.titleCaseUpper = exports.prepositions = exports.doUpperTitle = exports.articles = void 0; var _react = _interopRequireDefault(require("react")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } var prepositions = exports.prepositions = ['about', 'above', 'across', 'after', 'against', 'along', 'among', 'around', 'as', 'at', 'before', 'behind', 'below', 'beneath', 'beside', 'between', 'beyond', 'by', 'down', 'during', 'except', 'for', 'from', 'in', 'inside', 'into', 'like', 'near', 'of', 'off', 'on', 'onto', 'out', 'outside', 'over', 'past', 'round', 'since', 'through', 'throughout', 'to', 'toward', 'under', 'underneath', 'until', 'up', 'upon', 'with', 'within', 'without', 'or']; var articles = exports.articles = ['the', 'a', 'an']; var titleHandle = exports.titleHandle = function titleHandle(str) { var upperCaseIgnore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; // 例如tab/table种有部分特殊的词例如 lv,table这种数据库表的特殊字段 不转大写 if ((upperCaseIgnore === null || upperCaseIgnore === void 0 ? void 0 : upperCaseIgnore.length) && str && (upperCaseIgnore === null || upperCaseIgnore === void 0 ? void 0 : upperCaseIgnore.includes(str))) { return str; } // 以下逻辑特指一些介词不转大写 var words = str.split(' '); var capitalizedWords = words.map(function (word, i) { var lowerCaseWord = word.toLowerCase(); var ignoreList = prepositions.concat(articles); if (upperCaseIgnore === null || upperCaseIgnore === void 0 ? void 0 : upperCaseIgnore.length) { ignoreList = ignoreList.concat(upperCaseIgnore); ignoreList = Array.from(new Set(ignoreList)); } if (ignoreList.includes(lowerCaseWord) && i !== 0) { return lowerCaseWord; } else { return word.charAt(0).toUpperCase() + word.slice(1); } }); return capitalizedWords.join(' '); }; // 表头转换为首字母大写 var titleCaseUpper = exports.titleCaseUpper = function titleCaseUpper(str) { var upperCaseIgnore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; if (!str) { return str; } if (typeof str === 'string') { // 有斜杠根据斜杠划分 if (str === null || str === void 0 ? void 0 : str.includes('/')) { var parWords = str.split('/'); return parWords.map(function (str1) { return titleHandle(str1, upperCaseIgnore); }).join('/'); } return titleHandle(str, upperCaseIgnore); } return str; }; var _doUpperTitle = exports.doUpperTitle = function doUpperTitle(label) { var upperCaseIgnore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; var localeCode = arguments.length > 2 ? arguments[2] : undefined; var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; // 非英文直接返回,英文才大写 if (!['', undefined, null, 'en'].includes(localeCode)) { return label; } if (!label) { return label; } if (typeof label === 'string') { return titleCaseUpper(label, upperCaseIgnore); } else { if (_react["default"].isValidElement(label)) { if (((_a = label === null || label === void 0 ? void 0 : label.props) === null || _a === void 0 ? void 0 : _a.children) && Array.isArray((_b = label === null || label === void 0 ? void 0 : label.props) === null || _b === void 0 ? void 0 : _b.children)) { return Object.assign(Object.assign({}, label), { props: Object.assign(Object.assign({}, label.props), { children: (_d = (_c = label === null || label === void 0 ? void 0 : label.props) === null || _c === void 0 ? void 0 : _c.children) === null || _d === void 0 ? void 0 : _d.map(function (subLabel) { return _doUpperTitle(subLabel, upperCaseIgnore, localeCode); }) }) }); } else if (typeof ((_e = label === null || label === void 0 ? void 0 : label.props) === null || _e === void 0 ? void 0 : _e.children) === 'string') { label = Object.assign(Object.assign({}, label), { props: Object.assign(Object.assign({}, label.props), { children: titleCaseUpper((_f = label === null || label === void 0 ? void 0 : label.props) === null || _f === void 0 ? void 0 : _f.children, upperCaseIgnore) }) }); } else if (!((_g = label === null || label === void 0 ? void 0 : label.props) === null || _g === void 0 ? void 0 : _g.children) && ((_h = label === null || label === void 0 ? void 0 : label.props) === null || _h === void 0 ? void 0 : _h.title) && typeof ((_j = label === null || label === void 0 ? void 0 : label.props) === null || _j === void 0 ? void 0 : _j.title) === 'string') { label = Object.assign(Object.assign({}, label), { props: Object.assign(Object.assign({}, label.props), { title: titleCaseUpper((_k = label === null || label === void 0 ? void 0 : label.props) === null || _k === void 0 ? void 0 : _k.title, upperCaseIgnore) }) }); } } } return label; };