Registry / testing / racoon-js

racoon-js

JSON →
library1.6.0jsnpmunverified

A data validation and formatting library for JavaScript that supports both browser and Node.js. Version 1.6.0 includes chainable schema definitions for strings, numbers, booleans, objects, and arrays with support for required fields, defaults, min/max, regex patterns, custom error messages, and value formatting. It offers a try-catch validate method and a silent validate mode that returns error and value. The library is lightweight (~21 kB, 4.6 kB gzipped) and supports IE 11 and modern browsers. Release cadence is low (last update September 2020). Differentiators include flexible nested schema definitions, chainable methods without order restrictions, and easy custom error messages.

npm install racoon-js
INSTALL
IMPORT
SIG · RACOON-JS
R
racoon-js
testingjavascriptv1.6.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

racoon
import racoon from 'racoon-js'
const racoon = require('racoon-js')
Default import is the only way to import. CommonJS require works but TypeScript may need esModuleInterop.
Schema
import racoon from 'racoon-js'; const schema = racoon.object({...})
import { Schema } from 'racoon-js'
No named export; use default import and call racoon.object() helper.
validate (method)
schema.validate(data)
schema.validate() without arguments
validate() expects one argument (data). Calling without arguments will throw.

Shows how to use validateSilent to avoid try-catch and get both error and cleaned value.

import racoon from 'racoon-js'; const schema = racoon.object({ name: racoon.string().min(3).max(30).required().error('Name must be 3-30 characters'), age: racoon.number().int().default(0), email: racoon.string().pattern(/^[^@\s]+@[^@\s]+$/).required() }); const result = schema.validateSilent({ name: 'John', age: 25, email: 'john@example.com' }); if (result.error) { console.error(result.error); } else { console.log(result.value); } // Output: { name: 'John', age: 25, email: 'john@example.com' }
Debug
Known issues
gotchavalidateSilent returns { error, value } but value may be undefined if validation fails (partial data not preserved).
fix
Always check error before using value. If you need partial data, consider wrapping validate in try-catch.
affects: >=1.0.0
gotchaUsing .error() after each chain method sets the error for the previous check, not the entire field.
fix
Chain .error() after each .min(), .max(), etc. to set specific messages per constraint.
affects: >=1.0.0
gotchaThe .default() method only applies when value is null or undefined, not for other falsy values like empty string or 0.
fix
Manually handle empty strings or zeros in your data before validation if you want defaults for those.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: racoon is not a function
Using require('racoon-js') in an ES module environment or missing default import in TypeScript without esModuleInterop.
fix
Use import racoon from 'racoon-js' or set esModuleInterop: true in tsconfig.json.
Error: "age": value should be a type of number
Passing a non-number type (e.g., string) to a number field without parsing.
fix
Ensure input age is a number (e.g., parseInt(age)) before validation.
TypeError: Cannot read properties of undefined (reading 'validate')
Calling schema.validate() before schema is fully defined (e.g., schema is undefined).
fix
Ensure the schema variable is assigned correctly by calling racoon.object({...}) first.
Upgrade
Version history
1.6.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Amazon
1
Resources
racoon-js — npm install racoon-js · libregistry