5.0.2 • Published 2 years ago

map-obj v5.0.2

Weekly downloads
16,910,494
License
MIT
Repository
github
Last release
2 years ago

map-obj

Map object keys and values into a new object

Install

npm install map-obj

Usage

import mapObject, {mapObjectSkip} from '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] : mapObjectSkip);
//=> {one: 1}

API

mapObject(source, mapper, options?)

source

Type: object

The source object to copy properties from.

mapper

Type: (sourceKey, sourceValue, source) => [targetKey, targetValue, mapperOptions?] | mapObjectSkip

A 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: {}

The target object to map properties on to.

mapObjectSkip

Return this value from a mapper function to exclude the key from the new object.

import mapObject, {mapObjectSkip} from 'map-obj';

const object = {one: 1, two: 2}
const mapper = (key, value) => value === 1 ? [key, value] : mapObjectSkip
const result = mapObject(object, mapper);

console.log(result);
//=> {one: 1}

Related

  • filter-obj - Filter object keys and values into a new object

camelcase-keysdecamelize-keysarchetype-libraryeasy-select-rnchinjowwchinjowreact-native-bluetooth2killi8n-react-native-fast-image@arisageha/react-lazyloadairscanairscan-examplebb-chatreact-native-esc-pos-sahaab@borisovart/atol-kkt-module@frxf/frxfdeneme323112@ntt_app/react-native-custom-notificationreact-native-covid-sdk@jttechnic/interpreterttiocthpb-plugin-social@olivervorasai/slidermysql-formatpanqibaoreact-native-printer-brothersreact-native-shekhar-bridge-testcogoportutils@oiti/documentoscopy-react-native@mink-opn/build-tokensquoc-testunblock-block-save-variables@saaspe/componentsexpand-react-bridgeopea-bootstraapluminos-ui-core@everything-registry/sub-chunk-2128iqra-calculatorjawwy-sdkjawwy_gamification_releasereact-native-sphereuisphereuijawwy_libraryreact-native-credit-card-pkgreact-native-jawwy_samplelapture-ui-complaptureuigriffin-ui-library@segment/inspector-core@phong95/react-native-multiple-image-picker@thinxviewx/core-rn@thesunny/api2@tky-services/common@sweetsnodes/logger@taingo97/react-native-awesome-module@taingo97/react-native-bluetooth-xprinter@taingo97/react-native-expo-key-rsa-kt@taingo97/react-native-expo-rsa@taingo97/react-native-generate-key-rsa@taingo97/react-native-key-rsa@taingo97/react-native-print-xprinter@taingo97/react-native-rsa@taingo97/react-native-rsa-expo@taingo97/react-native-sunmi-printer@taingo97/react-native-telpo-printer@teambit/html@thedoctor0/vuex-shared-mutations@sidghimire/react-native-mapbox-navigation@silver0542/directus-extension-cma-components-editor@servisbot/sb-sdk@sephriot/react-native-persistable-uri@skeetboothppq/component-library@specomm/common@sergeysova/gatsby-source-simplecast@ssossou/styletool@status-im/react-native-transparent-video@tuannm301198/changeset-test@types/map-obj@tutanck/jsonfiles@tunnel/get-monorepo@tunnel/get-monorepo-root@tunnel/namespace@vitali_shcherbina/styled-lib@wholebuzz/search@wecraftapps/react-native-use-keyboard@zalastax/nolb-map-@yabe-siul/fluid-tailwind@yplabs-ltd/react-native-detectorappcharge-checkoutastra-ufo-sdk@zotasys/nativearchlibraryarifbudixzammar-testing1allauddin-clicalculatorappadonis-ally-figmaactionsflow-core@zohaibkhan/atmadyen-rnagent-get-agentawesome-module-kd
5.0.2

2 years ago

5.0.1

3 years ago

5.0.0

3 years ago

4.3.0

3 years ago

4.2.1

3 years ago

4.2.0

4 years ago

4.1.0

5 years ago

4.0.0

5 years ago

3.1.0

5 years ago

3.0.0

6 years ago

2.0.0

8 years ago

1.0.1

9 years ago

1.0.0

10 years ago