Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@modenr-kit/types 라이브러리 추가 #30

Merged
merged 3 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ pnpm i @modern-kit/utils

<br />

### @modern-kit/types <a href="https://www.npmjs.com/package/@modern-kit/types" target="_blank"><img align="center" src="https://img.shields.io/npm/v/@modern-kit/types.svg" /></a> <a href="https://bundlephobia.com/package/@modern-kit/types" target="_blank"><img align="center" src="https://img.shields.io/bundlephobia/minzip/@modern-kit/types/latest"></a>

- 유용한 타입스크립트 유틸 타입들을 제공합니다.

```shell
npm i @modern-kit/types
```

```shell
yarn add @modern-kit/types
```

```shell
pnpm i @modern-kit/types
```

<br />

## Tests

```shell
Expand Down
17 changes: 16 additions & 1 deletion docs/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,26 @@ export default function Home(): JSX.Element {
<img src="https://img.shields.io/bundlephobia/minzip/@modern-kit/utils/latest" />
</a>
</h2>

<p className={styles.mainContentParagraph}>
클라이언트 개발과 관련된 유용한 유틸리티 함수를 제공하는
라이브러리입니다.
</p>
<h2 className={styles.mainContentHead}>
@modern-kit/types
<a
href="https://www.npmjs.com/package/@modern-kit/types"
target="_blank">
<img src="https://img.shields.io/npm/v/@modern-kit/types.svg" />
</a>
<a
href="https://bundlephobia.com/package/@modern-kit/types"
target="_blank">
<img src="https://img.shields.io/bundlephobia/minzip/@modern-kit/types/latest" />
</a>
</h2>
<p className={styles.mainContentParagraph}>
유용한 타입스크립트 유틸 타입들을 제공합니다.
</p>
</div>
</main>
<div className={styles.contributors}>
Expand Down
33 changes: 33 additions & 0 deletions packages/types/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
*.log
npm-debug.log*

# Coverage directory used by tools like istanbul
coverage
.nyc_output

# Dependency directories
node_modules

# npm package lock
package-lock.json
yarn.lock

# project files
src

# git
.gitignore

# setting
tsconfig.json
tsconfig.paths.json
.prettierrc
.eslintrc.js
webpack.*.js
babel.config.js
rollup.config.mjs

# test
coverage
vite.config.ts
vite.setup.ts
32 changes: 32 additions & 0 deletions packages/types/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# @modern-kit/utils <a href="https://www.npmjs.com/package/@modern-kit/utils" target="_blank"><img align="center" src="https://img.shields.io/npm/v/@modern-kit/utils.svg" /></a> <a href="https://bundlephobia.com/package/@modern-kit/utils" target="_blank"><img align="center" src="https://img.shields.io/bundlephobia/minzip/@modern-kit/utils/latest"></a>

유용한 타입스크립트 유틸 타입들을 제공합니다.

<br />

## Documentation
`@modern-kit`의 공식 문서는 아래 웹사이트에서 확인하실 수 있습니다
- <a href="https://modern-agile-team.github.io/modern-kit" target="_blank">https://modern-agile-team.github.io/modern-kit</a>

<br />

## Usage
```shell
npm i @modern-kit/types
```

```shell
yarn add @modern-kit/types
```


```shell
pnpm i @modern-kit/types
```

<br />

## License
MIT © Modern Agile. See [LICENSE](../../LICENSE) for details.

<br />
46 changes: 46 additions & 0 deletions packages/types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "@modern-kit/types",
"sideEffects": false,
"version": "1.0.0",
"description": "modern-kit/types",
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./package.json": "./package.json"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"test": "vitest",
"test:run": "vitest run",
"typecheck": "tsc",
"build": "rm -rf dist && yarn typecheck"
},
"author": "ssi02014 <[email protected]>",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"devDependencies": {
"tslib": "^2.6.2",
"typescript": "^5.1.6",
"vitest": "^1.5.0"
},
"keywords": [
"react",
"next",
"utils",
"component",
"ui",
"hooks",
"custom hooks"
],
"gitHead": "7722785374b897572934e335817ec297ad45a943"
}
20 changes: 20 additions & 0 deletions packages/types/src/Arrayable/Arrayable.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { describe, expectTypeOf, it } from 'vitest';
import { Arrayable } from '.';

describe('Nullable', () => {
it('제네릭 타입으로 넣어준 원시 타입과 해당 원시 타입으로 이뤄진 배열을 허용합니다.', () => {
const test = ['123'] as Arrayable<string>;

expectTypeOf(test).toEqualTypeOf<string | string[]>();
});

it('조건식으로 원시 타입, 배열 타입 각각 타입을 좁힐 수 있습니다.', () => {
const test = ['123'] as Arrayable<string>;

if (Array.isArray(test)) {
expectTypeOf(test).toEqualTypeOf<string[]>();
} else {
expectTypeOf(test).toEqualTypeOf<string>();
}
});
});
1 change: 1 addition & 0 deletions packages/types/src/Arrayable/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Arrayable<T> = T | Array<T>;
10 changes: 10 additions & 0 deletions packages/types/src/ExcludeNullish/ExcludeNullish.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { describe, expectTypeOf, it } from 'vitest';
import { ExcludeNullish } from '.';

describe('ExcludeNullish', () => {
it('제네릭으로 넣어준 타입에서 null과 undefined를 제외합니다.', () => {
const test = '123' as ExcludeNullish<string | null | undefined>;

expectTypeOf(test).toEqualTypeOf<string>();
});
});
1 change: 1 addition & 0 deletions packages/types/src/ExcludeNullish/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type ExcludeNullish<T> = Exclude<T, null | undefined>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { describe, expectTypeOf, it } from 'vitest';
import { ExtendOmittedProperties } from '.';

describe('ExcludeNullish', () => {
it('첫 번째 제네릭 타입의 프로퍼티를 Omit으로 제외 후 제외 한 프로퍼티를 확장합니다.', () => {
type TestType = { foo: string; bar: number };

const test: ExtendOmittedProperties<TestType, { bar: string }> = {
foo: 'foo',
bar: 'bar',
};

// toEqualTypeOf 이슈로 우회 테스트
expectTypeOf(test as { foo: string; bar: string }).toEqualTypeOf<{
foo: string;
bar: string;
}>();
});
});
4 changes: 4 additions & 0 deletions packages/types/src/ExtendOmittedProperties/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type ExtendOmittedProperties<
T extends Record<PropertyKey, any>,
E extends Record<PropertyKey, any>
> = Omit<T, keyof E> & E;
11 changes: 11 additions & 0 deletions packages/types/src/IndexSignature/IndexSignature.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { describe, expectTypeOf, it } from 'vitest';
import { IndexSignature } from '.';

describe('IndexSignature', () => {
it('객체가 가질 수 있는 프로퍼티를 동적으로 추가할 수 있게 허용합니다. value의 타입은 제네릭으로 넣어준 타입입니다.', () => {
const test: IndexSignature<string> = { foo: 'foo', bar: 'bar' };
test.test = '1';

expectTypeOf(test).toEqualTypeOf<{ [key: PropertyKey]: string }>();
});
});
3 changes: 3 additions & 0 deletions packages/types/src/IndexSignature/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type IndexSignature<T> = {
[key: PropertyKey]: T;
};
18 changes: 18 additions & 0 deletions packages/types/src/Nullable/Nullable.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { describe, expectTypeOf, it } from 'vitest';
import { Nullable } from '.';

describe('Nullable', () => {
it('제네릭 타입으로 넣어준 타입과 더불어 null과 undefined를 허용합니다.', () => {
const test = '123' as Nullable<string>;

expectTypeOf(test).toEqualTypeOf<string | null | undefined>();
});

it('조건식으로 타입을 좁히면 제네릭 타입으로 좁혀집니다.', () => {
const test = '123' as Nullable<string>;

if (test) {
expectTypeOf(test).toEqualTypeOf<string>();
}
});
});
1 change: 1 addition & 0 deletions packages/types/src/Nullable/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Nullable<T> = T | null | undefined;
19 changes: 19 additions & 0 deletions packages/types/src/ObjectEntries/ObjectEntries.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { describe, expectTypeOf, it } from 'vitest';
import { ObjectEntries } from '.';

describe('ObjectKeys', () => {
it('Object.entries의 반환 타입을 명확하게 합니다. symbol은 제외합니다.', () => {
const test = {
foo: 'foo',
bar: 'bar',
} as const;

const defaultEntries = Object.entries(test);
const AppliedEntries = Object.entries(test) as ObjectEntries<typeof test>;

expectTypeOf(defaultEntries).toEqualTypeOf<[string, 'foo' | 'bar'][]>();
expectTypeOf(AppliedEntries).toEqualTypeOf<
['foo' | 'bar', 'foo' | 'bar'][]
>();
});
});
6 changes: 6 additions & 0 deletions packages/types/src/ObjectEntries/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ObjectKeys } from '../ObjectKeys';

export type ObjectEntries<T extends Record<PropertyKey, T[keyof T]>> = [
ObjectKeys<T>,
T[ObjectKeys<T>]
][];
Loading