-
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.
Imrpoved Vite configuration and prototypes
- Loading branch information
1 parent
79c5bd9
commit 00a8468
Showing
20 changed files
with
180 additions
and
115 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
File renamed without changes.
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
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
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
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
File renamed without changes.
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,19 @@ | ||
export {}; | ||
|
||
declare global { | ||
interface Object { | ||
isEqual(this: object, target: unknown): boolean; | ||
} | ||
interface Array<T> { | ||
isEqual(this: Array<T>, target: unknown): boolean; | ||
} | ||
interface String { | ||
isEqual(this: string, target: unknown): boolean; | ||
} | ||
interface Number { | ||
isEqual(this: number, target: unknown): boolean; | ||
} | ||
interface Boolean { | ||
isEqual(this: boolean, target: unknown): boolean; | ||
} | ||
} |
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,2 +1 @@ | ||
export * from './methods'; | ||
export * from './prototypes'; | ||
export * from './methods'; |
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,63 +1,22 @@ | ||
export function isEqual(this: unknown, target: unknown) { | ||
let leftChain: Array<unknown> = []; | ||
let rightChain: Array<unknown> = []; | ||
function compare2Objects(x: unknown, y: unknown) { | ||
let p; | ||
if (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y)) return true; | ||
if (x === y) return true; | ||
if ( | ||
(typeof x === 'function' && typeof y === 'function') || | ||
(x instanceof Date && y instanceof Date) || | ||
(x instanceof RegExp && y instanceof RegExp) || | ||
(x instanceof String && y instanceof String) || | ||
(x instanceof Number && y instanceof Number) | ||
) | ||
return x.toString() === y.toString(); | ||
if (!(x instanceof Object && y instanceof Object)) return false; | ||
if (Object.prototype.isPrototypeOf.call(x, y) || Object.prototype.isPrototypeOf.call(y, x)) | ||
return false; | ||
if (x.constructor !== y.constructor) return false; | ||
if (Object.prototype.valueOf.call(x) !== Object.prototype.valueOf.call(y)) return false; | ||
if (leftChain.indexOf(x) > -1 || rightChain.indexOf(y) > -1) return false; | ||
const a = (x as Record<string, unknown>) | ||
const b = (y as Record<string, unknown>) | ||
for (const p in b) { | ||
if ( | ||
Object.prototype.hasOwnProperty.call(y, p) !== | ||
Object.prototype.hasOwnProperty.call(x, p) | ||
) { | ||
return false; | ||
} else if (typeof b[p] !== typeof a[p]) { | ||
return false; | ||
} | ||
if (this === target) return true; | ||
// this verification for primitives (number, string, boolean, etc.) | ||
if (this == null || target == null || (typeof this !== 'object' && typeof target !== 'object')) | ||
return this === target; | ||
// deep object/array comparison | ||
// keep shallow copy of comparator | ||
const remainder = { | ||
...target | ||
}; | ||
for (const key in this) { | ||
if (this[key].isEqual(target[key])) { | ||
// remove properties from shallow copy to keep track of verified children | ||
delete remainder[key]; | ||
continue; | ||
} | ||
for (p in x) { | ||
if ( | ||
Object.prototype.hasOwnProperty.call(y, p) !== | ||
Object.prototype.hasOwnProperty.call(x, p) | ||
) | ||
return false; | ||
else if (typeof b[p] !== typeof b[p]) return false; | ||
switch (typeof a[p]) { | ||
case 'object': | ||
case 'function': { | ||
leftChain.push(x); | ||
rightChain.push(y); | ||
if (!compare2Objects(a[p], b[p])) return false; | ||
leftChain.pop(); | ||
rightChain.pop(); | ||
break; | ||
} | ||
default: { | ||
if (a[p] !== b[p]) return false; | ||
break; | ||
} | ||
} | ||
} | ||
return true; | ||
// if one property of comparator is not equal to itself on the original | ||
return false; | ||
} | ||
leftChain = []; | ||
rightChain = []; | ||
if (!compare2Objects(this, target)) return false; | ||
return true; | ||
// check if comparator has the same properties than original | ||
return Object.entries(remainder).length === 0; | ||
} |
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
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 |
---|---|---|
|
@@ -8,4 +8,4 @@ | |
"esModuleInterop": true | ||
}, | ||
"include": ["vite.config.ts"] | ||
} | ||
} |
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,7 +1,7 @@ | ||
import { defineConfig } from 'vite'; | ||
import config from './vite.shared'; | ||
import shared from './vite.shared'; | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig(async () => { | ||
return config; | ||
}); | ||
return shared; | ||
}); |
Oops, something went wrong.