feat: adding linter for commits
This commit is contained in:
151
node_modules/map-obj/index.d.ts
generated
vendored
Normal file
151
node_modules/map-obj/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,151 @@
|
||||
// Unique symbol cannot be declared in a namespace directly, so we declare it top-level
|
||||
// See: https://github.com/sindresorhus/map-obj/pull/38#discussion_r702396878
|
||||
declare const skipSymbol: unique symbol;
|
||||
|
||||
declare namespace mapObject {
|
||||
type Mapper<
|
||||
SourceObjectType extends {[key: string]: any},
|
||||
MappedObjectKeyType extends string,
|
||||
MappedObjectValueType
|
||||
> = (
|
||||
sourceKey: keyof SourceObjectType,
|
||||
sourceValue: SourceObjectType[keyof SourceObjectType],
|
||||
source: SourceObjectType
|
||||
) => [
|
||||
targetKey: MappedObjectKeyType,
|
||||
targetValue: MappedObjectValueType,
|
||||
mapperOptions?: mapObject.MapperOptions
|
||||
] | typeof mapObject.mapObjectSkip;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
interface MapperOptions {
|
||||
/**
|
||||
Whether `targetValue` should be recursed.
|
||||
|
||||
Requires `deep: true`.
|
||||
|
||||
@default true
|
||||
*/
|
||||
readonly shouldRecurse?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
Return this value from a `mapper` function to remove a key from an object.
|
||||
|
||||
@example
|
||||
```
|
||||
const mapObject = require('map-obj');
|
||||
|
||||
const object = {one: 1, two: 2}
|
||||
const mapper = (key, value) => value === 1 ? [key, value] : mapObject.mapObjectSkip
|
||||
const result = mapObject(object, mapper);
|
||||
|
||||
console.log(result);
|
||||
//=> {one: 1}
|
||||
```
|
||||
*/
|
||||
const mapObjectSkip: typeof skipSymbol
|
||||
}
|
||||
|
||||
/**
|
||||
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'}
|
||||
|
||||
const newObject = mapObject({FOO: true, bAr: {bAz: true}}, (key, value) => [key.toLowerCase(), value]);
|
||||
//=> {foo: true, bar: {bAz: true}}
|
||||
|
||||
const newObject = mapObject({FOO: true, bAr: {bAz: true}}, (key, value) => [key.toLowerCase(), value], {deep: true});
|
||||
//=> {foo: true, bar: {baz: true}}
|
||||
|
||||
const newObject = mapObject({one: 1, two: 2}, (key, value) => value === 1 ? [key, value] : mapObject.mapObjectSkip);
|
||||
//=> {one: 1}
|
||||
```
|
||||
*/
|
||||
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;
|
68
node_modules/map-obj/index.js
generated
vendored
Normal file
68
node_modules/map-obj/index.js
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
'use strict';
|
||||
|
||||
const isObject = value => typeof value === 'object' && value !== null;
|
||||
const mapObjectSkip = Symbol('skip');
|
||||
|
||||
// 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)) {
|
||||
const mapResult = mapper(key, value, object);
|
||||
|
||||
if (mapResult === mapObjectSkip) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let [newKey, newValue, {shouldRecurse = true} = {}] = mapResult;
|
||||
|
||||
// Drop `__proto__` keys.
|
||||
if (newKey === '__proto__') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (options.deep && shouldRecurse && 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);
|
||||
};
|
||||
|
||||
module.exports.mapObjectSkip = mapObjectSkip;
|
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> (https://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.
|
43
node_modules/map-obj/package.json
generated
vendored
Normal file
43
node_modules/map-obj/package.json
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "map-obj",
|
||||
"version": "4.3.0",
|
||||
"description": "Map object keys and values into a new object",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/map-obj",
|
||||
"funding": "https://github.com/sponsors/sindresorhus",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"map",
|
||||
"object",
|
||||
"key",
|
||||
"keys",
|
||||
"value",
|
||||
"values",
|
||||
"iterate",
|
||||
"iterator",
|
||||
"rename",
|
||||
"modify",
|
||||
"deep",
|
||||
"recurse",
|
||||
"recursive"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "^2.0.0",
|
||||
"tsd": "^0.14.0",
|
||||
"xo": "^0.24.0"
|
||||
}
|
||||
}
|
105
node_modules/map-obj/readme.md
generated
vendored
Normal file
105
node_modules/map-obj/readme.md
generated
vendored
Normal file
@ -0,0 +1,105 @@
|
||||
# map-obj
|
||||
|
||||
> Map object keys and values into a new object
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install map-obj
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const mapObject = require('map-obj');
|
||||
|
||||
const newObject = mapObject({foo: 'bar'}, (key, value) => [value, key]);
|
||||
//=> {bar: 'foo'}
|
||||
|
||||
const newObject = mapObject({FOO: true, bAr: {bAz: true}}, (key, value) => [key.toLowerCase(), value]);
|
||||
//=> {foo: true, bar: {bAz: true}}
|
||||
|
||||
const newObject = mapObject({FOO: true, bAr: {bAz: true}}, (key, value) => [key.toLowerCase(), value], {deep: true});
|
||||
//=> {foo: true, bar: {baz: true}}
|
||||
|
||||
const newObject = mapObject({one: 1, two: 2}, (key, value) => value === 1 ? [key, value] : mapObject.mapObjectSkip);
|
||||
//=> {one: 1}
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### mapObject(source, mapper, options?)
|
||||
|
||||
#### source
|
||||
|
||||
Type: `object`
|
||||
|
||||
Source object to copy properties from.
|
||||
|
||||
#### mapper
|
||||
|
||||
Type: `(sourceKey, sourceValue, source) => [targetKey, targetValue, mapperOptions?] | mapObject.mapObjectSkip`
|
||||
|
||||
Mapping function.
|
||||
|
||||
##### mapperOptions
|
||||
|
||||
Type: `object`
|
||||
|
||||
###### shouldRecurse
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
Whether `targetValue` should be recursed.
|
||||
|
||||
Requires `deep: true`.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### deep
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Recurse nested objects and objects in arrays.
|
||||
|
||||
##### target
|
||||
|
||||
Type: `object`\
|
||||
Default: `{}`
|
||||
|
||||
Target object to map properties on to.
|
||||
|
||||
### mapObject.mapObjectSkip
|
||||
|
||||
Return this value from a `mapper` function to exclude the key from the new object.
|
||||
|
||||
```js
|
||||
const mapObject = require('map-obj');
|
||||
|
||||
const object = {one: 1, two: 2}
|
||||
const mapper = (key, value) => value === 1 ? [key, value] : mapObject.mapObjectSkip
|
||||
const result = mapObject(object, mapper);
|
||||
|
||||
console.log(result);
|
||||
//=> {one: 1}
|
||||
```
|
||||
|
||||
## 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>
|
Reference in New Issue
Block a user