@shareyou/core 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +95 -2
- package/dist/index.d.ts +8 -0
- package/dist/index.js +6 -0
- package/package.json +49 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 IzayoiKyomu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,96 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Shareyou
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shareyou provides one entry point for all implemented Shareyou utility packages.
|
|
4
|
+
Import the default `shareyou` object to access utilities through `shareyou.xxx`,
|
|
5
|
+
or use named imports for individual functions and types.
|
|
6
|
+
|
|
7
|
+
Requires Node.js 22 or newer. This package uses ES modules and includes TypeScript
|
|
8
|
+
declarations. TypeScript 5.4 or newer is required for template type inference.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
pnpm add @shareyou/core
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import shareyou from '@shareyou/core';
|
|
20
|
+
|
|
21
|
+
const text = shareyou.templater('Hello, {{name:string}}! {{count:number!}} messages.', {
|
|
22
|
+
name: 'Shareyou',
|
|
23
|
+
count: 3,
|
|
24
|
+
});
|
|
25
|
+
// Hello, Shareyou! 3 messages.
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The default and named `shareyou` exports reference the same aggregate object.
|
|
29
|
+
You can choose a shorter local name when importing it:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import _ from '@shareyou/core';
|
|
33
|
+
|
|
34
|
+
_.templater('Hello, {{name}}!', { name: 'Shareyou' });
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Functions and types are also available as named exports:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { templater, type TemplateParameters } from '@shareyou/core';
|
|
41
|
+
|
|
42
|
+
const parameters: TemplateParameters<'{{count:number!}}'> = { count: 3 };
|
|
43
|
+
const text: string = templater('{{count:number!}} messages.', parameters);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Re-exports preserve each function's original implementation and type inference.
|
|
47
|
+
Templater still returns a primitive string synchronously, warns on non-strict
|
|
48
|
+
type mismatches, and throws on missing parameters or strict type mismatches.
|
|
49
|
+
|
|
50
|
+
## Included packages
|
|
51
|
+
|
|
52
|
+
| Package | Object API | Named exports |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| `@shareyou/templater` | `shareyou.templater` | `templater`, `TemplateParameters`, `TemplateParameterNames` |
|
|
55
|
+
| `@shareyou/i18n` | `shareyou.i18n` (factory) | `createI18n`, `I18nError`, i18n interfaces and types |
|
|
56
|
+
|
|
57
|
+
Create an isolated translator through the object API or named factory:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import shareyou, { createI18n } from '@shareyou/core';
|
|
61
|
+
|
|
62
|
+
console.log(shareyou.i18n === createI18n); // true
|
|
63
|
+
const i18n = shareyou.i18n({
|
|
64
|
+
locale: 'en',
|
|
65
|
+
messages: { en: { cart: '{{#plural count}}{{:one}}{{#}} item{{:other}}{{#}} items{{/plural}}' } },
|
|
66
|
+
});
|
|
67
|
+
i18n.t('cart', { count: 3 }); // 3 items
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
See [the i18n package documentation](https://shareyou.overl0ad1ng.com/docs/i18n) for templater syntax, generated
|
|
71
|
+
argument contracts, fallback and formatting. Install the standalone i18n package
|
|
72
|
+
directly when using its type-generation CLI.
|
|
73
|
+
|
|
74
|
+
Independent packages remain usable on their own. Importing this aggregate does
|
|
75
|
+
not register methods globally or modify the objects exported by those packages.
|
|
76
|
+
|
|
77
|
+
## Local development
|
|
78
|
+
|
|
79
|
+
From the repository root:
|
|
80
|
+
|
|
81
|
+
```sh
|
|
82
|
+
pnpm install
|
|
83
|
+
pnpm build
|
|
84
|
+
pnpm test
|
|
85
|
+
pnpm typecheck
|
|
86
|
+
pnpm --filter @shareyou/core demo
|
|
87
|
+
pnpm --filter @shareyou/core pack
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Workspace dependencies resolve to local packages during development. Packing
|
|
91
|
+
converts `workspace:^` into a regular version range, so the published aggregate
|
|
92
|
+
depends on the standalone packages. Publish dependency versions before publishing
|
|
93
|
+
the aggregate that requires them.
|
|
94
|
+
|
|
95
|
+
To include another implemented package, add it to `dependencies`, re-export its
|
|
96
|
+
public API in `src/index.ts`, and add its utilities to the aggregate object.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createI18n } from '@shareyou/i18n';
|
|
2
|
+
export * from '@shareyou/templater';
|
|
3
|
+
export * from '@shareyou/i18n';
|
|
4
|
+
export declare const shareyou: {
|
|
5
|
+
templater: typeof import("@shareyou/templater").templater;
|
|
6
|
+
i18n: typeof createI18n;
|
|
7
|
+
};
|
|
8
|
+
export default shareyou;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { shareyou as templaterUtilities } from '@shareyou/templater';
|
|
2
|
+
import { createI18n } from '@shareyou/i18n';
|
|
3
|
+
export * from '@shareyou/templater';
|
|
4
|
+
export * from '@shareyou/i18n';
|
|
5
|
+
export const shareyou = { ...templaterUtilities, i18n: createI18n };
|
|
6
|
+
export default shareyou;
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shareyou/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A unified entry point for Shareyou utilities",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=22"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"shareyou",
|
|
26
|
+
"utilities",
|
|
27
|
+
"typescript"
|
|
28
|
+
],
|
|
29
|
+
"author": {
|
|
30
|
+
"name": "IzayoiKyomu",
|
|
31
|
+
"email": "kyomu@overl0ad1ng.com"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"homepage": "https://shareyou.overl0ad1ng.com/docs",
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@shareyou/i18n": "^0.1.0",
|
|
40
|
+
"@shareyou/templater": "^0.1.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"typescript": "7.0.2"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
47
|
+
"build": "pnpm run clean && tsc -p tsconfig.json",
|
|
48
|
+
"test": "pnpm run build && node --test",
|
|
49
|
+
"typecheck": "pnpm run build && tsc -p tsconfig.typecheck.json",
|
|
50
|
+
"demo": "pnpm run build && node examples/node.mjs"
|
|
51
|
+
}
|
|
6
52
|
}
|