![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
indicative-parser
Advanced tools
Usage • Why? • Features • Examples • Documentation
Indicative parser parses the user defined schema object to a tree of nodes. Using this, the end user can always define their rules as a flat object and it's the job of the parser to expand it to a nested object.
Install the package from npm
npm i indicative-parser
# yarn user
yarn add indicative-parser
and then usage it as follows
const { rulesParser, messagesParser } = require('indicative-parser')
console.log(rulesParser({
'client_id': 'required',
'settings.key': 'required',
'users.*.email': 'required|email'
}))
// messages parser
console.log(messagesParser({
'users.*.email.required': 'Email is required',
'users.*.email.email': 'Invalid email address'
}))
The parser tree emits three types of nodes, which are explained below:
The literal
type is the reference to the final property or leaf in the tree. A literal node doesn't have any children.
{
username: 'required'
}
Output
{
username: {
type: 'literal',
rules: [{
name: 'required',
args: [],
}],
},
}
Property | Description |
---|---|
type | The type of the node |
rules | An array of parsed rules |
The object
type defines an object, which will always have one or more children.
Following is an example of object
node.
{
'user.profile': 'required'
}
Output
{
user: {
type: 'object',
rules: [],
children: {
profile: {
rules: [
{
name: 'required',
args: [],
},
],
type: 'literal',
},
},
},
}
In the above code example, you can see that the properties before the dot .
notation is marked as type = object
and last property username
is considered a literal. There is no limit to the depth of the object.
Property | Description |
---|---|
type | The type of the node |
rules | An array of parsed rules on the object node itself |
children | An object of nested named children |
The array
type detects the array expressions as shown below.
{
'users.*.username': 'required'
}
Output
{
users: {
type: 'array',
rules: [],
each: {
'*': {
rules: [],
children: {
username: {
type: 'literal',
rules: [
{
name: 'required',
args: [],
},
],
},
},
},
},
},
}
A node is considered as an array when it has *
or numeric
expressions. The each
property contains a sub object for each defined index
with nested children.
Property | Description |
---|---|
type | The type of the node |
rules | An array of parsed rules on the object node itself |
each | Set of children for each defined index. |
The output of parser
is used by compiler to create a top level function, which executes the validations on runtime data object.
FAQs
Schema parser for Indicative
The npm package indicative-parser receives a total of 5,374 weekly downloads. As such, indicative-parser popularity was classified as popular.
We found that indicative-parser demonstrated a not healthy version release cadence and project activity because the last version was released 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
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.