-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update LICENSE and README files with new information and examples
- Loading branch information
shixinzhu
committed
Aug 24, 2023
1 parent
7d2c385
commit e37fd6f
Showing
3 changed files
with
131 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,73 @@ | ||
# constant-sage | ||
<h1 align="center">constant-sage</h1> | ||
|
||
[![Unit Test](https://github.com/sxzz/ts-lib-starter/actions/workflows/unit-test.yml/badge.svg)](https://github.com/sxzz/ts-lib-starter/actions/workflows/unit-test.yml) | ||
<p align="center">constant-sage can generate various commonly used data structures with complete types based on the constant dictionary you define.</p> | ||
|
||
<p align="center"> | ||
<a href="https://github.com/4xii/constant-sage">GitHub</a> | ||
| | ||
<a href="https://github.com/4xii/constant-sage/blob/main/README.zh-CN.md">简体中文文档</a> | ||
</p> | ||
|
||
## Features | ||
|
||
- ✨ Convenient and easy to use | ||
- 🦾 Full TypeScript support | ||
|
||
## Install | ||
|
||
```bash | ||
npm i constant-sage | ||
pnpm i constant-sage | ||
yarn add constant-sage | ||
``` | ||
|
||
## Usage | ||
|
||
```typescript | ||
import { defineConstants } from 'your-module-name'; | ||
|
||
// Define the basic structure of constants | ||
const defs = [ | ||
{ key: 'KEY_1', value: 'VALUE_1', name: 'Name 1' }, | ||
{ key: 'KEY_2', value: 'VALUE_2', name: 'Name 2' }, | ||
{ key: 'KEY_3', value: 'VALUE_3', name: 'Name 3' }, | ||
] as const; | ||
|
||
// Generate the constant collection | ||
const { KEYS, VALUES } = defineConstants(defs); | ||
|
||
// Use the constants | ||
console.log(KEYS); // ['KEY_1', 'KEY_2', 'KEY_3'] | ||
console.log(VALUES); // ['VALUE_1', 'VALUE_2', 'VALUE_3'] | ||
// ... | ||
``` | ||
|
||
## API | ||
|
||
```typescript | ||
defineConstants(defs: readonly IBaseDef[], labelspace?: string) | ||
``` | ||
|
||
### Generate a constant collection | ||
|
||
- defs: An array defining the basic structure of constants, where each element contains the key, value, and name fields. | ||
- labelspace (optional): The namespace of the constant collection. | ||
|
||
Returns: An object containing the generated constants. | ||
|
||
### 常量集合对象 | ||
|
||
- KEYS: An array of all constant keys. | ||
- VALUES: An array of all constant values. | ||
- KV: An object mapping constant keys to values. | ||
- VK: An object mapping constant values to keys. | ||
- MAP_BY_KEY: A constant mapping object indexed by key. | ||
- MAP_BY_VALUE: A constant mapping object indexed by value. | ||
- MAP: An object mapping constant keys to values. | ||
- KN: An object mapping constant keys to names. | ||
- VN: An object mapping constant values to names. | ||
- LIST: An array containing all the constants. | ||
|
||
## License | ||
|
||
[MIT](./LICENSE) License © 2023 [4xii](https://github.com/4xii) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<h1 align="center">constant-sage</h1> | ||
|
||
<p align="center">constant-sage可以通过你定义的常量字典,生成类型完善的各种常用的 | ||
数据结构</p> | ||
|
||
## Features | ||
|
||
- ✨ 方便便捷 | ||
- 🦾 完善的 TypeScript 支持 | ||
|
||
## Install | ||
|
||
```bash | ||
npm i constant-sage | ||
pnpm i constant-sage | ||
yarn add constant-sage | ||
``` | ||
|
||
## 使用方法 | ||
|
||
```typescript | ||
import { defineConstants } from 'your-module-name'; | ||
|
||
// 定义常量的基本结构 | ||
const defs = [ | ||
{ key: 'KEY_1', value: 'VALUE_1', name: 'Name 1' }, | ||
{ key: 'KEY_2', value: 'VALUE_2', name: 'Name 2' }, | ||
{ key: 'KEY_3', value: 'VALUE_3', name: 'Name 3' }, | ||
] as const; | ||
|
||
// 生成常量集合 | ||
const { KEYS, VALUES } = defineConstants(defs); | ||
|
||
// 使用常量 | ||
console.log(KEYS); // ['KEY_1', 'KEY_2', 'KEY_3'] | ||
console.log(VALUES); // ['VALUE_1', 'VALUE_2', 'VALUE_3'] | ||
// ... | ||
``` | ||
|
||
## API | ||
|
||
```typescript | ||
defineConstants(defs: readonly IBaseDef[], labelspace?: string) | ||
``` | ||
|
||
### 生成常量集合。 | ||
|
||
- defs: 定义常量的基本结构的数组,每个元素包含 key、value 和 name 字段。 | ||
- labelspace (可选): 常量集合的命名空间。 | ||
|
||
返回值: 包含生成常量的对象。 | ||
|
||
### 常量集合对象 | ||
|
||
- KEYS: 所有常量的键数组。 | ||
- VALUES: 所有常量的值数组。 | ||
- KV: 常量键值对的对象。 | ||
- VK: 常量值键对的对象。 | ||
- MAP_BY_KEY: 以键为索引的常量映射对象。 | ||
- MAP_BY_VALUE: 以值为索引的常量映射对象。 | ||
- MAP: 常量键值对的对象。 | ||
- KN: 以键为索引的常量名称映射对象。 | ||
- VN: 以值为索引的常量名称映射对象。 | ||
- LIST: 包含所有常量的数组。 | ||
|
||
## License | ||
|
||
[MIT](./LICENSE) License © 2023 [4xii](https://github.com/4xii) |