Registry / serialization / base-cli-schema

base-cli-schema

JSON →
library0.1.19jsnpmunverified

This package provides a schema definition and normalization utility specifically designed for the `base-cli` plugin. Its primary function is to process and normalize command-line argument values (`argv`) before they are consumed by `cli.process()` within a `base` application. It allows for defining custom fields with specified types (e.g., 'string') and provides a `normalize` function that applies these definitions, including custom normalizer functions, to an `argv` object. The package is currently at version 0.1.19 and was last published in May 2016. Given its age and low version number, the release cadence is effectively inactive, indicating it is no longer actively maintained. Key differentiators include its tight integration with the `base` framework and its focused purpose of defining and applying schemas for CLI arguments, offering a structured approach to argument normalization within the `base` ecosystem, unlike more general-purpose validation libraries.

npm install base-cli-schema
INSTALL
IMPORT
SIG · BASE-CLI-SCHEMA
B
base-cli-schema
serializationjavascriptv0.1.19
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

cliSchema
const cliSchema = require('base-cli-schema');
import cliSchema from 'base-cli-schema';
This package is CommonJS-only and does not support ES Modules. Attempting to import using `import` syntax will result in an error in ES Module environments.
Base
const Base = require('base');
import Base from 'base';
The `base` framework, a key dependency, is also CommonJS-only.
minimist
const minimist = require('minimist');
import minimist from 'minimist';
The `minimist` package, used for argv parsing, is typically consumed via CommonJS `require` in contexts where `base-cli-schema` is used.

Demonstrates initializing a `base` application, attaching `base-cli`, creating a `cliSchema` instance, defining a custom field with a normalizer, and using it to process a mock argv object.

const argv = require('minimist')(process.argv.slice(2)); const Base = require('base'); const cliSchema = require('base-cli-schema'); const cli = require('base-cli'); // Assuming base-cli is also required for app.use(cli()) const app = new Base(); app.use(cli()); // Attach the cli plugin to the base application const schema = cliSchema(app); // Define a custom field for demonstration schema.field('foo', 'string', { normalize: function(val, key, config, schema) { // Example normalization: always return 'bar' for 'foo' return val ? val.toUpperCase() : 'bar'; } }); // Simulate argv input, e.g., 'node your-script.js --foo=test --other=value' const mockArgv = { foo: 'hello', other: 'world' }; const obj = schema.normalize(mockArgv); console.log(obj); // Expected output: { foo: 'HELLO', other: 'world' } (if --foo=hello was passed) // or { foo: 'BAR' } if --foo was not passed and 'bar' is default/fallback
Debug
Known issues
breakingThis package, including its core dependency `base`, is CommonJS-only. It does not support ES Modules (ESM) and will cause runtime errors if directly imported or `require`d within an ESM context without specific transpilation or loader configurations.
fix
Use a CommonJS environment or project. For ESM projects, consider alternative, more modern CLI argument parsing and schema validation libraries. If absolutely necessary, configure a CommonJS-to-ESM wrapper or bundler like Webpack/Rollup with appropriate plugins (e.g., `@rollup/plugin-commonjs`).
affects: All versions
gotchaThe package is effectively abandoned, with its last publish in 2016. This means there will be no new features, bug fixes, or security updates. It may not be compatible with newer Node.js versions or ecosystem changes.
fix
Evaluate if the functionality can be replaced by a more actively maintained library or custom code. If continued use is critical, ensure thorough testing against your specific Node.js version and dependencies. Be aware of potential unpatched vulnerabilities.
affects: All versions
gotchaHeavy reliance on the `base` framework, which itself is an older, less commonly used architecture in modern Node.js development. Understanding `base`'s plugin system is crucial for effective use of `base-cli-schema`.
fix
Familiarize yourself with the `base` framework's documentation. Ensure all necessary `base` plugins (like `base-cli`) are correctly installed and used with `app.use()`.
affects: All versions
Errors
Common errors & fixes
ReferenceError: require is not defined in ES module scope
Attempting to use `require('base-cli-schema')` (a CommonJS module) within an ES Module file (`.mjs` or `type: "module"` in `package.json`).
fix
Change your file to a CommonJS module (`.js` without `type: "module"`) or use a tool like `createRequire` from the `module` module if you must mix ESM and CJS (e.g., `import { createRequire } from 'module'; const require = createRequire(import.meta.url); const cliSchema = require('base-cli-schema');`). Ideally, migrate to an ESM-compatible alternative.
TypeError: app.use is not a function
The `base` instance (`app`) was not correctly initialized or the `base-cli` plugin was not properly `require`d and passed to `app.use()`.
fix
Ensure `const Base = require('base');` and `const cli = require('base-cli');` are present, and that `app.use(cli());` is called on your `new Base()` instance before using `cliSchema`.
Upgrade
Version history
0.1.19latest on npm
Audit
Dependencies
baserequiredCore framework this schema plugin integrates with, required for initialization.
minimistrequiredUsed for parsing raw command-line arguments (process.argv) into an object before schema normalization.
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
base-cli-schema — npm install base-cli-schema · libregistry