diff --git a/.github/README.md b/.github/README.md index 1569d17..ec643b8 100644 --- a/.github/README.md +++ b/.github/README.md @@ -130,6 +130,8 @@ Lite version: ```js // tailwind.config.ts +import { replacer } from "twg/lite/replacer" +// or import replacer from "twg/lite/replacer" // Rest like above @@ -676,7 +678,7 @@ interface TWGOptions { --- -💥 Light version: +💥 Lite version: ### `replacer({ /* option */ })(content)` diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cd343e..d35a69c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,18 @@ Undocumented APIs should be considered internal and may change without warning. - A bit slower, especially on the first time, when nothing is cached. - 4 more dependencies. +## [1.2.4] - 2024-08-24 + +### Refactor + +- Refactor `extractor()` function. +- Export `replacer()` as both `default` and `named` export. + +### Chore + +- Fixed typo in README. +- Update bundle shield links in npm README. + ## [1.2.3] - 2024-08-24 ### Core change diff --git a/package.json b/package.json index 03cc88d..7fdc9cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "twg", - "version": "1.2.3", + "version": "1.2.4", "description": "A utility function for grouping TailwindCSS variants.", "author": "Nguyễn Hoàng Nhân (https://github.com/hoangnhan2ka3)", "homepage": "https://github.com/hoangnhan2ka3/twg", diff --git a/src/lite/replacer/index.ts b/src/lite/replacer/index.ts index aacc665..53c930b 100644 --- a/src/lite/replacer/index.ts +++ b/src/lite/replacer/index.ts @@ -35,3 +35,5 @@ export function replacer({ callee = "twg" }: ReplacerLiteOption = {}) { } catch (e) { return content } } } + +export default replacer diff --git a/src/processor/extractor.ts b/src/processor/extractor.ts index 2850a6f..e3ceb7e 100644 --- a/src/processor/extractor.ts +++ b/src/processor/extractor.ts @@ -16,8 +16,7 @@ export function extractor( inCallee = false, calleeDepth = 0 - const objects: string[] = [] - const calleeList = Array.isArray(callee) ? callee : [callee] + const objects = [] for (let i = 0; i < content.length; i++) { const char = content[i] @@ -29,12 +28,10 @@ export function extractor( } // Skip template literals - if (inTemplateLiteral) { - continue - } + if (inTemplateLiteral) continue // Check if the current char is in any of the calleeList - for (const calleeName of calleeList) { + for (const calleeName of Array.isArray(callee) ? callee : [callee]) { if (content.slice(i, i + calleeName.length + 1) === `${calleeName}(`) { inCallee = true calleeDepth = 1