Skip to content

Commit

Permalink
change npm repository
Browse files Browse the repository at this point in the history
  • Loading branch information
djalmajr committed Feb 8, 2022
1 parent 23b72c5 commit 268c0d0
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 19 deletions.
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@djalmajr/help-es",
"name": "help-es",
"version": "0.1.0",
"author": "Djalma Jr. <[email protected]>",
"license": "SEE LICENSE IN LICENSE FILE",
Expand Down Expand Up @@ -31,16 +31,13 @@
"require": "./dist/*/*.js"
}
},
"publishConfig": {
"@djalmajr:registry": "https://npm.pkg.github.com"
},
"scripts": {
"build": "node ./scripts/build.mjs minify=true && npm run build:types",
"build:dev": "node ./scripts/build.mjs watch=true",
"build:types": "tsc --emitDeclarationOnly && cp src/types.d.ts dist",
"prettier:check": "prettier --check src/**/*.{ts,tsx}",
"prettier:fix": "prettier --write src/**/*.{ts,tsx}",
"postversion": "git push && git push --tags",
"postversion": "git push && git push --tags && npm publish",
"test": "exit 0",
"version": "npm run build"
},
Expand Down
7 changes: 3 additions & 4 deletions src/assign.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { clone } from './clone';
import { curry } from './curry';
import { merge } from './merge';
import { Obj } from './types';
import { merge, MergeFn } from './merge';

export const assign = curry(<T extends Obj>(target: T, source: T): T => {
export const assign = curry((target: any, source: any) => {
return merge(clone(target), source);
});
}) as MergeFn;
5 changes: 2 additions & 3 deletions src/clone.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { isObj } from './isObj';
import { Obj } from './types';

/**
* http://documentcloud.github.io/underscore-contrib/#snapshot
*
* TODO: adicionar documentação
*/
export function clone<T extends Obj>(data: T): T {
export function clone<T extends object>(data: T): T {
if (!isObj(data)) {
return data;
}
Expand All @@ -15,7 +14,7 @@ export function clone<T extends Obj>(data: T): T {

for (const key in data) {
if (data.hasOwnProperty(key)) {
res[key] = clone(data[key]);
res[key] = clone(data[key] as any);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/isObj.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function isObj(a: unknown): a is Record<string, any> {
export function isObj(a: unknown): a is object {
return a !== null && typeof a === 'object';
}
13 changes: 8 additions & 5 deletions src/merge.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { curry } from './curry';
import { isObj } from './isObj';
import { Obj } from './types';
import { Spread } from './types';

const getCtor = (v: any) => v.constructor;

export const merge = curry(<T = Obj>(target: T, source: T): T => {
for (const [k, val] of Object.entries(source)) {
const key = k as keyof T;
export interface MergeFn {
<A extends object>(a: A): <B extends object>(b: B) => Spread<[A, B]>;
<A extends object, B extends object>(a: A, b: B): Spread<[A, B]>;
}

export const merge = curry((target: any, source: any) => {
for (const [key, val] of Object.entries(source)) {
if (isObj(val)) {
if (target[key] === void 0 || getCtor(target[key]) !== getCtor(val)) {
target[key] = new (val as any).constructor();
Expand All @@ -20,4 +23,4 @@ export const merge = curry(<T = Obj>(target: T, source: T): T => {
}

return target;
});
}) as MergeFn;
48 changes: 48 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,51 @@ export declare type Fn<A extends any[], R> = (...args: A) => R;
export declare type Obj<T = any> = Record<string, T>;

export declare type ValueOf<T> = T[keyof T];

/***
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/lodash/common/function.d.ts
*/

export declare interface Curry {
<T1, R>(func: (t1: T1) => R): Curried1<T1, R>;
<T1, T2, R>(func: (t1: T1, t2: T2) => R): Curried2<T1, T2, R>;
// <T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R): Curried3<T1, T2, T3, R>;
// <T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R): Curried4<T1, T2, T3, T4, R>;
// <T1, T2, T3, T4, T5, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5) => R): Curried5<T1, T2, T3, T4, T5, R>;
// (func: (...args: any[]) => any): (...args: any[]) => any;
}

export declare interface Curried1<T1, R> {
(): Curried1<T1, R>;
(t1: T1): R;
}
export declare interface Curried2<T1, T2, R> {
(): Curried2<T1, T2, R>;
(t1: T1): Curried1<T2, R>;
(t1: T1, t2: T2): R;
}

/***
* https://stackoverflow.com/a/49683575/2528550
*/

export declare type OptionalPropertyNames<T> = {
[K in keyof T]-?: {} extends { [P in K]: T[K] } ? K : never;
}[keyof T];

export declare type SpreadProperties<L, R, K extends keyof L & keyof R> = {
[P in K]: L[P] | Exclude<R[P], undefined>;
};

export declare type Id<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;

export declare type SpreadTwo<L, R> = Id<
Pick<L, Exclude<keyof L, keyof R>> &
Pick<R, Exclude<keyof R, OptionalPropertyNames<R>>> &
Pick<R, Exclude<OptionalPropertyNames<R>, keyof L>> &
SpreadProperties<L, R, OptionalPropertyNames<R> & keyof L>
>;

export declare type Spread<A extends readonly [...any]> = A extends [infer L, ...infer R]
? SpreadTwo<L, Spread<R>>
: unknown;

0 comments on commit 268c0d0

Please sign in to comment.