Implements a comprehensive suite of AI SDK v6 tools across multiple categories: - Research (5): page-brief, compare-pages, source-credibility, claim-checklist, timeline-from-text - Web (10): fetch-text, links-catalog, extract-meta, extract-json-ld, redirect-trace, sitemap-read, rss-read, table-extract, robots-policy, url-normalize - Data (15): csv-parse, csv-stringify, json-repair, json-schema-validate, yaml-parse, yaml-stringify, text-chunk, normalize-whitespace, dedupe-by-key, pivot, rows-filter, rows-sort, rows-group-aggregate, rows-join, schema-infer - Doc (12): toc-generate, glossary-build, faq-from-text, executive-brief, decision-record-adr, prd-outline, acceptance-criteria, style-rewrite - Eng (12): diff-text-unified, env-var-docs-generate, dependency-audit-lite, conventional-commit-suggest, markdown-lint-basic, test-case-generate, stacktrace-parse, release-notes, changelog-entry, release-checklist - Security (7): redact-secrets, secret-scan-text, url-risk-heuristic, csp-compose, hardening-checklist-web, access-control-matrix, data-classification-heuristic - Stats (9): effect-size-suite, bootstrap-ci, permutation-test, multiple-testing-adjust, linear-regression-ols, logistic-regression, time-series-decompose-lite, anomaly-detect-mad - Ops (7): slo-draft, runbook-draft, postmortem-draft, postmortem-action-extractor, error-log-triage, coverage-tracker, monitoring-gap-analysis - Agent (15): prompt-to-workflow-skeleton, workflow-validate-io, workflow-explain, workflow-cost-estimate, tool-call-accuracy-score, eval-fixture-build, guardrail-policy-draft, workflow-auto-repair, tool-selection-plan, novelty-score-workflow, workflow-variant-generate, config-normalize, recipe-* - Utility (8): base64-encode, base64-decode, hash-text, regex-extract, template-render, date-parse, json-path-query, url-parse - HTML (3): html-sanitize, html-to-markdown, markdown-to-html All tools follow AI SDK v6 pattern with tool() and jsonSchema<T>(). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
3.7 KiB
3.7 KiB
@tpmjs/tools-config-normalize
Normalizes configuration objects by sorting keys, removing nulls, and cleaning empty values.
Installation
npm install @tpmjs/tools-config-normalize
Usage
import { configNormalize } from '@tpmjs/tools-config-normalize';
import { generateText } from 'ai';
const result = await generateText({
model: yourModel,
tools: { configNormalize },
prompt: 'Normalize this config object: ...',
});
Features
- Sorts object keys alphabetically for consistent ordering
- Removes null and undefined values
- Removes empty objects and empty arrays
- Recursively processes nested structures
- Tracks all changes made during normalization
- Provides before/after key counts
Input
config(object): The configuration object to normalizeoptions(object, optional): Normalization optionssortKeys(boolean, default: true): Sort object keys alphabeticallyremoveNulls(boolean, default: true): Remove null and undefined valuesremoveEmpty(boolean, default: true): Remove empty objects and arrays
Output
Returns an object with:
normalized(object): The normalized configuration objectchanges(array): List of changes made during normalizationtype: '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 config
Example
const 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
Custom Options
// 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
}
});
Use Cases
- Cleaning up generated configuration files
- Normalizing user-provided config for comparison
- Preparing config for version control (consistent key ordering)
- Removing test/debug values before deployment
- Standardizing API responses
Change Types
- removed: A key was removed due to null/undefined/empty value
- sorted: Keys in an object were reordered alphabetically
- cleaned: A nested structure became empty after normalization and was removed
License
MIT