Website Structure

This commit is contained in:
supalerk-ar66 2026-01-13 10:46:40 +07:00
parent 62812f2090
commit 71f0676a62
22365 changed files with 4265753 additions and 791 deletions

View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 Austin Paquette
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,181 @@
<p align="center"></p>
<div align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://cdn.forcir.com/oss/forcir-object-deep-merge/assets/images/logos/dark.png" height="64">
<source media="(prefers-color-scheme: light)" srcset="https://cdn.forcir.com/oss/forcir-object-deep-merge/assets/images/logos/light.png" height="64">
<img alt="Forcir Object Deep Merge Logo" src="https://cdn.forcir.com/oss/forcir-object-deep-merge/assets/images/logos/light.png" height="64">
</picture>
</div>
<p align="center"><strong>Strongly-typed deep and recursive object merging with support for all value types.</strong></p>
<p align="center"></p>
## Install
```bash
pnpm add object-deep-merge
```
```bash
yarn add object-deep-merge
```
```bash
npm install object-deep-merge
```
## Basic Usage
```ts
import { merge } from "object-deep-merge";
```
### Simply merge two objects, with no nested properties
```ts
const merged = merge({ foo: false }, { bar: true });
console.log({ merged });
```
<details><summary>Output</summary>
```json
{
"merged": {
"foo": false,
"bar": true
}
}
```
</details>
## Typed Usage
### `merge` Type Signature
The `merge` function accepts two optional type generics. `TData` and `TResult`.
```ts
function merge<TData extends MergeableObject = MergeableObject, TResult extends MergeableObject = TData>(
source: TData,
target: TData,
...targets: Array<TData>
): TResult;
```
> [!IMPORTANT]
> The [`Merge`](https://github.com/sindresorhus/type-fest/blob/main/source/merge.d.ts) and [`MergeDeep`](https://github.com/sindresorhus/type-fest/blob/main/source/merge-deep.d.ts) types from [`type-fest`](https://github.com/sindresorhus/type-fest) are great additions to this library. It is not unreasonable to use those types for your merge typing needs.
Without explicitly passing in types the function will infer the shape of the object(s) passed in.
- Passing in `TData` will validate the shape of the objects passed in.
- Passing in `TResult` will override the output type. While this should be used sparingly, it provides a convenient approach for correctly typing partial types into complete types.
### Simple Example w/o Generics
```ts
type Data = {
name: string;
description: string;
};
const base: Data = { name: "object-deep-merge", description: "merge objects" };
const overrides: Partial<Data> = { description: "merge objects, deeply" };
const merged = merge(base, overrides);
// Type is inferred so the signature becomes:
// function merge<Partial<Data>, Partial<Data>>(source: Partial<Data>, target: Partial<Data>, ...targets: Partial<Data>[]): Partial<Data>
// TData = Partial<Data>
// TResult = Data
console.log({ merged });
```
<details><summary>Output</summary>
```json
{
"merged": {
"name": "object-deep-merge",
"description": "merge objects, deeply"
}
}
```
</details>
### Simple Example w/ `TData` Generic
> [!NOTE]
> Passing in TData will validate the shape of the objects passed in.
```ts
type Data = {
name: string;
description: string;
};
const base: Data = { name: "object-deep-merge", description: "merge objects" };
const overrides: Partial<Data> = { description: "merge objects, deeply" };
const merged: Partial<Data> = merge<Partial<Data>>(base, overrides);
// TData = Partial<Data>
// TResult = Data
console.log({ merged });
```
<details><summary>Output</summary>
```json
{
"merged": {
"name": "object-deep-merge",
"description": "merge objects, deeply"
}
}
```
</details>
### Simple Example w/ `TData` and `TResult` Generics
> [!NOTE]
> Passing in `TResult` will override the output type. While this should be used sparingly, it provides a convenient approach for correctly typing partial types into complete types.
```ts
type Data = {
name: string;
description: string;
};
const base: Data = { name: "object-deep-merge", description: "merge objects" };
const overrides: Partial<Data> = { description: "merge objects, deeply" };
const merged: Data = merge<Partial<Data>, Data>(base, overrides);
// TData = Partial<Data>
// TResult = Data
console.log({ merged });
```
<details><summary>Output</summary>
```json
{
"merged": {
"name": "object-deep-merge",
"description": "merge objects, deeply"
}
}
```
</details>

View file

@ -0,0 +1 @@
"use strict";var y=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var w=(e,t)=>{for(var c in t)y(e,c,{get:t[c],enumerable:!0})},x=(e,t,c,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of m(t))!k.call(e,r)&&r!==c&&y(e,r,{get:()=>t[r],enumerable:!(s=g(t,r))||s.enumerable});return e};var A=e=>x(y({},"__esModule",{value:!0}),e);var S={};w(S,{initialValue:()=>f,isMap:()=>l,isMapInstance:()=>T,isObjectLiteral:()=>u,isSet:()=>b,isSetInstance:()=>j,merge:()=>M,objectKeys:()=>p});module.exports=A(S);var f={};function l(e){return T(e)}function T(e){return e instanceof Map}function b(e){return j(e)}function j(e){return e instanceof Set}function u(e){return!!e&&e.constructor===Object}function p(e){return Object.keys(e)}function M(e,t,...c){let s=f;for(let r of[e,t,...c]){if(!u(r))throw new TypeError("Expected all arguments to be object literals.");let o={...s},O=p(r);for(let i of O){let a=o[i],n=r[i];if(a!==n){if(u(a)&&u(n)){o[i]=M(a,n);continue}if(Array.isArray(a)&&Array.isArray(n)){o[i]=[...new Set([...a,...n])];continue}if(l(a)&&l(n)){o[i]=new Map([...a,...n]);continue}if(b(a)&&b(n)){o[i]=new Set([...a,...n]);continue}o[i]=n}}s=o}return s}0&&(module.exports={initialValue,isMap,isMapInstance,isObjectLiteral,isSet,isSetInstance,merge,objectKeys});

View file

@ -0,0 +1,12 @@
type MergeableObject = Record<string | number | symbol, any>;
declare const initialValue: MergeableObject;
declare function isMap<TKey = unknown, TValue = unknown>(input: any): input is Map<TKey, TValue>;
declare function isMapInstance(input: any): boolean;
declare function isSet<T = unknown>(input: any): input is Set<T>;
declare function isSetInstance(input: any): boolean;
declare function isObjectLiteral(input: any): boolean;
declare function objectKeys<T extends object>(object: T): Array<keyof T>;
declare function merge<TData extends MergeableObject = MergeableObject, TResult extends MergeableObject = TData>(source: TData, target: TData, ...targets: Array<TData>): TResult;
export { type MergeableObject, initialValue, isMap, isMapInstance, isObjectLiteral, isSet, isSetInstance, merge, objectKeys };

View file

@ -0,0 +1,12 @@
type MergeableObject = Record<string | number | symbol, any>;
declare const initialValue: MergeableObject;
declare function isMap<TKey = unknown, TValue = unknown>(input: any): input is Map<TKey, TValue>;
declare function isMapInstance(input: any): boolean;
declare function isSet<T = unknown>(input: any): input is Set<T>;
declare function isSetInstance(input: any): boolean;
declare function isObjectLiteral(input: any): boolean;
declare function objectKeys<T extends object>(object: T): Array<keyof T>;
declare function merge<TData extends MergeableObject = MergeableObject, TResult extends MergeableObject = TData>(source: TData, target: TData, ...targets: Array<TData>): TResult;
export { type MergeableObject, initialValue, isMap, isMapInstance, isObjectLiteral, isSet, isSetInstance, merge, objectKeys };

View file

@ -0,0 +1 @@
var l={};function s(e){return T(e)}function T(e){return e instanceof Map}function u(e){return j(e)}function j(e){return e instanceof Set}function o(e){return!!e&&e.constructor===Object}function b(e){return Object.keys(e)}function M(e,y,...f){let i=l;for(let c of[e,y,...f]){if(!o(c))throw new TypeError("Expected all arguments to be object literals.");let r={...i},p=b(c);for(let a of p){let n=r[a],t=c[a];if(n!==t){if(o(n)&&o(t)){r[a]=M(n,t);continue}if(Array.isArray(n)&&Array.isArray(t)){r[a]=[...new Set([...n,...t])];continue}if(s(n)&&s(t)){r[a]=new Map([...n,...t]);continue}if(u(n)&&u(t)){r[a]=new Set([...n,...t]);continue}r[a]=t}}i=r}return i}export{l as initialValue,s as isMap,T as isMapInstance,o as isObjectLiteral,u as isSet,j as isSetInstance,M as merge,b as objectKeys};

View file

@ -0,0 +1,85 @@
{
"name": "object-deep-merge",
"version": "2.0.0",
"private": false,
"description": "Strongly-typed deep and recursive object merging. Considers all nested levels of objects, arrays, sets and maps.",
"keywords": [
"typescript",
"typescript-library",
"type-safe",
"typesafe",
"object-merge",
"deep-merge",
"merge-object",
"merge-objects",
"deep-merge-object",
"object-merging",
"merge-options",
"object-deep-merge",
"object-deep-merging",
"deep-merging",
"deep-merge-objects"
],
"homepage": "https://github.com/forcir/object-deep-merge",
"bugs": {
"url": "https://github.com/forcir/object-deep-merge/issues"
},
"license": "MIT",
"author": {
"name": "Forcir Engineering",
"email": "engineering@forcir.com",
"url": "https://code.forcir.com"
},
"type": "module",
"main": "dist/index.js",
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
}
},
"types": "dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "run-s build:*",
"build:prepare": "rimraf dist",
"build:code": "tsup src/index.ts --format cjs,esm --dts --minify",
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
"format": "prettier --check \"**/*.{cjs,js,json,md,ts,tsx}\"",
"format:fix": "prettier --write \"**/*.{cjs,js,json,md,ts,tsx}\"",
"lint": "eslint \"**/*.{cjs,cts,js,jsx,mjs,mts,ts,tsx}\"",
"lint:fix": "eslint --fix \"**/*.{cjs,cts,js,jsx,mjs,mts,ts,tsx}\"",
"prepublishOnly": "run-s build",
"test": "NODE_OPTIONS='--experimental-vm-modules --require ./scripts/suppress-experimental-vm-modules-warning.cjs' jest --runInBand",
"test:coverage": "NODE_OPTIONS='--experimental-vm-modules --require ./scripts/suppress-experimental-vm-modules-warning.cjs' jest --coverage"
},
"prettier": "@forcir/prettier-config",
"eslintConfig": {
"extends": "@forcir/eslint-config"
},
"devDependencies": {
"@digitak/esrun": "3.2.24",
"@forcir/eslint-config": "1.0.3",
"@forcir/prettier-config": "1.0.2",
"@forcir/tsconfig": "1.0.4",
"@types/jest": "29.5.14",
"eslint": "8.47.0",
"jest": "29.7.0",
"npm-run-all": "4.1.5",
"prettier": "3.0.2",
"rimraf": "6.0.1",
"ts-jest": "29.1.1",
"ts-node": "10.9.1",
"tsup": "8.5.0",
"typescript": "5.1.6"
},
"packageManager": "pnpm@10.17.0"
}