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

chance-generators

Package Overview
Dependencies
Maintainers
2
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chance-generators - npm Package Compare versions

Comparing version 3.4.0 to 3.5.0

5

CHANGELOG.md

@@ -0,1 +1,6 @@

### v3.5.0 (2018-11-27)
- [#29](https://github.com/sunesimonsen/chance-generators/pull/29) Added a first method to the generators ([Sune Simonsen](mailto:sune@we-knowhow.dk))
- [#28](https://github.com/sunesimonsen/chance-generators/pull/28) Fail the take method if the user forgets to provide a count ([Sune Simonsen](mailto:sune@we-knowhow.dk))
### v3.4.0 (2018-11-26)

@@ -2,0 +7,0 @@

2

lib/createGeneratorFacade.js

@@ -16,3 +16,3 @@ "use strict";

["expand", "generate", "map", "shrink", "take", "toString", "values"].forEach(function (method) {
["expand", "first", "generate", "map", "shrink", "take", "toString", "values"].forEach(function (method) {
if (defaultGenerator[method]) {

@@ -19,0 +19,0 @@ generatorFacade[method] = defaultGenerator[method].bind(defaultGenerator);

@@ -26,2 +26,7 @@ "use strict";

}, {
key: "first",
value: function first(options) {
return this.values(options).next();
}
}, {
key: "take",

@@ -28,0 +33,0 @@ value: function take(count, options) {

@@ -74,3 +74,25 @@ "use strict";

describe("first", function () {
it("returns the first item from the generator", function () {
expect(generator.first(), "to equal", 37);
});
it("advances the random values", function () {
expect(generator.first(), "not to equal", generator.first());
});
describe("when given a seed", function () {
it("generate an item with the given seed", function () {
expect(generator.first({ seed: 666 }), "to equal", 70);
});
});
});
describe("take", function () {
it("fails when given no arguments", function () {
expect(function () {
generator.take();
}, "to throw", "The take method requires a positive number as parameter");
});
it("returns the given number of items from the generator", function () {

@@ -77,0 +99,0 @@ expect(generator.take(5), "to equal", [37, 80, 96, 18, 73]);

@@ -56,2 +56,6 @@ "use strict";

value: function take(count) {
if (typeof count !== "number" || count < 1) {
throw new Error("The take method requires a positive number as parameter");
}
var result = new Array(count);

@@ -58,0 +62,0 @@ for (var i = 0; i < count; i += 1) {

@@ -45,3 +45,3 @@ "use strict";

it("expands the parent generator and maps it again", function () {
var value = mapGenerator.take(1)[0];
var value = mapGenerator.first();

@@ -48,0 +48,0 @@ expect(mapGenerator.expand(value), "to yield items", ["E)1(N25SSLGLTEH#YSK0", "A(N25SSLGLHEH#YJK09", "(%25SSLGLHEH)YSK0U", "(N25SSLGLHEH#YSK0", "(N25SSLGLHEH#YSK0"]);

@@ -55,3 +55,3 @@ "use strict";

it("returns the shrunken generator that it was given", function () {
var value = generator.take(1)[0];
var value = generator.first();
expect(generator.shrink(value), "to satisfy", {

@@ -58,0 +58,0 @@ generatorName: "integer",

"use strict";
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var expect = require("../test/expect");

@@ -23,5 +21,3 @@ var PrimitiveGenerator = require("./PrimitiveGenerator");

it("shrinks the primitive value", function () {
var _generator$take = generator.take(1),
_generator$take2 = _slicedToArray(_generator$take, 1),
value = _generator$take2[0];
var value = generator.first();

@@ -35,5 +31,3 @@ expect(value, "to equal", 9015);

it("expands the primitive value", function () {
var _generator$take3 = generator.take(1),
_generator$take4 = _slicedToArray(_generator$take3, 1),
value = _generator$take4[0];
var value = generator.first();

@@ -40,0 +34,0 @@ expect(value, "to equal", 9015);

"use strict";
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var SequenceGenerator = require("./SequenceGenerator");

@@ -47,3 +45,3 @@ var expect = require("../test/expect");

it("expands the given sequence", function () {
var generated = generator.take(1)[0];
var generated = generator.first();
expect(generator.expand(generated), "to yield items", [[{ gender: "female", age: 46 }, { gender: "male", age: 87 }, { gender: "female", age: 33 }, { gender: "male", age: 60 }, { gender: "female", age: 14 }, { gender: "male", age: 71 }, { gender: "female", age: 65 }, { gender: "male", age: 2 }, { gender: "female", age: 5 }, { gender: "male", age: 97 }, { gender: "female", age: 72 }, { gender: "male", age: 84 }, { gender: "female", age: 94 }], [{ gender: "female", age: 0 }, { gender: "male", age: 18 }, { gender: "female", age: 100 }, { gender: "male", age: 18 }, { gender: "female", age: 62 }, { gender: "male", age: 30 }, { gender: "female", age: 61 }, { gender: "male", age: 53 }, { gender: "female", age: 0 }, { gender: "male", age: 43 }, { gender: "female", age: 2 }, { gender: "male", age: 29 }, { gender: "female", age: 53 }, { gender: "male", age: 61 }, { gender: "female", age: 40 }, { gender: "male", age: 14 }], [{ gender: "female", age: 29 }, { gender: "male", age: 98 }, { gender: "female", age: 37 }, { gender: "male", age: 23 }, { gender: "female", age: 46 }, { gender: "male", age: 9 }, { gender: "female", age: 79 }, { gender: "male", age: 62 }, { gender: "female", age: 20 }, { gender: "male", age: 38 }, { gender: "female", age: 51 }, { gender: "male", age: 99 }]]);

@@ -70,5 +68,3 @@ });

it("honors the length constraints", function () {
var _generator$take = generator.take(1),
_generator$take2 = _slicedToArray(_generator$take, 1),
generated = _generator$take2[0];
var generated = generator.first();

@@ -75,0 +71,0 @@ expect(generator.expand(generated), "to yield items", [[{ gender: "female", age: 60 }, { gender: "male", age: 60 }, { gender: "female", age: 15 }, { gender: "male", age: 45 }, { gender: "female", age: 15 }], [{ gender: "female", age: 5 }, { gender: "male", age: 46 }, { gender: "female", age: 87 }, { gender: "male", age: 33 }, { gender: "female", age: 60 }], [{ gender: "female", age: 71 }, { gender: "male", age: 65 }, { gender: "female", age: 2 }, { gender: "male", age: 5 }, { gender: "female", age: 97 }]]);

@@ -73,3 +73,3 @@ "use strict";

it("returns a new shape generator where all generators in the structure has been shunken", function () {
var value = generator.take(1)[0];
var value = generator.first();
expect(generator.shrink(value), "to satisfy", {

@@ -113,3 +113,3 @@ isGenerator: true,

it("shrinks all of the generators in the shape with regards to the given structure", function () {
var value = generator.take(1)[0];
var value = generator.first();
expect(generator.shrink(value), "to yield items", [{

@@ -163,3 +163,3 @@ nested: {

it("expands all of the generators in the shape with regards to the given structure", function () {
var value = generator.take(1)[0];
var value = generator.first();
expect(generator.expand(value), "to yield items", [{

@@ -166,0 +166,0 @@ nested: {

@@ -32,3 +32,3 @@ "use strict";

it("create arrays by picking subsets of the given items", function () {
expect(generator, "to yield items", []);
expect(generator, "to yield items", [["b", "c", "a"], ["a", "b", "c"], ["b", "c", "a"], ["b", "a", "c"], ["a", "c", "b"]]);
});

@@ -35,0 +35,0 @@

"use strict";
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var expect = require("../test/expect").clone();

@@ -53,5 +51,3 @@ var TreeGenerator = require("./TreeGenerator");

it("produces a generator that will generate trees similar to the given value", function () {
var _generator$take = generator.take(1),
_generator$take2 = _slicedToArray(_generator$take, 1),
value = _generator$take2[0];
var value = generator.first();

@@ -84,5 +80,3 @@ expect(value, "to equal", [80, [96, [18, 73], 78, 60], [[60, 15], 45], 15, 10]);

it("honor the constaints", function () {
var _generator$take3 = generator.take(1),
_generator$take4 = _slicedToArray(_generator$take3, 1),
value = _generator$take4[0];
var value = generator.first();

@@ -108,5 +102,3 @@ expect(generator.expand(value), "to yield items satisfying", "to have size satisfying", "to be within", generator.options.min, generator.options.max);

it("honor the constaints", function () {
var _generator$take5 = generator.take(1),
_generator$take6 = _slicedToArray(_generator$take5, 1),
value = _generator$take6[0];
var value = generator.first();

@@ -113,0 +105,0 @@ expect(generator.expand(value), "to yield items satisfying", "to have size satisfying", "to be within", generator.options.min, generator.options.max);

@@ -59,3 +59,3 @@ "use strict";

it("returns the shrunken generator that it was given", function () {
var value = generator.take(1)[0];
var value = generator.first();
expect(generator.shrink(value), "to satisfy", {

@@ -70,3 +70,3 @@ generatorName: "stringSplicer",

it("returns a weighted generator where the found item is expanded and the weight is increased", function () {
var value = generator.take(1)[0];
var value = generator.first();

@@ -73,0 +73,0 @@ expect(generator.expand(value), "to yield items", ["TwTMaFbvMTDkdv[BrHg6ToCM[RId@S", "n25SSlGlheH#ySk0Wbe)19*pa", "n25SSlG&heH#ySk0Wbe)19*pa", "^@!UHyheBxXyX1RVu$PIC", "!41Pr5sKcM0FibGhoc%VJxPLZ^ksSE", "n25SSlGlheH#ySk0Wbe)19*pa", "xqMP0DAe)s)ssZK0wkv]ctT[LEdcu", "rYkNKH[OrRXf4Brr17BIU[UDN8g7", "n25SSlGlheH#ySk0Wbe)19*pa", "m8[PMNtr]g", "%nU5SSlGlheH$ySk0Wbe)19*pa", "n25SSlGlheH#yKk0Ube)19*Oa", ")Q)[@fvwCo!txJmB", "n25SSlGlheH#ySk0Wbe)19*pa", 70]);

@@ -6,3 +6,3 @@ {

"license": "MIT",
"version": "3.4.0",
"version": "3.5.0",
"main": "lib/index.js",

@@ -9,0 +9,0 @@ "files": [

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