Socket
Socket
Sign inDemoInstall

markov-strings

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

markov-strings - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

17

index.js

@@ -15,3 +15,3 @@ 'use strict';

maxLength: 0,
minWords : 5,
minWords : 0,
maxWords : 0,

@@ -30,8 +30,3 @@ minScore : 0,

return new Promise((resolve, reject) => {
try {
resolve(this.buildCorpusSync());
}
catch (e) {
reject(e);
}
resolve(this.buildCorpusSync());
});

@@ -80,6 +75,6 @@ }

generateSentence(options, check) {
generateSentence(options) {
return new Promise((resolve, reject) => {
try {
resolve(this.generateSentenceSync(options, check))
resolve(this.generateSentenceSync(options))
}

@@ -92,3 +87,3 @@ catch (e) {

generateSentenceSync(options, check) {
generateSentenceSync(options) {
if (!this.corpus) {

@@ -138,2 +133,3 @@ throw new Error('Corpus is not built.')

!ended
|| typeof options.checker === 'function' && !options.checker(sentence)
|| options.minWords > 0 && sentence.split(' ').length < options.minWords

@@ -143,3 +139,2 @@ || options.maxWords > 0 && sentence.split(' ').length > options.maxWords

|| score < options.minScore
|| typeof check === 'function' && !check(sentence)
) {

@@ -146,0 +141,0 @@ continue;

{
"name": "markov-strings",
"version": "1.0.1",
"version": "1.1.0",
"description": "A Markov string generator",

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

@@ -21,2 +21,3 @@ [![Build Status](https://travis-ci.org/scambier/markov-strings.svg?branch=master)](https://travis-ci.org/scambier/markov-strings)

- [maxTries](#maxtries)
- [checker(sentence)](#checkersentence)
- [markov.buildCorpus()](#markovbuildcorpus)

@@ -56,2 +57,5 @@ - [markov.generateSentence([options])](#markovgeneratesentenceoptions)

minScore: 25,
checker: sentence => {
return sentence.endsWith('.'); // I want my tweets to end with a dot.
}
};

@@ -91,5 +95,4 @@

});
```
```
## API

@@ -155,2 +158,9 @@ ### new Markov(data, [options])

##### checker(sentence)
Type: `function`
In addition to all previous options, you can define your own checking function that will be called once the sentence is generated.
If this callback returns `false`, the sentence is rejected and a new one is generated.
#### markov.buildCorpus()

@@ -157,0 +167,0 @@ Return a Promise that will resolve to nothing.

@@ -70,2 +70,9 @@ 'use strict';

});
describe('Options', function() {
it('should take given options into account', function() {
const generator = new Generator([], {maxTries: 2});
expect(generator.options.maxTries).to.equal(2);
})
})
});

@@ -75,2 +82,9 @@

it('should throw an error if corpus is not built', function() {
const generator = new Generator(data);
expect(() => {
generator.generateSentenceSync()
}).to.throw(Error);
});
it('should output a sentence', function() {

@@ -119,3 +133,3 @@ generator.generateSentence({stateSize: 1})

it('should reject because maxLength is unattainable', function() {
generator.generateSentence({maxTries: 10, maxLength: 1, minWords: 0, maxWords: 0})
generator.generateSentence({maxTries: 100, maxLength: 1, minWords: 0, maxWords: 0})
.then(result => {

@@ -127,3 +141,3 @@ expect(result).to.throw(Error);

it('should reject because minWords is unattainable', function() {
generator.generateSentence({maxTries: 10, minWords: 100})
generator.generateSentence({maxTries: 100, minWords: 100})
.then(result => {

@@ -135,3 +149,3 @@ expect(result).to.throw(Error);

it('should reject because minScore is unattainable', function() {
generator.generateSentence({maxTries: 10, minScore: 20})
generator.generateSentence({maxTries: 100, minScore: 20})
.then(result => {

@@ -143,3 +157,3 @@ expect(result).to.throw(Error);

it('should reject because maxWords is unattainable', function() {
generator.generateSentence({maxTries: 10, maxWords: 1, minWords: 0})
generator.generateSentence({maxTries: 100, maxWords: 1, minWords: 0})
.then(result => {

@@ -150,2 +164,25 @@ expect(result).to.throw(Error);

it('should reject all sentences because of the callback', function() {
generator.generateSentence({
maxTries: 100,
callback: sentence => {
return false;
}
})
.then(result => {
expect(result).to.throw(Error);
});
});
it('should accept all sentences because of the callback', function() {
generator.generateSentence({
callback: sentence => {
return true;
}
})
.then(result => {
expect(result).to.exist;
});
});
});
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