1.1.1 • Published 10 months ago

key-transformer v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Key Transformer

key-transformer is a utility for transforming object keys and values in JavaScript and TypeScript. It allows you to omit specific keys, apply custom transformations to values, remove empty entries, and handle nested objects with ease.

Installation

npm install key-transformer

Usage

import transformKeys from 'key-transformer';

const obj = {
    name: "Alice",
    age: 25,
    city: "Wonderland",
    hobby: null,
    status: "active",
};
const result = transformKeys(obj, {
    omit: ["age"],
    omitEmpty: true,
    omitByValues: ["active"],
    valueTransformer: (value) =>
        typeof value === "string" ? value.toUpperCase() : value,
});

console.log(result);
// output: { name: 'ALICE', city: 'WONDERLAND' }

API

transformKeys(obj, options?)
optionsDescriptiontypeDefault
omitArray of keys to omit from the objectstring[][]
omitEmptyIf true, removes keys with null, undefined, or empty stringsbooleanfalse
omitByValuesArray of values; Keys with matching values will be omittedstring[][]
valueTransformerFunction to transform each value in the object(value: any) => anyno-op
deepIf true, recursively applies transformations to nested objectsbooleanfalse
1.1.1

10 months ago

1.1.0

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago