Skip to content

Commit

Permalink
refactor(transformer): 生成随机字符串现在遵循一个固定的模式
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche committed Sep 16, 2019
1 parent cf283ac commit 0f81ded
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/taro-transformer-wx/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,18 @@ export function createUUID () {
}).replace(/-/g, '').slice(0, 8)
}

let count = 0
export function createRandomLetters (n: number) {
const str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
return Array(n).join().split(',').map(function () { return str.charAt(Math.floor(Math.random() * str.length)) }).join('')
const countStr = (count++).toString()
let letters = ''
for (const s of countStr) {
letters += String.fromCharCode(97 + parseInt(s, 10))
}
const padding = n - letters.length
for (let i = 0; i < padding; i++) {
letters += 'z'
}
return letters
}

export function isBlockIfStatement (ifStatement, blockStatement): ifStatement is NodePath<t.IfStatement> {
Expand Down

0 comments on commit 0f81ded

Please sign in to comment.