Skip to content

Commit d560449

Browse files
Version 5.0.0 (#29)
## Breaking changes * Get rid of CommonJS support ## Minor changes * Get rid of some unnecessary files in `dist` * Enable `ESNext` library's target ## Chore * Update dependencies * Replace `ts-jest` by `@swc-node/jest` * Refine `package.json` * Update documentation
1 parent 78fdbf0 commit d560449

File tree

11 files changed

+543
-186
lines changed

11 files changed

+543
-186
lines changed

.eslintrc

Lines changed: 209 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,224 @@
11
{
22
"extends": [
3+
// https://github.com/eslint/eslint/blob/master/conf/eslint-recommended.js#L13-L71
4+
"eslint:recommended",
5+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/src/configs/recommended.ts#L6-L33
36
"plugin:@typescript-eslint/recommended",
4-
"prettier",
7+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/src/configs/recommended-requiring-type-checking.ts#L6-L25
8+
"plugin:@typescript-eslint/recommended-requiring-type-checking",
9+
// https://github.com/benmosher/eslint-plugin-import/blob/master/config/recommended.js#L6-L27
10+
"plugin:import/recommended",
11+
// https://github.com/benmosher/eslint-plugin-import/blob/master/config/typescript.js#L9-L27
12+
"plugin:import/typescript",
13+
// https://github.com/jest-community/eslint-plugin-jest#rules
14+
"plugin:jest/recommended",
15+
// https://github.com/jest-community/eslint-plugin-jest#rules
16+
"plugin:jest/style",
17+
// https://github.com/prettier/eslint-plugin-prettier/blob/master/eslint-plugin-prettier.js#L92-L100
518
"plugin:prettier/recommended"
619
],
7-
"parser": "@typescript-eslint/parser",
20+
// Some @typescript-eslint rules need it
21+
"parserOptions": {
22+
"project": "tsconfig.json"
23+
},
24+
"root": true,
825
"rules": {
9-
"import/prefer-default-export": "off",
26+
// https://eslint.org/docs/rules/consistent-return
27+
"consistent-return": "error",
28+
// https://eslint.org/docs/rules/default-case-last
29+
"default-case-last": "error",
30+
// https://eslint.org/docs/rules/default-case
31+
"default-case": "error",
32+
// Handled by @typescript-eslint/default-param-last
33+
// https://eslint.org/docs/rules/default-param-last
34+
"default-param-last": "off",
35+
// Handled by @typescript-eslint/dot-notation
36+
// https://eslint.org/docs/rules/dot-notation
37+
"dot-notation": "off",
38+
// https://eslint.org/docs/rules/eqeqeq
39+
"eqeqeq": "error",
40+
// https://eslint.org/docs/rules/id-denylist
41+
"id-denylist": ["error", "err"],
42+
// https://eslint.org/docs/rules/line-comment-position
43+
"line-comment-position": [
44+
"error",
45+
{ "position": "above", "ignorePattern": "(Prefix|Suffix) (=|!)==" }
46+
],
47+
// https://eslint.org/docs/rules/no-alert
48+
"no-alert": "error",
49+
// https://eslint.org/docs/rules/no-console
50+
"no-console": ["error", { "allow": ["error"] }],
51+
// https://eslint.org/docs/rules/no-implicit-coercion
52+
"no-implicit-coercion": "error",
53+
// https://eslint.org/docs/rules/no-new-wrappers
54+
"no-new-wrappers": "error",
55+
// https://eslint.org/docs/rules/no-param-reassign
56+
"no-param-reassign": "error",
57+
// https://eslint.org/docs/rules/no-plusplus
58+
"no-plusplus": "error",
59+
// https://eslint.org/docs/rules/no-restricted-imports
60+
"no-restricted-imports": [
61+
"error",
62+
{
63+
"name": "lodash",
64+
"message": "Please use `import <package> from \"lodash/<package>\";` instead."
65+
}
66+
],
67+
// https://eslint.org/docs/rules/no-return-assign
68+
"no-return-assign": "error",
69+
// Handled by @typescript-eslint/return-await
70+
// https://eslint.org/docs/rules/no-return-await
71+
"no-return-await": "off",
72+
// https://eslint.org/docs/rules/no-self-compare
73+
"no-self-compare": "error",
74+
// https://eslint.org/docs/rules/no-unneeded-ternary
75+
"no-unneeded-ternary": "error",
76+
// Handled by @typescript-eslint/no-unused-expressions
77+
// https://eslint.org/docs/rules/no-unused-expressions
78+
"no-unused-expressions": "off",
79+
// https://eslint.org/docs/rules/no-useless-computed-key
80+
"no-useless-computed-key": "error",
81+
// https://eslint.org/docs/rules/no-useless-concat
82+
"no-useless-concat": "error",
83+
// https://eslint.org/docs/rules/no-useless-rename
84+
"no-useless-rename": "error",
85+
// https://eslint.org/docs/rules/no-useless-return
86+
"no-useless-return": "error",
87+
// https://eslint.org/docs/rules/object-shorthand
88+
"object-shorthand": "error",
89+
// https://eslint.org/docs/rules/one-var
90+
"one-var": ["error", "never"],
91+
// https://eslint.org/docs/rules/operator-assignment
92+
"operator-assignment": ["error", "always"],
93+
// https://eslint.org/docs/rules/prefer-arrow-callback
94+
"prefer-arrow-callback": "error",
95+
// https://eslint.org/docs/rules/prefer-destructuring
96+
"prefer-destructuring": "error",
97+
// https://eslint.org/docs/rules/prefer-named-capture-group
98+
"prefer-named-capture-group": "error",
99+
// https://eslint.org/docs/rules/prefer-promise-reject-errors
100+
"prefer-promise-reject-errors": "error",
101+
// https://eslint.org/docs/rules/prefer-template
102+
"prefer-template": "error",
103+
// https://eslint.org/docs/rules/radix
104+
"radix": "error",
105+
// https://eslint.org/docs/rules/sort-imports
10106
"sort-imports": [
11107
"error",
12108
{
13109
"ignoreCase": false,
14110
"ignoreDeclarationSort": true,
15111
"ignoreMemberSort": false
16112
}
17-
]
113+
],
114+
// https://eslint.org/docs/rules/yoda
115+
"yoda": ["error", "never"],
116+
117+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/array-type.md
118+
"@typescript-eslint/array-type": ["error", { "default": "array-simple" }],
119+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/consistent-indexed-object-style.md
120+
"@typescript-eslint/consistent-indexed-object-style": "error",
121+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/consistent-type-assertions.md
122+
"@typescript-eslint/consistent-type-assertions": "error",
123+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/consistent-type-definitions.md
124+
"@typescript-eslint/consistent-type-definitions": "error",
125+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/consistent-type-imports.md
126+
"@typescript-eslint/consistent-type-imports": [
127+
"error",
128+
{ "prefer": "no-type-imports" }
129+
],
130+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/default-param-last.md
131+
"@typescript-eslint/default-param-last": "error",
132+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/dot-notation.md
133+
"@typescript-eslint/dot-notation": "error",
134+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-function-return-type.md
135+
"@typescript-eslint/explicit-function-return-type": [
136+
"error",
137+
{ "allowExpressions": true }
138+
],
139+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/method-signature-style.md
140+
"@typescript-eslint/method-signature-style": "error",
141+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-confusing-non-null-assertion.md
142+
"@typescript-eslint/no-confusing-non-null-assertion": "error",
143+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-implicit-any-catch.md
144+
"@typescript-eslint/no-implicit-any-catch": "error",
145+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-invalid-void-type.md
146+
"@typescript-eslint/no-invalid-void-type": "error",
147+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unnecessary-condition.md
148+
"@typescript-eslint/no-unnecessary-condition": "error",
149+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unnecessary-type-arguments.md
150+
"@typescript-eslint/no-unnecessary-type-arguments": "error",
151+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unnecessary-type-constraint.md
152+
"@typescript-eslint/no-unnecessary-type-constraint": "error",
153+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-expressions.md
154+
"@typescript-eslint/no-unused-expressions": "error",
155+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-reduce-type-parameter.md
156+
"@typescript-eslint/prefer-reduce-type-parameter": "error",
157+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-string-starts-ends-with.md
158+
"@typescript-eslint/prefer-string-starts-ends-with": "error",
159+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/return-await.md
160+
"@typescript-eslint/return-await": "error",
161+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/strict-boolean-expressions.md
162+
"@typescript-eslint/strict-boolean-expressions": "error",
163+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/unified-signatures.md
164+
"@typescript-eslint/unified-signatures": "error",
165+
166+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/exports-last.md
167+
"import/exports-last": "error",
168+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/first.md
169+
"import/first": "error",
170+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/group-exports.md
171+
"import/group-exports": "error",
172+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/newline-after-import.md
173+
"import/newline-after-import": "error",
174+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-absolute-path.md
175+
"import/no-absolute-path": "error",
176+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-anonymous-default-export.md
177+
"import/no-anonymous-default-export": "error",
178+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-mutable-exports.md
179+
"import/no-mutable-exports": "error",
180+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-self-import.md
181+
"import/no-self-import": "error",
182+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-useless-path-segments.md
183+
"import/no-useless-path-segments": ["error", { "noUselessIndex": true }],
184+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md
185+
"import/order": [
186+
"error",
187+
{
188+
"alphabetize": { "order": "asc", "caseInsensitive": false },
189+
"groups": [
190+
"builtin",
191+
"external",
192+
"internal",
193+
["parent", "sibling", "index"],
194+
"object",
195+
"type",
196+
"unknown"
197+
],
198+
"newlines-between": "always",
199+
"warnOnUnassignedImports": true
200+
}
201+
],
202+
203+
// https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/consistent-test-it.md
204+
"jest/consistent-test-it": ["error", { "withinDescribe": "test" }],
205+
// https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-duplicate-hooks.md
206+
"jest/no-duplicate-hooks": "error",
207+
// https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/prefer-hooks-on-top.md
208+
"jest/prefer-hooks-on-top": "error",
209+
// https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/prefer-spy-on.md
210+
"jest/prefer-spy-on": "error",
211+
// https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/prefer-strict-equal.md
212+
"jest/prefer-strict-equal": "error",
213+
// https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/require-to-throw-message.md
214+
"jest/require-to-throw-message": "error"
215+
},
216+
"settings": {
217+
// https://github.com/benmosher/eslint-plugin-import/issues/1582#issuecomment-568951354
218+
"import/resolver": {
219+
"node": {
220+
"moduleDirectory": ["node_modules", "src"]
221+
}
222+
}
18223
}
19224
}

README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,24 @@ A small, dependency-free and strongly typed template engine.
3232
## Features
3333

3434
- **Light-weight**. Less than 1 KiB (actual size depends on imported functions).
35-
- **Dependency-free**. Only bundled JavaScript files and TypeScript type declarations.
35+
- **Dependency-free**. Only bundled JavaScript files and TypeScript type declarations are included.
3636
- **Tree-shakable**. Only imported code comes to your bundle.
37-
- **ES Modules** and **CommonJS** syntax are supported.
3837
- Strongly typed with **TypeScript**. All types are exported alongside with the core functions.
3938
- **Flexible interpolation options change**. Change variables' markers in each function or use a special function to configure them once for further usage.
4039

4140
## Examples
4241

4342
```typescript
44-
// ES Modules syntax
4543
import { hydrateText } from "hydrate-text";
46-
// CommonJS syntax
47-
const hydrateText = require("hydrate-text").hydrateText;
4844

49-
// 'Hello, John!'
45+
// "Hello, John!"
5046
console.log(
5147
hydrateText("Hello, {username}!", {
5248
username: "John",
5349
}),
5450
);
5551

56-
// '/users/42'
52+
// "/users/42"
5753
console.log(
5854
hydrateText(
5955
"/users/:id",
@@ -96,10 +92,10 @@ import { configureHydrateText } from "hydrate-text";
9692

9793
const hydrateRoute = configureHydrateText({ prefix: ":" });
9894

99-
// '/users/42'
95+
// "/users/42"
10096
console.log(hydrateRoute("/users/:id", { id: 42 }));
10197

102-
// '/users/42'
98+
// "/users/42"
10399
console.log(
104100
hydrateRoute(
105101
"/users/(id)",
@@ -153,9 +149,9 @@ Check out [types.ts](./src/types.ts) file for more information.
153149

154150
## Known issues
155151

156-
- If a string potentially has 8+ variables, an error "Type instantiation is excessively deep and possibly infinite" can occur. Until it is resolved, it is better to break the string into several pieces to avoid the error.
152+
- If a string has more than 8 variables, an error "Type instantiation is excessively deep and possibly infinite" can occur. In this case, it is better to break the string down into several pieces.
157153

158-
Tracking the issue here: [Type instantiation is excessively deep and possibly infinite](https://github.com/vasilii-kovalev/hydrate-text/issues/27)
154+
Check out the [original TypeScript issue](https://github.com/microsoft/TypeScript/issues/37613) for more information.
159155

160156
## Background
161157

jest.config.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"collectCoverageFrom": ["src/index.ts"],
3+
"testEnvironment": "node",
4+
"transform": {
5+
"^.+\\.ts$": "@swc-node/jest"
6+
}
7+
}

package.json

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "hydrate-text",
3-
"version": "4.0.0",
3+
"version": "5.0.0",
44
"description": "A small, dependency-free and strongly typed template engine.",
5-
"main": "dist/cjs/index.js",
6-
"module": "dist/esm/index.js",
7-
"types": "dist/types/index.d.ts",
85
"sideEffects": false,
6+
"type": "module",
7+
"main": "./dist/index.js",
8+
"types": "./dist/types.d.ts",
99
"files": [
10-
"/dist"
10+
"./dist"
1111
],
1212
"keywords": [
1313
"javascript",
@@ -29,42 +29,37 @@
2929
"url": "https://github.com/vasilii-kovalev/hydrate-text/issues"
3030
},
3131
"scripts": {
32-
"tslint": "tsc -p tsconfig.tslint.json",
33-
"types": "check-dts",
34-
"eslint:check": "eslint --ext .ts src --color",
35-
"eslint:fix": "yarn eslint:check --fix",
36-
"prettier:check": "prettier --check .",
37-
"prettier:fix": "prettier --write .",
38-
"lint": "yarn tslint && yarn types && yarn eslint:check && yarn prettier:check",
39-
"test": "jest",
40-
"build:esm": "tsc -p tsconfig.esm.json",
41-
"build:cjs": "tsc -p tsconfig.cjs.json",
42-
"build": "yarn build:esm && yarn build:cjs",
43-
"prepare": "yarn build",
44-
"prepublishOnly": "yarn lint && yarn test",
32+
"tslint": "tsc --project tsconfig.tslint.json",
33+
"types": "check-dts **/*.ts",
34+
"eslint:check": "eslint src",
35+
"eslint:fix": "eslint src --fix",
36+
"prettier:check": "prettier . --check",
37+
"prettier:fix": "prettier . --write",
38+
"lint": "npm-run-all tslint types eslint:check prettier:check",
39+
"test": "jest --coverage",
40+
"build:js": "tsc --project tsconfig.build.json",
41+
"build:types": "tsc --project tsconfig.types.json",
42+
"build": "npm-run-all build:js build:types",
43+
"postbuild": "node postbuild.js",
44+
"prepare": "npm-run-all build",
45+
"prepublishOnly": "npm-run-all lint test",
4546
"postversion": "git push && git push --tags"
4647
},
4748
"devDependencies": {
49+
"@swc-node/jest": "^1.3.1",
4850
"@types/jest": "^26.0.24",
49-
"@types/node": "^16.3.1",
50-
"@typescript-eslint/eslint-plugin": "^4.28.3",
51-
"@typescript-eslint/parser": "^4.28.3",
52-
"check-dts": "^0.5.3",
53-
"eslint": "^7.30.0",
54-
"eslint-config-prettier": "^8.3.0",
55-
"eslint-plugin-import": "^2.23.4",
56-
"eslint-plugin-prettier": "^3.4.0",
51+
"@types/node": "^16.4.5",
52+
"@typescript-eslint/eslint-plugin": "4.28.5",
53+
"@typescript-eslint/parser": "4.28.5",
54+
"check-dts": "^0.5.4",
55+
"eslint": "7.31.0",
56+
"eslint-config-prettier": "8.3.0",
57+
"eslint-plugin-import": "2.23.4",
58+
"eslint-plugin-jest": "24.4.0",
59+
"eslint-plugin-prettier": "3.4.0",
5760
"jest": "^27.0.6",
61+
"npm-run-all": "^4.1.5",
5862
"prettier": "^2.3.2",
59-
"ts-jest": "^27.0.3",
6063
"typescript": "^4.3.5"
61-
},
62-
"jest": {
63-
"preset": "ts-jest",
64-
"testEnvironment": "node",
65-
"collectCoverage": true,
66-
"collectCoverageFrom": [
67-
"src/index.ts"
68-
]
6964
}
7065
}

postbuild.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import fs from "fs";
2+
3+
fs.rmSync("./dist/types.js", { force: true });

tsconfig.build.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"noEmit": false,
5+
"outDir": "./dist"
6+
},
7+
"exclude": ["**/tests/*.ts", "**/types.ts"]
8+
}

0 commit comments

Comments
 (0)