map-anything
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "map-anything", | ||
"sideEffects": false, | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Array.map but for objects. A small and simple integration.", | ||
"main": "dist/index.cjs.js", | ||
"module": "dist/index.esm.js", | ||
"typings": "types/index.d.ts", | ||
"types": "types/index.d.ts", | ||
"scripts": { | ||
@@ -13,17 +13,19 @@ "test": "ava", | ||
"rollup": "rollup -c build/rollup.js", | ||
"build": "npm run lint && npm run test && npm run rollup" | ||
"build": "npm run lint && npm run test && npm run rollup", | ||
"release": "npm run build && np" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@typescript-eslint/eslint-plugin": "^4.6.1", | ||
"@typescript-eslint/parser": "^4.6.1", | ||
"ava": "^3.13.0", | ||
"eslint": "^7.12.1", | ||
"eslint-config-prettier": "^6.15.0", | ||
"@typescript-eslint/eslint-plugin": "^4.17.0", | ||
"@typescript-eslint/parser": "^4.17.0", | ||
"ava": "^3.15.0", | ||
"eslint": "^7.21.0", | ||
"eslint-config-prettier": "^8.1.0", | ||
"eslint-plugin-tree-shaking": "^1.8.0", | ||
"rollup": "^2.33.1", | ||
"rollup-plugin-typescript2": "^0.29.0", | ||
"ts-node": "^9.0.0", | ||
"np": "^7.4.0", | ||
"prettier": "^2.2.1", | ||
"rollup": "^2.41.2", | ||
"rollup-plugin-typescript2": "^0.30.0", | ||
"ts-node": "^9.1.1", | ||
"tsconfig-paths": "^3.9.0", | ||
"typescript": "^4.0.5" | ||
"typescript": "^4.2.3" | ||
}, | ||
@@ -51,3 +53,27 @@ "keywords": [ | ||
] | ||
}, | ||
"np": { | ||
"yarn": false, | ||
"branch": "production" | ||
}, | ||
"eslintConfig": { | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": [ | ||
"@typescript-eslint", | ||
"tree-shaking" | ||
], | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"prettier" | ||
], | ||
"rules": { | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/ban-ts-ignore": "off", | ||
"tree-shaking/no-side-effects-in-initialization": "error", | ||
"@typescript-eslint/ban-ts-comment": "off" | ||
} | ||
} | ||
} |
@@ -17,3 +17,3 @@ # Map anything 🗺 | ||
But this doesn't exist for objects, so you need to do this instead: | ||
But this doesn't exist for objects, you need to do this instead: | ||
@@ -29,2 +29,4 @@ ```js | ||
`map-anything` has very good #[TypeScript](#typescript) support as well. | ||
## Meet the family | ||
@@ -83,2 +85,8 @@ | ||
## TypeScript | ||
Without having to specify the return type in the reducer, I've set `map-anything` up so it automatically detects that type for you! | ||
![typescript support](https://raw.githubusercontent.com/mesqueeb/merge-anything/master/.github/typescript-support.png) | ||
## Source code | ||
@@ -85,0 +93,0 @@ |
@@ -5,3 +5,5 @@ import test from 'ava' | ||
test('mapObjectWithObjects', (t) => { | ||
const target = { | ||
type Pokemon = { name: string; level: number } | ||
const target: { [id in string]: Pokemon } = { | ||
'001': { name: 'Bulbasaur', level: 10 }, | ||
@@ -23,3 +25,4 @@ '004': { name: 'Charmander', level: 8 }, | ||
test('with types', (t) => { | ||
type Pokemon = { name: string, level: number } | ||
type Pokemon = { name: string; level: number } | ||
const target: { [id in string]: Pokemon } = { | ||
@@ -57,3 +60,4 @@ '001': { name: 'Bulbasaur', level: 10 }, | ||
test('set to propname + test type inside of second arg', (t) => { | ||
type Pokemon = { name: string, level: number } | ||
type Pokemon = { name: string; level: number } | ||
const target: { [id in string]: Pokemon } = { | ||
@@ -73,3 +77,4 @@ '001': { name: 'Bulbasaur', level: 10 }, | ||
test('replace objects with numbers', (t) => { | ||
type Pokemon = { name: string, level: number } | ||
type Pokemon = { name: string; level: number } | ||
const target: { [id in string]: Pokemon } = { | ||
@@ -80,6 +85,6 @@ '001': { name: 'Bulbasaur', level: 10 }, | ||
} | ||
const mapFn = (pkmn: Pokemon) => pkmn.name | ||
const res = mapObject(target, mapFn) | ||
t.deepEqual(res, { | ||
const mappedNames = mapObject(target, (pkmn: Pokemon) => pkmn.name) | ||
t.deepEqual(mappedNames, { | ||
'001': 'Bulbasaur', | ||
@@ -86,0 +91,0 @@ '004': 'Charmander', |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
133215
14
103
13
203