Skip to content

Commit

Permalink
💚 fix: ci
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Apr 8, 2023
1 parent bb22f1b commit 87b56f2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
28 changes: 14 additions & 14 deletions javascript/format-prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Converter {
*/
static convertStr2Array(str) {
// 匹配各种括号中的内容,包括括号本身
const bracketRegex = /(\(|\)|<|>|\[|\])/g
const bracketRegex = /([()<>[\]])/g
/**
* 将字符串按照各种括号分割成数组
* @param str 字符串
Expand Down Expand Up @@ -107,11 +107,11 @@ class Converter {
if (item.includes('<')) return item
const newItem = item
.replace(/\s+/g, ' ')
.replace(/\,|\.|\/g, ',')
.replace(/\“|\‘|\”|\"|\\|\//g, '')
.replace(/\, /g, ',')
.replace(/\,\,/g, ',')
.replace(/\,/g, ', ')
.replace(/,|\.\|/g, ',')
.replace(/“|‘|”|"|\/'/g, '')
.replace(/, /g, ',')
.replace(/,,/g, ',')
.replace(/,/g, ', ')
return Converter.convertStr2Array(newItem).join(', ')
})
return newArray.join(', ')
Expand All @@ -122,7 +122,7 @@ class Converter {
* @returns 转换后的字符串
*/
static convert(input) {
const re_attention = /\{|\[|\}|\]|[^\{\}\[\]]+/gmu
const re_attention = /\{|\[|\}|\]|[^{}[\]]+/gmu
let text = Converter.convertStr(input)
const textArray = Converter.convertStr2Array(text)
text = Converter.convertArray2Str(textArray)
Expand All @@ -147,7 +147,7 @@ class Converter {
let word = match[0]
if (word in brackets) {
brackets[word].stack.push(res.length)
} else if (word == '}' || word == ']') {
} else if (word === '}' || word === ']') {
const bracket = brackets[word === '}' ? '{' : '[']
if (bracket.stack.length > 0) {
multiply_range(bracket.stack.pop(), bracket.multiplier)
Expand All @@ -156,17 +156,17 @@ class Converter {
res.push([word, 1.0])
}
}
for (const bracketType in brackets) {
for (const pos of brackets[bracketType].stack) {
Object.keys(brackets).forEach((bracketType) => {
brackets[bracketType].stack.forEach((pos) => {
multiply_range(pos, brackets[bracketType].multiplier)
}
}
if (res.length == 0) {
})
})
if (res.length === 0) {
res = [['', 1.0]]
}
let i = 0
while (i + 1 < res.length) {
if (res[i][1] == res[i + 1][1]) {
if (res[i][1] === res[i + 1][1]) {
res[i][0] += res[i + 1][0]
res.splice(i + 1, 1)
} else {
Expand Down
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@
"type-check": "tsc -p tsconfig-check.json"
},
"lint-staged": {
"*.{js,jsx,less,css,md,json}": [
"*.{less,css}": [
"prettier --write"
],
"*.{md,json}": [
"prettier --write --no-error-on-unmatched-pattern"
],
"*.{js,jsx}": [
"eslint --fix",
"prettier --write"
],
"*.{ts,tsx}": [
"eslint --fix",
"prettier --parser=typescript --write"
]
},
"dependencies": {},
Expand Down

0 comments on commit 87b56f2

Please sign in to comment.