Skip to content

Commit

Permalink
feat(StringTemplate): 支持判断是否有代码块
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Aug 7, 2024
1 parent 2c75262 commit 169505b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/utils/StringTemplate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,12 @@ describe('StringTemplate', () => {
),
).toBe('3爱你{么}')
})

test('hasCodeBlock', () => {
expect(StringTemplate.hasCodeBlock('ddd')).toBe(false)
expect(StringTemplate.hasCodeBlock('{x}ddd')).toBe(false)
expect(StringTemplate.hasCodeBlock('{{x}}ddd')).toBe(true)
expect(StringTemplate.hasCodeBlock('{{x }}ddd')).toBe(true)
expect(StringTemplate.hasCodeBlock('{{ x }}ddd')).toBe(true)
})
})
5 changes: 5 additions & 0 deletions src/utils/StringTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ export class StringTemplate {
}
return template
}

/** 判断是否有代码块 */
static hasCodeBlock(template: string): boolean {
return /\{\{(.+?)\}\}/.test(template)
}
}

0 comments on commit 169505b

Please sign in to comment.