![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
assert-options
Advanced tools
The assert-options npm package is a utility for validating and asserting options in JavaScript objects. It helps ensure that the options passed to a function or module are valid and meet the expected criteria.
Basic Option Validation
This feature allows you to validate and merge user-provided options with default options. If the user does not provide an option, the default value is used.
const assertOptions = require('assert-options');
function myFunction(options) {
const defaultOptions = { a: 1, b: 2 };
options = assertOptions(options, defaultOptions);
console.log(options);
}
myFunction({ a: 10 }); // { a: 10, b: 2 }
myFunction(); // { a: 1, b: 2 }
Strict Option Validation
This feature enforces strict validation, ensuring that only the specified options are allowed. If an unknown option is provided, an error is thrown.
const assertOptions = require('assert-options');
function myFunction(options) {
const defaultOptions = { a: 1, b: 2 };
options = assertOptions(options, defaultOptions, { strict: true });
console.log(options);
}
myFunction({ a: 10, c: 3 }); // Throws an error because 'c' is not a valid option
Nested Option Validation
This feature supports validation of nested options, allowing you to merge and validate deeply nested objects.
const assertOptions = require('assert-options');
function myFunction(options) {
const defaultOptions = { a: 1, b: { c: 2, d: 3 } };
options = assertOptions(options, defaultOptions);
console.log(options);
}
myFunction({ b: { c: 10 } }); // { a: 1, b: { c: 10, d: 3 } }
myFunction(); // { a: 1, b: { c: 2, d: 3 } }
Joi is a powerful schema description language and data validator for JavaScript. It allows you to create blueprints or schemas for JavaScript objects to ensure validation. Compared to assert-options, Joi offers more advanced and flexible validation capabilities, including support for complex data types and custom validation rules.
Yup is a JavaScript schema builder for value parsing and validation. It is similar to Joi but is often preferred for its simplicity and ease of use. Like assert-options, Yup can validate and transform objects, but it provides more comprehensive validation features and better integration with form libraries.
Prop-types is a runtime type checking library for React props. While it is primarily used for validating React component props, it can also be used for general object validation. Compared to assert-options, prop-types is more focused on type checking rather than option validation and merging.
Smart options
handling, with one line of code:
Strongly-typed, built for TypeScript 3.x strict
mode.
This module automates proper options parsing and setting defaults where needed.
$ npm install assert-options
import {assertOptions} from 'assert-options';
function functionWithOptions(options) {
options = assertOptions(options, {first: 123, second: null});
// options is a safe object here, with all missing defaults set.
}
And when default values are not needed, you can use an array of strings:
function functionWithOptions(options) {
options = assertOptions(options, ['first', 'second']);
// the result is exactly the same as using the following:
// options = assertOptions(options, {first: undefined, second: undefined});
// options is a safe object here, without defaults.
}
assertOptions(options, defaults) => {}
When options
is null
/undefined
, new {}
is returned, applying defaults
as specified.
When options
contains an unknown property, Error Option "name" is not recognized.
is thrown.
When a property in options
is missing or undefined
, its value is set from the defaults
,
provided it is available and not undefined
.
When options
is not null
/undefined
, it must be of type object
, or else TypeError is thrown:
Invalid "options" parameter: value
.
Parameter defaults
is required, as a non-null
object or an array of strings, or else TypeError
is thrown: Invalid "defaults" parameter: value
.
FAQs
Generic options parameter handling.
We found that assert-options demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.