update
This commit is contained in:
parent
d9becc67b6
commit
9308795b8b
964 changed files with 104265 additions and 16 deletions
106
node_modules/map-obj/index.d.ts
generated
vendored
Normal file
106
node_modules/map-obj/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,106 @@
|
|||
declare namespace mapObject {
|
||||
type Mapper<
|
||||
SourceObjectType extends {[key: string]: any},
|
||||
MappedObjectKeyType extends string,
|
||||
MappedObjectValueType
|
||||
> = (
|
||||
sourceKey: keyof SourceObjectType,
|
||||
sourceValue: SourceObjectType[keyof SourceObjectType],
|
||||
source: SourceObjectType
|
||||
) => [MappedObjectKeyType, MappedObjectValueType];
|
||||
|
||||
interface Options {
|
||||
/**
|
||||
Recurse nested objects and objects in arrays.
|
||||
|
||||
@default false
|
||||
*/
|
||||
deep?: boolean;
|
||||
|
||||
/**
|
||||
Target object to map properties on to.
|
||||
|
||||
@default {}
|
||||
*/
|
||||
target?: {[key: string]: any};
|
||||
}
|
||||
|
||||
interface DeepOptions extends Options {
|
||||
deep: true;
|
||||
}
|
||||
|
||||
interface TargetOptions<TargetObjectType extends {[key: string]: any}> extends Options {
|
||||
target: TargetObjectType;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Map object keys and values into a new object.
|
||||
|
||||
@param source - Source object to copy properties from.
|
||||
@param mapper - Mapping function.
|
||||
|
||||
@example
|
||||
```
|
||||
import mapObject = require('map-obj');
|
||||
|
||||
const newObject = mapObject({foo: 'bar'}, (key, value) => [value, key]);
|
||||
//=> {bar: 'foo'}
|
||||
```
|
||||
*/
|
||||
declare function mapObject<
|
||||
SourceObjectType extends object,
|
||||
TargetObjectType extends {[key: string]: any},
|
||||
MappedObjectKeyType extends string,
|
||||
MappedObjectValueType
|
||||
>(
|
||||
source: SourceObjectType,
|
||||
mapper: mapObject.Mapper<
|
||||
SourceObjectType,
|
||||
MappedObjectKeyType,
|
||||
MappedObjectValueType
|
||||
>,
|
||||
options: mapObject.DeepOptions & mapObject.TargetOptions<TargetObjectType>
|
||||
): TargetObjectType & {[key: string]: unknown};
|
||||
declare function mapObject<
|
||||
SourceObjectType extends object,
|
||||
MappedObjectKeyType extends string,
|
||||
MappedObjectValueType
|
||||
>(
|
||||
source: SourceObjectType,
|
||||
mapper: mapObject.Mapper<
|
||||
SourceObjectType,
|
||||
MappedObjectKeyType,
|
||||
MappedObjectValueType
|
||||
>,
|
||||
options: mapObject.DeepOptions
|
||||
): {[key: string]: unknown};
|
||||
declare function mapObject<
|
||||
SourceObjectType extends {[key: string]: any},
|
||||
TargetObjectType extends {[key: string]: any},
|
||||
MappedObjectKeyType extends string,
|
||||
MappedObjectValueType
|
||||
>(
|
||||
source: SourceObjectType,
|
||||
mapper: mapObject.Mapper<
|
||||
SourceObjectType,
|
||||
MappedObjectKeyType,
|
||||
MappedObjectValueType
|
||||
>,
|
||||
options: mapObject.TargetOptions<TargetObjectType>
|
||||
): TargetObjectType & {[K in MappedObjectKeyType]: MappedObjectValueType};
|
||||
declare function mapObject<
|
||||
SourceObjectType extends {[key: string]: any},
|
||||
MappedObjectKeyType extends string,
|
||||
MappedObjectValueType
|
||||
>(
|
||||
source: SourceObjectType,
|
||||
mapper: mapObject.Mapper<
|
||||
SourceObjectType,
|
||||
MappedObjectKeyType,
|
||||
MappedObjectValueType
|
||||
>,
|
||||
options?: mapObject.Options
|
||||
): {[K in MappedObjectKeyType]: MappedObjectValueType};
|
||||
|
||||
export = mapObject;
|
54
node_modules/map-obj/index.js
generated
vendored
Normal file
54
node_modules/map-obj/index.js
generated
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
'use strict';
|
||||
|
||||
const isObject = value => typeof value === 'object' && value !== null;
|
||||
|
||||
// Customized for this use-case
|
||||
const isObjectCustom = value =>
|
||||
isObject(value) &&
|
||||
!(value instanceof RegExp) &&
|
||||
!(value instanceof Error) &&
|
||||
!(value instanceof Date);
|
||||
|
||||
const mapObject = (object, mapper, options, isSeen = new WeakMap()) => {
|
||||
options = {
|
||||
deep: false,
|
||||
target: {},
|
||||
...options
|
||||
};
|
||||
|
||||
if (isSeen.has(object)) {
|
||||
return isSeen.get(object);
|
||||
}
|
||||
|
||||
isSeen.set(object, options.target);
|
||||
|
||||
const {target} = options;
|
||||
delete options.target;
|
||||
|
||||
const mapArray = array => array.map(element => isObjectCustom(element) ? mapObject(element, mapper, options, isSeen) : element);
|
||||
if (Array.isArray(object)) {
|
||||
return mapArray(object);
|
||||
}
|
||||
|
||||
for (const [key, value] of Object.entries(object)) {
|
||||
let [newKey, newValue] = mapper(key, value, object);
|
||||
|
||||
if (options.deep && isObjectCustom(newValue)) {
|
||||
newValue = Array.isArray(newValue) ?
|
||||
mapArray(newValue) :
|
||||
mapObject(newValue, mapper, options, isSeen);
|
||||
}
|
||||
|
||||
target[newKey] = newValue;
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
module.exports = (object, mapper, options) => {
|
||||
if (!isObject(object)) {
|
||||
throw new TypeError(`Expected an object, got \`${object}\` (${typeof object})`);
|
||||
}
|
||||
|
||||
return mapObject(object, mapper, options);
|
||||
};
|
9
node_modules/map-obj/license
generated
vendored
Normal file
9
node_modules/map-obj/license
generated
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
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.
|
74
node_modules/map-obj/package.json
generated
vendored
Normal file
74
node_modules/map-obj/package.json
generated
vendored
Normal file
|
@ -0,0 +1,74 @@
|
|||
{
|
||||
"_from": "map-obj@^4.0.0",
|
||||
"_id": "map-obj@4.1.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-glc9y00wgtwcDmp7GaE/0b0OnxpNJsVf3ael/An6Fe2Q51LLwN1er6sdomLRzz5h0+yMpiYLhWYF5R7HeqVd4g==",
|
||||
"_location": "/map-obj",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "map-obj@^4.0.0",
|
||||
"name": "map-obj",
|
||||
"escapedName": "map-obj",
|
||||
"rawSpec": "^4.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^4.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/camelcase-keys"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/map-obj/-/map-obj-4.1.0.tgz",
|
||||
"_shasum": "b91221b542734b9f14256c0132c897c5d7256fd5",
|
||||
"_spec": "map-obj@^4.0.0",
|
||||
"_where": "/home/dawidd6/github/dawidd6/action-debian-package/node_modules/camelcase-keys",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/sindresorhus/map-obj/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "Map object keys and values into a new object",
|
||||
"devDependencies": {
|
||||
"ava": "^2.0.0",
|
||||
"tsd": "^0.7.3",
|
||||
"xo": "^0.24.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"homepage": "https://github.com/sindresorhus/map-obj#readme",
|
||||
"keywords": [
|
||||
"map",
|
||||
"object",
|
||||
"key",
|
||||
"keys",
|
||||
"value",
|
||||
"values",
|
||||
"iterate",
|
||||
"iterator",
|
||||
"rename",
|
||||
"modify",
|
||||
"deep",
|
||||
"recurse",
|
||||
"recursive"
|
||||
],
|
||||
"license": "MIT",
|
||||
"name": "map-obj",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/sindresorhus/map-obj.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"version": "4.1.0"
|
||||
}
|
76
node_modules/map-obj/readme.md
generated
vendored
Normal file
76
node_modules/map-obj/readme.md
generated
vendored
Normal file
|
@ -0,0 +1,76 @@
|
|||
# map-obj [](https://travis-ci.org/sindresorhus/map-obj)
|
||||
|
||||
> Map object keys and values into a new object
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install map-obj
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const mapObject = require('map-obj');
|
||||
|
||||
const newObject = mapObject({foo: 'bar'}, (key, value) => [value, key]);
|
||||
//=> {bar: 'foo'}
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### mapObject(source, mapper, options?)
|
||||
|
||||
#### source
|
||||
|
||||
Type: `object`
|
||||
|
||||
Source object to copy properties from.
|
||||
|
||||
#### mapper
|
||||
|
||||
Type: `Function`
|
||||
|
||||
Mapping function.
|
||||
|
||||
- It has signature `mapper(sourceKey, sourceValue, source)`.
|
||||
- It must return a two item array: `[targetKey, targetValue]`.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### deep
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
Recurse nested objects and objects in arrays.
|
||||
|
||||
##### target
|
||||
|
||||
Type: `object`<br>
|
||||
Default: `{}`
|
||||
|
||||
Target object to map properties on to.
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [filter-obj](https://github.com/sindresorhus/filter-obj) - Filter object keys and values into a new object
|
||||
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
<b>
|
||||
<a href="https://tidelift.com/subscription/pkg/npm-map-obj?utm_source=npm-map-obj&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
||||
</b>
|
||||
<br>
|
||||
<sub>
|
||||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
||||
</sub>
|
||||
</div>
|
Loading…
Add table
Add a link
Reference in a new issue