Skip to content

Commit

Permalink
add cjs exports
Browse files Browse the repository at this point in the history
  • Loading branch information
rawpixel-vincent committed Mar 14, 2024
1 parent cd8055f commit 0d4a937
Show file tree
Hide file tree
Showing 10 changed files with 5,342 additions and 133 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
]
},
"overrides": [],
"ignorePatterns": ["*.cjs"],
"parserOptions": {
"ecmaVersion": 14,
"sourceType": "module"
Expand Down
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ The StringList class extends the Array with new methods and supercharges the arr

- `without(...$)`: filter out the given values, accept string and StringList.
- `withPrefix($)` and `withSuffix($)`: add prefix/suffix to all the words.
- `withDerivatedPrefix($)` and `withDerivatedSuffix($)`: Generate words variants with or without the given suffix/prefix depending on their presence.
- `value($)`: similar to enum but throws an error if the value doesn't exists.
- `enum[$]:$` Object is exposed as readonly.
- `withTrim()`: trim all the words.
Expand Down Expand Up @@ -129,15 +128,6 @@ const arr = list.mutable(); // => ["foo","bar"]
list.value('foo'); // 'foo'
list.value('n'); // throws error

// Generate words variants with or without the given suffix/prefix depending on their presence.
const foods = sl('food', 'bars', 'pasta', 'meatballs');
foods.withDerivatedSuffix('s');
// => SL<"food" | "bars" | "pasta" | "meatballs" | "foods" | "pastas" | "bar" | "meatball">

const tags = sl('spring', '#boot', '#typescript', 'fundamentals');
tags.withDerivatedPrefix('#');
//=> SL<"#spring" | "#boot" | "#typescript" | "#fundamentals" | "spring" | "boot" | "typescript" | "fundamentals">

const scored = sl(' has ', 'spaces', ' between ', ' o r', 'in the words')
.withTrim()
.withReplaceAll(' ', '_');
Expand Down
54 changes: 27 additions & 27 deletions StringLiteralList.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,33 +124,33 @@ export class SL extends Array {
);
}

withDerivatedSuffix(chars = '') {
return freezeIfImmutable(
this,
new SL(
...super.flatMap((t) => [
t,
t.endsWith(chars)
? t.slice(0, Math.min(t.length, chars.length) * -1)
: `${t}${chars}`,
]),
),
);
}

withDerivatedPrefix(chars = '') {
return freezeIfImmutable(
this,
new SL(
...super.flatMap((t) => [
t,
t.startsWith(chars)
? t.slice(Math.min(chars.length, t.length), t.length)
: `${chars}${t}`,
]),
),
);
}
// withDerivatedSuffix(chars = '') {
// return freezeIfImmutable(
// this,
// new SL(
// ...super.flatMap((t) => [
// t,
// t.endsWith(chars)
// ? t.slice(0, Math.min(t.length, chars.length) * -1)
// : `${t}${chars}`,
// ]),
// ),
// );
// }

// withDerivatedPrefix(chars = '') {
// return freezeIfImmutable(
// this,
// new SL(
// ...super.flatMap((t) => [
// t,
// t.startsWith(chars)
// ? t.slice(Math.min(chars.length, t.length), t.length)
// : `${chars}${t}`,
// ]),
// ),
// );
// }

withReplace(string, replacement = undefined) {
return freezeIfImmutable(
Expand Down
3 changes: 2 additions & 1 deletion jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"traceResolution": false,
"allowSyntheticDefaultImports": true
},
"include": ["*.js", "*.d.ts", "*.ts", "types/*"]
"include": ["*.js", "*.d.ts", "*.ts", "types/*.d.ts"],
"exclude": ["node_modules", "*.cjs", "**/*.cjs"]
}
Loading

0 comments on commit 0d4a937

Please sign in to comment.