update
parent
0cfeb517be
commit
324d6e338f
|
@ -30,6 +30,20 @@ export function str2unicode(str) {
|
|||
return str
|
||||
}
|
||||
|
||||
//驼峰转换为连字符线风格
|
||||
export function hyphen(target) {
|
||||
return target.replace(/([a-z\d])([A-Z]+)/g, '$1-$2').toLowerCase()
|
||||
}
|
||||
|
||||
//连字符转换为驼峰风格
|
||||
export function camelize(target) {
|
||||
//提前判断,提高效率
|
||||
if (target.indexOf('-') < 0) {
|
||||
return target
|
||||
}
|
||||
return target.replace(/\-([a-z])/g, (m, s) => s.toUpperCase())
|
||||
}
|
||||
|
||||
export function toUnicode(str) {
|
||||
let uArray = str2unicode(str)
|
||||
uArray = uArray.split(';')
|
||||
|
@ -41,15 +55,12 @@ export function normalizeUnicode(str) {
|
|||
return toUnicode(str)[0]
|
||||
}
|
||||
|
||||
export function toLine(str) {
|
||||
return str.replace(/([A-Z]{1})/g, (_, s) => '-' + s.toLowerCase())
|
||||
}
|
||||
|
||||
export function key2underline(obj) {
|
||||
let result = {}
|
||||
for (let k in obj) {
|
||||
k = toLine(k)
|
||||
result[k] = obj[k]
|
||||
let v = obj[k]
|
||||
k = hyphen(k)
|
||||
result[k] = v
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
import { svg2ttf } from '../src/index.js'
|
||||
import { toUnicode } from '../src/lib/utils.js'
|
||||
import { toUnicode, key2underline, normalizeUnicode } from '../src/lib/utils.js'
|
||||
import fs from 'iofs'
|
||||
|
||||
// let svg = fs.cat('test/game.svg').toString()
|
||||
|
@ -14,4 +14,6 @@ import fs from 'iofs'
|
|||
|
||||
// console.log(ttf)
|
||||
|
||||
console.log(toUnicode('哈哈'))
|
||||
console.log(toUnicode('哈哈'), normalizeUnicode('哈哈'))
|
||||
console.log(toUnicode('哈'), normalizeUnicode(toUnicode('哈')[0]))
|
||||
console.log(key2underline({ fooBar: '大', FooGoo: '圭' }))
|
||||
|
|
Loading…
Reference in New Issue