123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- function trim(str, type = 'both') {
- if (type === 'both') {
- return str.replace(/^\s+|\s+$/g, "")
- } else if (type === 'left') {
- return str.replace(/^\s*/g, "")
- } else if (type === 'right') {
- return str.replace(/(\s*$)/g, "")
- } else if (type === 'all') {
- return str.replace(/\s+/g, "")
- } else {
- return str
- }
- }
- function getLengthUnitValue(value, unit = 'rpx') {
- if (!value) {
- return ''
- }
- if (/(%|px|rpx|auto)$/.test(value)) return value
- else return value + unit
- }
- function humpConvertChar(string, replace = '_') {
- if (!string || !replace) {
- return ''
- }
- return string.replace(/([A-Z])/g, `${replace}$1`).toLowerCase()
- }
- function charConvertHump(string, replace = '_') {
- if (!string || !replace) {
- return ''
- }
- let reg = RegExp(replace + "(\\w)", "g")
- return string.replace(reg, function(all, letter) {
- return letter.toUpperCase()
- })
- }
- export default {
- trim,
- getLengthUnitValue,
- humpConvertChar,
- charConvertHump
- }
|