UNPKG

@iimm/shared

Version:

shared utils on browser and react env

57 lines (55 loc) 2.01 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/cjs/html/string/index.ts var string_exports = {}; __export(string_exports, { camelCase: () => camelCase, capitalize: () => capitalize, hasChineseWord: () => hasChineseWord, isAllChineseWord: () => isAllChineseWord, pascalCase: () => pascalCase, separatorCase: () => separatorCase }); module.exports = __toCommonJS(string_exports); var isAllChineseWord = (str) => /^[\u4e00-\u9fa5]+$/.test(str); var hasChineseWord = (str) => /[\u4e00-\u9fa5]+/.test(str); var capitalize = (word = "") => { return word.replace(/( |^)[a-z]/, (c) => c.toUpperCase()); }; var pascalCase = (str = "") => { return str.split(/[_-]/).map(capitalize).join(""); }; var camelCase = (str = "") => { return str.replace(/[_-](\w)/g, (all, letter) => letter.toUpperCase()); }; var separatorCase = (name = "", separator = "_") => { let str = name || ""; if (str.length && str.slice(0, 1) === str.slice(0, 1).toUpperCase()) { str = str.slice(0, 1).toLowerCase() + str.slice(1); } return str.replace(/([A-Z])/g, `${separator}$1`); }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { camelCase, capitalize, hasChineseWord, isAllChineseWord, pascalCase, separatorCase });