factory-mate
Advanced tools
Comparing version 1.3.0 to 1.3.1
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var FactoryStamp_1 = require("./FactoryStamp"); | ||
var FactoryMate = (function () { | ||
@@ -10,7 +11,3 @@ function FactoryMate() { | ||
FactoryMate.defineWithName = function (cns, alias, initFunction) { | ||
FactoryMate.definedConstructors.push({ | ||
classAlias: alias, | ||
classConstructor: cns, | ||
initializationFunction: initFunction | ||
}); | ||
FactoryMate.definedConstructors.push(new FactoryStamp_1.FactoryStamp(cns, alias, initFunction)); | ||
}; | ||
@@ -29,3 +26,3 @@ FactoryMate.build = function (itemName, overrideFn) { | ||
if (numberToBuild < 1) { | ||
numberToBuild = 1; | ||
throw new Error("Number of Items to Build Must Be 1 or Higher. Received " + numberToBuild); | ||
} | ||
@@ -39,3 +36,5 @@ var createdClasses = new Array(); | ||
FactoryMate.locateConstructor = function (objectName) { | ||
var clazz = FactoryMate.definedConstructors.find(function (stored) { return stored.classAlias === objectName; }); | ||
var clazz = FactoryMate.definedConstructors.find(function (stored) { | ||
return stored.classAlias === objectName; | ||
}); | ||
if (clazz === undefined) { | ||
@@ -42,0 +41,0 @@ throw new Error("Class with name " + objectName + " is not registered to FactoryMate."); |
{ | ||
"name": "factory-mate", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "TypeScript library for building domain objects", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -16,2 +16,5 @@ # FactoryMate | ||
## Example | ||
An example project using FactoryMate can be found here: [FactoryMateConsumer](https://github.com/rwaskiewicz/factory-mate-consumer) | ||
## Usage | ||
@@ -187,6 +190,19 @@ | ||
## Example | ||
An example project using FactoryMate can be found here [FactoryMateConsumer](https://github.com/rwaskiewicz/factory-mate-consumer) | ||
## Recipes | ||
### Creating a Random Number Generator | ||
A random number generator can be created by passing a `Math.random()` function call wrapped in an array to the `ProvidedNumberGenerator` class: | ||
```typescript | ||
// Each call to randomNumberGenerator.nextValue() will produce a number between 0 and 9 | ||
const randomNumberGenerator = new ProvidedValueGenerator([Math.floor(Math.random() * 10)], true); | ||
FactoryMate.define(GroceryItem, (): GroceryItem => { | ||
const groceryItem = new GroceryItem(); | ||
groceryItem.id = randomNumberGenerator.nextValue(); | ||
groceryItem.groceryName = 'Chips'; | ||
return groceryItem; | ||
}); | ||
``` | ||
## License | ||
FactoryMate is distributed under the [MIT license](https://opensource.org/licenses/MIT) | ||
FactoryMate is distributed under the [MIT license](https://opensource.org/licenses/MIT) |
Sorry, the diff of this file is not supported yet
17728
19
163
207