Criada a API do site
This commit is contained in:
21
node_modules/copy-anything/LICENSE
generated
vendored
Normal file
21
node_modules/copy-anything/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Luca Ban - Mesqueeb
|
||||
|
||||
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.
|
||||
136
node_modules/copy-anything/README.md
generated
vendored
Normal file
136
node_modules/copy-anything/README.md
generated
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
# Copy anything 🎭
|
||||
|
||||
<a href="https://www.npmjs.com/package/copy-anything"><img src="https://img.shields.io/npm/v/copy-anything.svg" alt="Total Downloads"></a>
|
||||
<a href="https://www.npmjs.com/package/copy-anything"><img src="https://img.shields.io/npm/dw/copy-anything.svg" alt="Latest Stable Version"></a>
|
||||
|
||||
```
|
||||
npm i copy-anything
|
||||
```
|
||||
|
||||
An optimised way to copy'ing (cloning) an object or array. A small and simple integration.
|
||||
|
||||
## Motivation
|
||||
|
||||
I created this package because I tried a lot of similar packages that do copy'ing/cloning. But all had its quirks, and _all of them break things they are not supposed to break_... 😞
|
||||
|
||||
I was looking for:
|
||||
|
||||
- a simple copy/clone function
|
||||
- has to be fast!
|
||||
- props must lose any reference to original object
|
||||
- works with arrays and objects in arrays!
|
||||
- supports symbols
|
||||
- can copy non-enumerable props as well
|
||||
- **does not break special class instances** ‼️
|
||||
|
||||
This last one is crucial! So many libraries use custom classes that create objects with special prototypes, and such objects all break when trying to copy them improperly. So we gotta be careful!
|
||||
|
||||
copy-anything will copy objects and nested properties, but only as long as they're "plain objects". As soon as a sub-prop is not a "plain object" and has a special prototype, it will copy that instance over "as is". ♻️
|
||||
|
||||
## Meet the family (more tiny utils with TS support)
|
||||
|
||||
- [is-what 🙉](https://github.com/mesqueeb/is-what)
|
||||
- [is-where 🙈](https://github.com/mesqueeb/is-where)
|
||||
- [merge-anything 🥡](https://github.com/mesqueeb/merge-anything)
|
||||
- [check-anything 👁](https://github.com/mesqueeb/check-anything)
|
||||
- [remove-anything ✂️](https://github.com/mesqueeb/remove-anything)
|
||||
- [getorset-anything 🐊](https://github.com/mesqueeb/getorset-anything)
|
||||
- [map-anything 🗺](https://github.com/mesqueeb/map-anything)
|
||||
- [filter-anything ⚔️](https://github.com/mesqueeb/filter-anything)
|
||||
- [copy-anything 🎭](https://github.com/mesqueeb/copy-anything)
|
||||
- [case-anything 🐫](https://github.com/mesqueeb/case-anything)
|
||||
- [flatten-anything 🏏](https://github.com/mesqueeb/flatten-anything)
|
||||
- [nestify-anything 🧅](https://github.com/mesqueeb/nestify-anything)
|
||||
|
||||
## Usage
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
```js
|
||||
import { copy } from 'copy-anything'
|
||||
|
||||
const original = { name: 'Ditto', type: { water: true } }
|
||||
const copy = copy(original)
|
||||
|
||||
// now if we change a nested prop like the type
|
||||
copy.type.water = false
|
||||
// or add a new nested prop
|
||||
copy.type.fire = true
|
||||
|
||||
// then the original object will still be the same:
|
||||
(original.type.water === true) // true
|
||||
(original.type.fire === undefined) // true
|
||||
```
|
||||
|
||||
> Please note, by default copy-anything does not copy non-enumerable props. If you need to copy those, see the instructions further down below.
|
||||
|
||||
## Works with arrays
|
||||
|
||||
It will also clone arrays, **as well as objects inside arrays!** 😉
|
||||
|
||||
```js
|
||||
const original = [{ name: 'Squirtle' }]
|
||||
const copy = copy(original)
|
||||
|
||||
// now if we change a prop in the array
|
||||
copy[0].name = 'Wartortle'
|
||||
// or add a new item to the array
|
||||
copy.push({ name: 'Charmander' })
|
||||
|
||||
// then the original array will still be the same:
|
||||
(original[0].name === 'Squirtle') // true
|
||||
(original[1] === undefined) // true
|
||||
```
|
||||
|
||||
## Non-enumerable
|
||||
|
||||
By default, copy-anything only copies enumerable properties. If you also want to copy non-enumerable properties you can do so by passing that as an option.
|
||||
|
||||
```js
|
||||
const original = { name: 'Bulbasaur' }
|
||||
// bulbasaur's ID is non-enumerable
|
||||
Object.defineProperty(original, 'id', {
|
||||
value: '001',
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
})
|
||||
const copy1 = copy(original)
|
||||
(copy1.id === undefined) // true
|
||||
|
||||
const copy2 = copy(original, { nonenumerable: true })
|
||||
(copy2.id === '001') // true
|
||||
```
|
||||
|
||||
## Limit to specific props
|
||||
|
||||
You can limit to specific props.
|
||||
|
||||
```js
|
||||
const original = { name: 'Flareon', type: ['fire'], id: '136' }
|
||||
const copy = copy(original, { props: ['name'] })
|
||||
|
||||
(copy) // will look like: `{ name: 'Flareon' }`
|
||||
```
|
||||
|
||||
> Please note, if the props you have specified are non-enumerable, you will also need to pass `{nonenumerable: true}`.
|
||||
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
## Source code
|
||||
|
||||
The source code is literally just these lines. Most of the magic comes from the isPlainObject function from the [is-what library](https://github.com/mesqueeb/is-what).
|
||||
|
||||
```JavaScript
|
||||
import { isPlainObject } from 'is-what'
|
||||
|
||||
export function copy (target) {
|
||||
if (isArray(target)) return target.map(i => copy(i))
|
||||
if (!isPlainObject(target)) return target
|
||||
return Object.keys(target)
|
||||
.reduce((carry, key) => {
|
||||
const val = target[key]
|
||||
carry[key] = copy(val)
|
||||
return carry
|
||||
}, {})
|
||||
}
|
||||
```
|
||||
19
node_modules/copy-anything/dist/index.d.ts
generated
vendored
Normal file
19
node_modules/copy-anything/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
export type Options<T> = {
|
||||
props?: (keyof T)[];
|
||||
nonenumerable?: boolean;
|
||||
};
|
||||
/**
|
||||
* Copy (clone) an object and all its props recursively to get rid of any prop referenced of the
|
||||
* original object. Arrays are also cloned, however objects inside arrays are still linked.
|
||||
*
|
||||
* @param target Target can be anything
|
||||
* @param [options={}] See type {@link Options} for more details.
|
||||
*
|
||||
* - `{ props: ['key1'] }` will only copy the `key1` property. When using this you will need to cast
|
||||
* the return type manually (in order to keep the TS implementation in here simple I didn't
|
||||
* built a complex auto resolved type for those few cases people want to use this option)
|
||||
* - `{ nonenumerable: true }` will copy all non-enumerable properties. Default is `{}`
|
||||
*
|
||||
* @returns The target with replaced values
|
||||
*/
|
||||
export declare function copy<T>(target: T, options?: Options<T>): T;
|
||||
52
node_modules/copy-anything/dist/index.js
generated
vendored
Normal file
52
node_modules/copy-anything/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
import { isArray, isPlainObject } from 'is-what';
|
||||
function assignProp(carry, key, newVal, originalObject, includeNonenumerable) {
|
||||
const propType = {}.propertyIsEnumerable.call(originalObject, key)
|
||||
? 'enumerable'
|
||||
: 'nonenumerable';
|
||||
if (propType === 'enumerable')
|
||||
carry[key] = newVal;
|
||||
if (includeNonenumerable && propType === 'nonenumerable') {
|
||||
Object.defineProperty(carry, key, {
|
||||
value: newVal,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copy (clone) an object and all its props recursively to get rid of any prop referenced of the
|
||||
* original object. Arrays are also cloned, however objects inside arrays are still linked.
|
||||
*
|
||||
* @param target Target can be anything
|
||||
* @param [options={}] See type {@link Options} for more details.
|
||||
*
|
||||
* - `{ props: ['key1'] }` will only copy the `key1` property. When using this you will need to cast
|
||||
* the return type manually (in order to keep the TS implementation in here simple I didn't
|
||||
* built a complex auto resolved type for those few cases people want to use this option)
|
||||
* - `{ nonenumerable: true }` will copy all non-enumerable properties. Default is `{}`
|
||||
*
|
||||
* @returns The target with replaced values
|
||||
*/
|
||||
export function copy(target, options = {}) {
|
||||
if (isArray(target)) {
|
||||
return target.map((item) => copy(item, options));
|
||||
}
|
||||
if (!isPlainObject(target)) {
|
||||
return target;
|
||||
}
|
||||
const props = Object.getOwnPropertyNames(target);
|
||||
const symbols = Object.getOwnPropertySymbols(target);
|
||||
return [...props, ...symbols].reduce((carry, key) => {
|
||||
// Skip __proto__ properties to prevent prototype pollution
|
||||
if (key === '__proto__')
|
||||
return carry;
|
||||
if (isArray(options.props) && !options.props.includes(key)) {
|
||||
return carry;
|
||||
}
|
||||
const val = target[key];
|
||||
const newVal = copy(val, options);
|
||||
assignProp(carry, key, newVal, target, options.nonenumerable);
|
||||
return carry;
|
||||
}, {});
|
||||
}
|
||||
55
node_modules/copy-anything/package.json
generated
vendored
Normal file
55
node_modules/copy-anything/package.json
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"name": "copy-anything",
|
||||
"version": "4.0.5",
|
||||
"description": "An optimised way to copy'ing an object. A small and simple integration",
|
||||
"type": "module",
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": "./dist/index.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "vitest run",
|
||||
"lint": "tsc --noEmit && eslint ./src",
|
||||
"build": "del-cli dist && tsc",
|
||||
"release": "npm run lint && npm run build && np"
|
||||
},
|
||||
"dependencies": {
|
||||
"is-what": "^5.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@cycraft/eslint": "^0.4.4",
|
||||
"@cycraft/tsconfig": "^0.1.2",
|
||||
"del-cli": "^6.0.0",
|
||||
"np": "^10.2.0",
|
||||
"vitest": "^3.0.9"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"keywords": [
|
||||
"copy",
|
||||
"clone",
|
||||
"json-stringify",
|
||||
"stringify-parse",
|
||||
"object",
|
||||
"copy-objects",
|
||||
"clone-objects",
|
||||
"json-stringify-json-parse",
|
||||
"deep-clone",
|
||||
"deep-copy",
|
||||
"typescript",
|
||||
"ts"
|
||||
],
|
||||
"author": "Luca Ban - Mesqueeb (https://cycraft.co)",
|
||||
"funding": "https://github.com/sponsors/mesqueeb",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mesqueeb/copy-anything.git"
|
||||
},
|
||||
"homepage": "https://github.com/mesqueeb/copy-anything#readme",
|
||||
"bugs": "https://github.com/mesqueeb/copy-anything/issues"
|
||||
}
|
||||
Reference in New Issue
Block a user