@aigne/afs-utils
v1.0.0
Published
Utility functions for AIGNE AFS modules
Readme
@aigne/afs-utils
Utility functions for AIGNE AFS modules.
Overview
This package provides shared utility functions used across AIGNE AFS modules, including:
- Type utilities: Type checking, validation, and manipulation helpers
- Schema utilities: Zod schema helpers for validation and transformation
- Camelize utilities: Object key transformation between camelCase and snake_case
Installation
npm install @aigne/afs-utilsFeatures
- Type checking and validation - Runtime type checking utilities
- Zod schema parsing - Parse and validate with human-readable error messages
- Synchronous and asynchronous validation support
- Optional error message prefix for better context
- Customizable error message formatting
- Object key transformation - Convert between camelCase and snake_case
- Shallow and deep conversion modes
- Zod schema preprocessing support
API
Type Utilities
isNil(value)- Check if value is null or undefinedisRecord(value)- Check if value is a plain objectisEmpty(obj)- Check if object/array/string is emptyisNonNullable(value)- Type guard for non-nullable valuesget(obj, path)- Safe nested property access
Schema Utilities
zodParse(schema, data, options?)- Parse and validate data with Zod schema and human-readable error messagesoptions.prefix- Optional prefix for error messagesoptions.prefixSeparator- Separator between prefix and error message (default:": ")options.async- Use async parsing withparseAsyncfor async refinements (default:false)
optionalize(schema)- Make Zod schema optionalcamelizeSchema(schema, options)- Transform object keys to camelCasepreprocessSchema(fn, schema)- Apply preprocessing to schema
Camelize Utilities
camelize(obj, shallow?)- Convert object keys to camelCasesnakelize(obj, shallow?)- Convert object keys to snake_case
License
Elastic-2.0
