Skip to content

Commit

Permalink
refactor: extractor()
Browse files Browse the repository at this point in the history
- Refactor `extractor()` function.
- Export `replacer()` as both `default` and `named` export.

chore:
- Fixed typo in README.
- Update bundle shield links in npm README.
  • Loading branch information
hoangnhan2ka3 committed Aug 24, 2024
1 parent f51999f commit 2bc195e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -676,7 +678,7 @@ interface TWGOptions {
---
💥 Light version:
💥 Lite version:
### `replacer({ /* option */ })(content)`
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> (https://github.com/hoangnhan2ka3)",
"homepage": "https://github.com/hoangnhan2ka3/twg",
Expand Down
2 changes: 2 additions & 0 deletions src/lite/replacer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ export function replacer({ callee = "twg" }: ReplacerLiteOption = {}) {
} catch (e) { return content }
}
}

export default replacer
9 changes: 3 additions & 6 deletions src/processor/extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down

0 comments on commit 2bc195e

Please sign in to comment.