Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/michal-wrzosek/worp
worp - fixtures factory / generator
https://github.com/michal-wrzosek/worp
database factory fixture-data fixture-generator fixture-loader fixture-loading fixtures mongodb mongoose package typescript
Last synced: about 2 months ago
JSON representation
worp - fixtures factory / generator
- Host: GitHub
- URL: https://github.com/michal-wrzosek/worp
- Owner: michal-wrzosek
- License: mit
- Created: 2019-05-21T10:15:02.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-05-21T12:29:50.000Z (over 5 years ago)
- Last Synced: 2024-10-29T03:49:26.508Z (2 months ago)
- Topics: database, factory, fixture-data, fixture-generator, fixture-loader, fixture-loading, fixtures, mongodb, mongoose, package, typescript
- Language: JavaScript
- Homepage:
- Size: 343 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# worp - fixtures factory / generator
This package is useful when you need to quickly create lots of objects (fixtures) based on some instructions. Nice thing about this library is that it's super small (no dependencies) and it works very well with Typescript.
### Installation
To install this package:
```bash
npm install worp
```If you use Typescript you don't need to download anything else. Typescript will be automatically loaded.
### Example use
**Javascript:**
```typescript
import { fixtureFactory } from "worp";const factoryInstructions = {
a: index => `property A, record nr: ${index + 1}`,
b: index => index + 1,
c: () =>
`property C, random integer from 1 to 10: ${Math.ceil(Math.random() * 10)}`
};const records = fixtureFactory(factoryInstructions, {
nrOfRecordsToGenerate: 100
});
```**Typescript:**
```typescript
import { fixtureFactory, FactoryInstructions } from "worp";type ExampleProps = {
a: string;
b: number;
c: string;
};const factoryInstructions: FactoryInstructions = {
a: index => `property A, record nr: ${index + 1}`,
b: index => index + 1,
c: () =>
`property C, random integer from 1 to 10: ${Math.ceil(Math.random() * 10)}`
};const records = fixtureFactory(factoryInstructions, {
nrOfRecordsToGenerate: 100
});
```This code will generate 100 objects like this:
```
[
{
a: "property A, record nr: 1",
b: 1,
c: "property C, random integer from 1 to 10: 3",
},
{
a: "property A, record nr: 2",
b: 2,
c: "property C, random integer from 1 to 10: 6",
},
... (98 more like this)
]
```---
**Tags:**
mongodb, mongoose, typescript, database, db, fixtures, fixture, factory, generator---
This package was created out of this boilerplate:
https://github.com/michal-wrzosek/react-component-lib