New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

genitive

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

genitive

A DSL for defining grammars for generating strings.

latest
Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Genitive

A DSL for defining grammars for generating strings.

npm install genitive

Call the default export with a grammar that defines productions as nonterminals mapped to an (array of) expansion.

const genitive = require('genitive')
const g = genitive({
  greeting: ['Hello, <who>!', 'Hi, <who>!'],
  who: 'World'
})
console.log([...g('<greeting>')])
// [ 'Hello, World!', 'Hi, World!' ]

The following examples are in YAML, and always the first production is evaluated.

You can build filters from variables, whose effect is only active within the block given to them - every assignment of a variable is undone at backtracking.

greeting:
  style=formal: Good morning <title>!
  style=informal:
    - Hi <title>!
    - Hey <title>!
title:
  style=formal: [Sir, Madam]
  style=informal: Dude
Good morning Sir!
Good morning Madam!
Hi Dude!
Hey Dude!

There are different kinds of filters:

  • var=value if unset, sets it. if set, succeeds if has the same value (using ==)
  • var:=value sets the value regardless of whether it is set, always succeeds
  • var?=value sets the value if unset, always succeeds
  • var!=value succeeds if unset or set to a different value
  • var<value
    var<=value
    var>value
    var>=value error if unset, succeeds if the mathematical relation holds

You can specify a disjunction of filters with |:

greeting:
  style=formal|style=informal: Hello, <title>!

You can also specify filters in the substitution placeholders:

greeting:
  - Good morning, <style=formal:title>!
  - Hi, <style=informal:title>!
  - Hey, <style=informal:title>!
title:
  style=formal: [Sir, Madam]
  style=informal: Dude

FAQs

Package last updated on 30 Jul 2020

Did you know?

Socket

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.

Install

Related posts