From c01bc2c5c88dcc6bdb0ef271c882458f74eaab86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malcolm=20Nihl=C3=A9n?= Date: Sat, 23 Jul 2022 17:07:17 +0200 Subject: [PATCH] feat: mixed case keyword matching --- index.test.js | 5 +++++ lib/index.js | 2 +- lib/keywords.js | 7 +------ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/index.test.js b/index.test.js index 557dc98..8dc7d94 100644 --- a/index.test.js +++ b/index.test.js @@ -50,6 +50,11 @@ describe('unicode', () => { .toBe('[keyword]select[clear]') }) + it('keywords (mixed case)', () => { + expect(hlUni('SElect')) + .toBe('[keyword]SElect[clear]') + }) + it('special characters', () => { expect(hlUni('=')) .toBe('[special]=[clear]') diff --git a/lib/index.js b/lib/index.js index c190bfb..95376be 100644 --- a/lib/index.js +++ b/lib/index.js @@ -22,7 +22,7 @@ const highlighters = [ { name: 'keyword', group: 1, - regex: new RegExp(`(^|${SPLIT_CHARS})(${keywords.join('|')})(?=${SPLIT_CHARS}|$)`, 'g') + regex: new RegExp(`(^|${SPLIT_CHARS})(${keywords.join('|')})(?=${SPLIT_CHARS}|$)`, 'gi') }, { name: 'special', diff --git a/lib/keywords.js b/lib/keywords.js index cd7c005..cd7ad5d 100644 --- a/lib/keywords.js +++ b/lib/keywords.js @@ -1,4 +1,4 @@ -const KEYWORDS = [ +module.exports = [ 'ADD', 'ADD CONSTRAINT', 'ALTER', @@ -140,8 +140,3 @@ const KEYWORDS = [ 'PRINT', 'OVERLAPS' ] - -module.exports = [ - ...KEYWORDS, - ...KEYWORDS.map((keyword) => keyword.toLowerCase()) -]