Skip to content

Commit

Permalink
Update identifiers matcher and invalid/unsupported condition error me…
Browse files Browse the repository at this point in the history
…ssage
  • Loading branch information
aaronccasanova committed Jun 12, 2022
1 parent f5fcabe commit 1dd2b84
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/violet-terms-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'truuu': patch
---

Updated identifiers matcher and invalid/unsupported condition error message
38 changes: 19 additions & 19 deletions packages/truuu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ npm i -g truuu
## Usage

```sh
$ truuu 'isFoo && !isBar'
$ truuu 'isPizza && !hasPineapple'
```

```
╔══════════════════════════════════════════════╗
║ _____ ____ _ _ _ _ _ _ ║
║ |_ _| _ \| | | | | | | | | | ║
║ | | | |_) | | | | | | | | | | ║
║ | | | _ <| |_| | |_| | |_| | ║
║ |_| |_| \_\\___/ \___/ \___/ ║
║ ║
╟────────────────────┬────────────────────────╢
isFoo │ isBarisFoo && !isBar
╟────────────────────┼────────────────────────╢
║ false │ false │ false ║
╟────────────────────┼────────────────────────╢
║ false │ true │ false ║
╟────────────────────┼────────────────────────╢
║ true │ false │ true ║
╟────────────────────┼────────────────────────╢
║ true │ true │ false ║
╚════════════════════╧════════════════════════╝
╔══════════════════════════════════════════════════════════════
_____ ____ _ _ _ _ _ _
|_ _| _ \| | | | | | | | | |
| | | |_) | | | | | | | | | |
| | | _ <| |_| | |_| | |_| |
|_| |_| \_\\___/ \___/ \___/
╟────────────────────┬──────────────┬──────────────────────────╢
isPizza │ hasPineappleisPizza && !hasPineapple
╟────────────────────┼──────────────┼──────────────────────────╢
║ false │ false false
╟────────────────────┼──────────────┼──────────────────────────╢
║ false │ true false
╟────────────────────┼──────────────┼──────────────────────────╢
║ true │ false true
╟────────────────────┼──────────────┼──────────────────────────╢
║ true │ true false
╚════════════════════╧══════════════╧══════════════════════════╝
```
1 change: 1 addition & 0 deletions packages/truuu/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default {
}),
],
external: [
'node:vm',
...Object.keys(pkg.dependencies ?? {}),
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
Expand Down
10 changes: 8 additions & 2 deletions packages/truuu/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ if (typeof input !== 'string') exit('Please enter a JavaScript condition')

// Extract unique identifiers from the input condition
const identifiers = Array.from(
new Set([...input.matchAll(/\w+/g)].map(([identifier]) => identifier ?? '')),
new Set(
// https://regex101.com/r/ueqoAD/1
// https://stackoverflow.com/a/2108007
[...input.matchAll(/(?!true|false\b)\b[\w.]+/g)].map(
([identifier]) => identifier ?? '',
),
),
)

if (!identifiers.length) exit('Error: No variables found in the condition')
Expand All @@ -32,7 +38,7 @@ for (const permutation of permutations) {
input,
)

const errorMessage = `Error: Invalid JavaScript condition ${chalk.red(
const errorMessage = `Error: Invalid or unsupported JavaScript condition ${chalk.red(
`'${input}'`,
)}`

Expand Down

0 comments on commit 1dd2b84

Please sign in to comment.