Skip to content

Commit 4f08b1b

Browse files
committed
Finalizing package
1 parent e05d218 commit 4f08b1b

File tree

5 files changed

+62
-23
lines changed

5 files changed

+62
-23
lines changed

.changeset/young-trainers-cheer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"typed-string-interpolation": patch
3+
---
4+
5+
Finalizing package

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2023 Mikko Vänskä
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Typed string interpolation
1+
# `typed-string-interpolation`
22

33
[String interpolation](https://en.wikipedia.org/wiki/String_interpolation) utility that returns the correct type based on passed in variable substitutions.
44

@@ -8,15 +8,26 @@
88
- Sanity checks that correct variables were passed in
99
- Returns the correct type based on passed in variable substitutions
1010
- Options to customize return, pattern matching and sanity checking
11-
- Both `.cjs` and `mjs` distributions available. Use anywhere!
11+
- Both ES Module `.mjs` and CommonJS `.cjs` distributions available. Use anywhere!
12+
- Tiny footprint:
13+
- ES Module: `0.462kB` (`773B` unpacked)
14+
- CommonJS: `0.833B` (`1.75kB` unpacked)
1215

13-
## Install
16+
## Motivation
17+
18+
String interpolation/variable substitution (i.e. injecting variables within text) is a really common operation when building single and multilingual applications. Existing string interpolation utilities within the most used `i18n` / `l10n` packages like `i18next` and `formatjs` come with massive overhead while lacking thing like proper TypeScript infer support for the interpolation operation.
19+
20+
This package aims to provide a high quality string interpolation "primitive" to use as is or within other localization frameworks and tooling.
21+
22+
## Getting started
23+
24+
### Install
1425

1526
```bash
1627
npm i typed-string-interpolation
1728
```
1829

19-
## Usage
30+
### Usage
2031

2132
```ts
2233
// ES module
@@ -59,14 +70,14 @@ If the string can be joined you'll get back a string. Otherwise a union type wit
5970
stringInterpolation("hello {{world}} with number {{number}}", {
6071
world: "world",
6172
number: 1,
62-
}) // => Returns type: string
73+
}) // : string
6374
```
6475

6576
```tsx
6677
stringInterpolation("hello {{world}} with number {{number}}", {
6778
world: <span className="bold">world</span>,
6879
number: 1,
69-
}) // => Returns type: (string | JSX.Element | number)[]
80+
}) // : (string | JSX.Element | number)[]
7081
```
7182

7283
## Options
@@ -97,7 +108,7 @@ stringInterpolation(
97108
number: 1,
98109
},
99110
{ raw: true }
100-
) // => Returns type: (string | number)[]
111+
) // : (string | number)[]
101112
```
102113
103114
`pattern`
@@ -126,13 +137,20 @@ Turning of sanity checking removes `throw` from:
126137
127138
## Contributing
128139
129-
API suggestions are welcome and greatly appreciated.
140+
Easiest way to contribute is to open new issues for API suggestions and fixes.
141+
142+
### Contributing for a release
130143
131144
Basic steps for contributing for a release:
132145
133-
- Fork `main`
134-
- `npm ci`
135-
- Run tests `npm run test`
136-
- Create a changeset with `npx changeset`
146+
- Fork `main` on Github and clone fork locally
147+
- `npm ci` to install dependencies
148+
- Make changes while running tests
149+
- Unit test in watch mode:
150+
- `npm run test:unit:watch`
151+
- Unit test for types in watch mode:
152+
- `npm run test:unit:types:watch`
153+
- Once all changes are complete create a new release with changeset
154+
- `npm run changeset`
137155
- Commit and push changes
138-
- Open a pull request
156+
- Open a pull request for the fork

package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "typed-string-interpolation",
33
"description": "String interpolation with correct return type based on passed variable substitutions",
4+
"author": "Mikko Vänskä",
45
"license": "MIT",
56
"version": "0.0.2",
67
"main": "dist/index.js",
@@ -10,13 +11,22 @@
1011
"keywords": [
1112
"string",
1213
"interpolation",
14+
"substitution",
15+
"injection",
1316
"replace",
17+
"inject",
18+
"substitute",
19+
"interpolate",
1420
"variable",
1521
"variables",
1622
"type",
1723
"typed",
1824
"infer",
19-
"type-safe"
25+
"type-safe",
26+
"i18n",
27+
"l10n",
28+
"i18next",
29+
"formatjs"
2030
],
2131
"scripts": {
2232
"lint": "tsc",
@@ -26,7 +36,8 @@
2636
"test:unit:types:watch": "jest -c jest.config.tsd.js --watch",
2737
"test": "npm run test:unit && npm run test:unit:types",
2838
"build": "tsup src/index.ts --format cjs,esm --dts",
29-
"release": "npm run build && changeset publish"
39+
"release": "npm run build && changeset publish",
40+
"changeset": "changeset"
3041
},
3142
"devDependencies": {
3243
"@babel/core": "^7.20.12",

tsconfig.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
{
22
"compilerOptions": {
3-
"target": "es2020" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
3+
"target": "ES2020" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
44
"module": "commonjs" /* Specify what module code is generated. */,
5-
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing
5+
"noEmit": true /* Disable emitting files from a compilation. */,
6+
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
67
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
7-
"strict": true /* Enable all strict type-checking options. */,
8-
/* Skip type checking .d.ts files that are included with TypeScript. */
9-
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
10-
"noUncheckedIndexedAccess": true,
11-
"noEmit": true
12-
}
8+
"strict": true /* Enable all strict type-checking options. */
9+
},
10+
"exclude": ["dist", "node_modules"]
1311
}

0 commit comments

Comments
 (0)