@tpmjs/tools-config-normalize
Normalize configuration objects by sorting keys alphabetically, removing null/undefined values, and removing empty objects/arrays. Returns the normalized config along with a list of changes made and key counts.
Test @tpmjs/tools-config-normalize (configNormalize) with AI-powered execution
0/2000 characters
Install this tool and use it with the AI SDK
npm install @tpmjs/tools-config-normalizepnpm add @tpmjs/tools-config-normalizeyarn add @tpmjs/tools-config-normalizebun add @tpmjs/tools-config-normalizedeno add npm:@tpmjs/tools-config-normalizeimport { configNormalize } from '@tpmjs/tools-config-normalize';import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { configNormalize } from '@tpmjs/tools-config-normalize';
const result = await generateText({
model: openai('gpt-4o'),
tools: { configNormalize },
prompt: 'Your prompt here...',
});
console.log(result.text);Available configuration options
configobjectThe configuration object to normalize
optionsobjectNormalization options
Schema extracted: 1/1/2026, 8:17:37 AM
Normalizes configuration objects by sorting keys, removing nulls, and cleaning empty values.
npm install @tpmjs/tools-config-normalize
import { configNormalize } from '@tpmjs/tools-config-normalize'; import { generateText } from 'ai'; const result = await generateText({ model: yourModel, tools: { configNormalize }, prompt: 'Normalize this config object: ...', });
config (object): The configuration object to normalizeoptions (object, optional): Normalization options
sortKeys (boolean, default: true): Sort object keys alphabeticallyremoveNulls (boolean, default: true): Remove null and undefined valuesremoveEmpty (boolean, default: true): Remove empty objects and arraysReturns an object with:
normalized (object): The normalized configuration objectchanges (array): List of changes made during normalization
type: 'removed' | 'sorted' | 'cleaned'path: Path to the changed property (e.g., "database.options")reason: Human-readable explanationoldValue: The original value (for removals)keyCount (number): Total keys in normalized configoriginalKeyCount (number): Total keys in original configconst config = { name: "my-app", version: null, database: { port: 5432, host: "localhost", options: {} }, cache: { enabled: true, ttl: undefined }, features: [] }; const result = await configNormalize.execute({ config }); console.log(result.normalized); // { // cache: { // enabled: true // }, // database: { // host: "localhost", // port: 5432 // }, // name: "my-app" // } console.log(result.changes); // [ // { // type: 'removed', // path: 'version', // reason: 'null value', // oldValue: null // }, // { // type: 'removed', // path: 'database.options', // reason: 'empty object', // oldValue: {} // }, // { // type: 'removed', // path: 'cache.ttl', // reason: 'undefined value', // oldValue: undefined // }, // { // type: 'removed', // path: 'features', // reason: 'empty array', // oldValue: [] // }, // { // type: 'sorted', // path: 'root', // reason: 'keys sorted alphabetically' // } // ] console.log(result.keyCount); // 4 console.log(result.originalKeyCount); // 9
// Only sort keys, don't remove anything const result = await configNormalize.execute({ config, options: { sortKeys: true, removeNulls: false, removeEmpty: false } }); // Remove nulls but keep empty objects/arrays const result = await configNormalize.execute({ config, options: { sortKeys: true, removeNulls: true, removeEmpty: false } }); // Don't sort, just clean const result = await configNormalize.execute({ config, options: { sortKeys: false, removeNulls: true, removeEmpty: true } });
MIT
Downloads/month
39
Quality Score