Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

articulate-nlg

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

articulate-nlg - npm Package Compare versions

Comparing version 1.0.13 to 1.0.14

2

package.json
{
"name": "articulate-nlg",
"version": "1.0.13",
"version": "1.0.14",
"description": "A natural language generator (NLG) that articulates concepts as words, phrases, and sentences.",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

@@ -106,4 +106,6 @@ [![Build Status](https://travis-ci.org/justinmahar/articulate-nlg.svg?branch=master)](https://travis-ci.org/justinmahar/articulate-nlg) [![codecov](https://codecov.io/gh/justinmahar/articulate-nlg/branch/master/graph/badge.svg)](https://codecov.io/gh/justinmahar/articulate-nlg)

See the [mustache.js](https://github.com/janl/mustache.js/) documentation for reference on the syntax.
There are [Vocab Helper Functions](#vocab-helper-functions) which abstract away the mustache.js syntax shown above. These can (and should!) be used instead of mustache.js syntax whenever possible.
If you must, see the [mustache.js](https://github.com/janl/mustache.js/) documentation for reference on the syntax.
## Function Wrappers

@@ -125,9 +127,20 @@

### Vocab Helpers
## Vocab Helper Functions
The class `VocabHelpers` contains helper functions that create the function wrapper templates shown above. You can use these to make vocabs easier to define.
The class `VocabHelpers` contains static helper functions that create the function wrapper templates shown above and create common templates using mustache.js syntax.
- `capitalize(text:string)` - Creates a template for capitalization.
- `choose(texts:(string|{v:value,w:weight})[])` - Creates a template for random choice. Takes an array of strings or weighted objects in the format `{v: value, w: weight}`.
You can use these to make vocabs easier to define, and can abstract away most, if not all, mustache.js templating syntax from a persona definition. This results in clean and easy to read persona vocabs. **Where possible, it is recommended that you use helper functions over mustache.js syntax to define your persona.**
The following functions are available in `VocabHelpers`:
- `capitalize(text: string)` - Creates a template for capitalization. See the function wrappers section above for details.
- `choose(texts: (string|{v:value,w:weight})[])` - Creates a template for random choice. See the function wrappers section above for details. Takes a mixed array of strings or weighted objects in the format `{v: value, w: weight}`. You cannot use a `|` character in any of the texts. If you need this character, use `say("pipe")` and have the `"pipe"` key map to `"|"`.
- `maybe(text: string)` - Creates a template that results in a 50/50 choice between an empty string or the provided text. You cannot use a `|` character in the text.
- `say(vocabKey: string)` - Creates a template that references another vocab key (as a mustache.js partial).
- `param(paramKey: string)` - Creates a template that references the value of a parameter.
- `ifThen(paramKey: string, thenText: string)` - Creates a template that uses the provided `thenText` if the param key exists and is not falsy.
- `ifNot(paramKey: string, thenText: string)` - Creates a template that uses the provided `thenText` if the param key doesn't exist or is falsy.
- `ifElse(paramKey: string, thenText: string, elseText: string)` - Creates a template with both `ifThen()` and `ifNot()` templates for the given param key.
- `doFirst(paramTextPairs: {p: paramKey, t: text}[], defaultText: string = "")` - Creates a template that uses `ifElse()` templates for each pair provided until true. If no param keys are truthy, the `defaultText` is used (defaults to empty string).
Example:

@@ -139,2 +152,9 @@

const capitalize = VocabHelpers.capitalize;
// const maybe = VocabHelpers.maybe;
// const say = VocabHelpers.say;
// const param = VocabHelpers.param;
// const ifThen = VocabHelpers.ifThen;
// const ifNot = VocabHelpers.ifNot;
// const ifElse = VocabHelpers.ifElse;
// const doFirst = VocabHelpers.doFirst;

@@ -151,3 +171,3 @@ let greeterVocab = {

Again, you cannot nest the same function wrapper in itself. If, say, you need to nest `choose()` within `choose()`, you should create a separate vocab key with the function and reference it in the original one like so: `{{>nameOfVocabKey}}`.
Again, you cannot nest the same function wrapper in itself. If, say, you need to nest `choose()` within `choose()`, you should create a separate vocab key with the function and reference it in the original one like so: `say("nameOfVocabKey")`. A safety check is built into these functions to prevent nesting and a warning will be printed to the console if you do nest them.

@@ -154,0 +174,0 @@ ## TypeScript Support

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc