Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Noelware/utils
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d44a93e0b007671e8ab27c2816afb1b649f4c8a9
Choose a base ref
...
head repository: Noelware/utils
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a0e5aa694dfc19732d89277fa1051cd5491e8a3f
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on May 16, 2021

  1. Copy the full SHA
    1872aa5 View commit details
  2. move types into main namespace

    auguwu committed May 16, 2021
    Copy the full SHA
    47dd968 View commit details
  3. Add DotNotation type

    auguwu committed May 16, 2021
    Copy the full SHA
    a0e5aa6 View commit details
Showing with 301 additions and 350 deletions.
  1. +93 −0 index.d.ts
  2. +207 −349 package-lock.json
  3. +1 −1 package.json
93 changes: 93 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -33,8 +33,19 @@
*/
/** */
declare global {
/**
* Filters from it's [Conidition] in the specified [Base] object
*/
type FilterFlags<Base, Condition> = { [K in keyof Base]: Base[K] extends Condition ? K : never };

/**
* Get the keys of the [Base]'s allowed names
*/
type AllowedNames<Base, Condition> = FilterFlags<Base, Condition>[keyof Base];

/**
* Object of the picked values of the [Base] from the [Condition].
*/
type FilterOut<Base, Condition> = Pick<Base, keyof Omit<Base, AllowedNames<Base, Condition>>>;

/** Nestly make all properties in a object not required */
@@ -53,6 +64,47 @@ declare global {
? P
: unknown;

/** Nestly make all properties in a object required */
type DeepRequired<T> = {
[P in keyof T]-?: DeepRequired<T[P]>;
};

/**
* Returns all the keys of [T] as the specified [Sep]erator.
*/
// credit: Ben - https://github.com/Benricheson101
type ObjectKeysWithSeperator<
T extends Record<string, any>,
Sep extends string = '.',
Keys extends keyof T = keyof T
> = Keys extends string
? T[Keys] extends any[]
? Keys
: T[Keys] extends object
? `${Keys}${Sep}${ObjectKeysWithSeperator<T[Keys], Sep>}`
: Keys
: never;

/**
* Returns all the keys from the [Obj]ect as a seperated object
*/
// credit: Ben - https://github.com/Benricheson101
type KeyToPropType<
T extends Record<string, any>,
Obj extends ObjectKeysWithSeperator<T, Sep>,
Sep extends string = '.'
> = Obj extends `${infer First}${Sep}${infer Rest}`
? KeyToPropType<T[First], Rest extends ObjectKeysWithSeperator<T[First], Sep> ? Rest : never, Sep>
: Obj extends `${infer First}`
? T[First]
: T;

/**
* Returns a object from a nested object that can be used
* for dot notation
*/
type DotNotation<T extends Record<string, unknown>, Keys extends string> = KeyToPropType<T, ObjectKeysWithSeperator<T, '.', Keys>>;

/**
* Interface to mark [[T]] as a `import('...')`/`require('...')` value.
* If this module is a CJS import, it'll just return the class, so you can do:
@@ -135,6 +187,47 @@ declare namespace utils {
[P: string]: Listener;
}

/** Nestly make all properties in a object required */
type DeepRequired<T> = {
[P in keyof T]-?: DeepRequired<T[P]>;
};

/**
* Returns all the keys of [T] as the specified [Sep]erator.
*/
// credit: Ben - https://github.com/Benricheson101
type ObjectKeysWithSeperator<
T extends Record<string, any>,
Sep extends string = '.',
Keys extends keyof T = keyof T
> = Keys extends string
? T[Keys] extends any[]
? Keys
: T[Keys] extends object
? `${Keys}${Sep}${ObjectKeysWithSeperator<T[Keys], Sep>}`
: Keys
: never;

/**
* Returns all the keys from the [Obj]ect as a seperated object
*/
// credit: Ben - https://github.com/Benricheson101
type KeyToPropType<
T extends Record<string, any>,
Obj extends ObjectKeysWithSeperator<T, Sep>,
Sep extends string = '.'
> = Obj extends `${infer First}${Sep}${infer Rest}`
? KeyToPropType<T[First], Rest extends ObjectKeysWithSeperator<T[First], Sep> ? Rest : never, Sep>
: Obj extends `${infer First}`
? T[First]
: T;

/**
* Returns a object from a nested object that can be used
* for dot notation
*/
type DotNotation<T extends Record<string, unknown>, Keys extends string> = KeyToPropType<T, ObjectKeysWithSeperator<T, '.', Keys>>;

/** Returns the version of `@augu/utils` */
export const version: string;

556 changes: 207 additions & 349 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@augu/utils",
"description": "🌸 Extra utilities to keep code consise and non-repeative.",
"version": "1.5.2",
"version": "1.5.3",
"main": "build/index.js",
"types": "index.d.ts",
"author": "August <cutie@floofy.dev>",