Skip to content

Commit

Permalink
refactor(typing): normalize exports
Browse files Browse the repository at this point in the history
  • Loading branch information
lowlighter committed May 31, 2024
1 parent 12b9f5d commit a1e2372
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 46 deletions.
2 changes: 1 addition & 1 deletion typing/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 🧰 Utility types

[![JSR](https://jsr.io/badges/@libs/typing)](https://jsr.io/@libs/typing) [![JSR Score](https://jsr.io/badges/@libs/typing/score)](https://jsr.io/@libs/typing) [![Coverage](https://libs-coverage.lecoq.io/typing/badge.svg)](https://libs-coverage.lecoq.io/typing)
[![JSR](https://jsr.io/badges/@libs/typing)](https://jsr.io/@libs/typing) [![JSR Score](https://jsr.io/badges/@libs/typing/score)](https://jsr.io/@libs/typing) [![NPM](https://img.shields.io/npm/v/@lowlighter%2Ftyping?logo=npm&labelColor=cb0000&color=183e4e)](https://www.npmjs.com/package/@lowlighter/typing) [![Coverage](https://libs-coverage.lecoq.io/typing/badge.svg)](https://libs-coverage.lecoq.io/typing)

- [`📚 Documentation`](https://jsr.io/@libs/typing/doc)

Expand Down
2 changes: 2 additions & 0 deletions typing/deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
},
"exports": {
".": "./mod.ts",
"./types": "./types.ts",
"./func": "./func.ts"
},
"npm": true,
"imports": {
"@libs/testing": "jsr:@libs/testing@1"
},
Expand Down
46 changes: 2 additions & 44 deletions typing/mod.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,2 @@
/** Read-write accessor. */
//deno-lint-ignore no-explicit-any
export type rw = any

/** Callback function. */
// deno-lint-ignore ban-types
export type callback = Function

/** Record. */
export type record<T = unknown> = Record<PropertyKey, T>

/** Extract key type from {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map | Map}. */
export type MapKey<T> = T extends Map<infer U, unknown> ? U : never

/** Extract value type from {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map | Map}. */
export type MapValue<T> = T extends Map<unknown, infer U> ? U : never

/** Extract value type from {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set | Set}. */
export type SetValue<T> = T extends Set<infer U> ? U : never

/** Extract key type from {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WeakMap | WeakMap}. */
export type WeakMapKey<T> = T extends WeakMap<infer U, unknown> ? U : never

/** Extract value type from {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WeakMap | WeakMap}. */
export type WeakMapValue<T> = T extends WeakMap<WeakKey, infer U> ? U : never

/** Extract value type from {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WeakSet | WeakSet}. */
export type WeakSetValue<T> = T extends WeakSet<infer U> ? U : never

/** Optional type. */
export type Optional<T> = T | undefined

/** Nullable type. */
export type Nullable<T> = T | null

/** Promisable type. */
export type Promisable<T> = T | Promise<T>

/** Arrayable type. */
export type Arrayable<T> = T | Array<T>

/** Extract function argument. */
// deno-lint-ignore no-explicit-any
export type Arg<T extends ((...args: any[]) => any), index extends number = 0, required extends boolean = false> = required extends true ? NonNullable<Parameters<T>[index]> : Parameters<T>[index]
export type * from "./types.ts"
export * from "./func.ts"
2 changes: 1 addition & 1 deletion typing/mod_test.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import "./mod.ts"
import "./mod.ts"
44 changes: 44 additions & 0 deletions typing/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/** Read-write accessor. */
//deno-lint-ignore no-explicit-any
export type rw = any

/** Callback function. */
// deno-lint-ignore ban-types
export type callback = Function

/** Record. */
export type record<T = unknown> = Record<PropertyKey, T>

/** Extract key type from {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map | Map}. */
export type MapKey<T> = T extends Map<infer U, unknown> ? U : never

/** Extract value type from {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map | Map}. */
export type MapValue<T> = T extends Map<unknown, infer U> ? U : never

/** Extract value type from {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set | Set}. */
export type SetValue<T> = T extends Set<infer U> ? U : never

/** Extract key type from {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WeakMap | WeakMap}. */
export type WeakMapKey<T> = T extends WeakMap<infer U, unknown> ? U : never

/** Extract value type from {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WeakMap | WeakMap}. */
export type WeakMapValue<T> = T extends WeakMap<WeakKey, infer U> ? U : never

/** Extract value type from {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WeakSet | WeakSet}. */
export type WeakSetValue<T> = T extends WeakSet<infer U> ? U : never

/** Optional type. */
export type Optional<T> = T | undefined

/** Nullable type. */
export type Nullable<T> = T | null

/** Promisable type. */
export type Promisable<T> = T | Promise<T>

/** Arrayable type. */
export type Arrayable<T> = T | Array<T>

/** Extract function argument. */
// deno-lint-ignore no-explicit-any
export type Arg<T extends ((...args: any[]) => any), index extends number = 0, required extends boolean = false> = required extends true ? NonNullable<Parameters<T>[index]> : Parameters<T>[index]
1 change: 1 addition & 0 deletions typing/types_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./types.ts"

0 comments on commit a1e2372

Please sign in to comment.