Skip to content

Commit

Permalink
Merge pull request #31 from helpscout/security-and-avatar
Browse files Browse the repository at this point in the history
Update packages & es module only
  • Loading branch information
plbabin authored May 18, 2021
2 parents 22f520c + f218056 commit ccb4aae
Show file tree
Hide file tree
Showing 37 changed files with 8,271 additions and 5,150 deletions.
19 changes: 8 additions & 11 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
{
"presets": ["./scripts/babel-preset-env"],
"env": {
"development": {
"presets": ["es2015"],
},
"umd": {
"plugins": [
"transform-es2015-modules-umd"
]
}
}
"presets": [
[
"@babel/env",
{
"targets": ">0.25%"
}
]
]
}
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@
Helix allows you to quickly (and reliably) generate fixture data to be hydrated into Javascript components/views (like React, Vue, Backbone, etc…).


## Install

```
npm install @helpscout/helix --save-dev
```


## Documentation

Check out **[our documentation](./docs)** for more info!


## Basic usage

The `createSpec` function is used to define your fixture spec. Helix comes with an adjusted version of [Faker.js](https://github.com/marak/Faker.js/), which also needs to be imported. Note, the API for Helix's faker is the **exact** same as Faker.js.
Expand All @@ -27,7 +24,7 @@ The `createSpec` function is used to define your fixture spec. Helix comes with
import { createSpec, faker } from '@helpscout/helix'

const CustomerSpec = createSpec({
id: faker.random.number()
id: faker.datatype.number()
fname: faker.name.firstName()
lname: faker.name.lastName()
company: faker.company.companyName()
Expand Down
26 changes: 11 additions & 15 deletions docs/api/HelixSpec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,29 @@

HelixSpec is the class that gets returned by the `createSpec()` function.


### Usage

```js
const Dinosaur = createSpec({
id: faker.random.number(),
id: faker.datatype.number(),
name: faker.name.firstName(),
location: faker.address.country()
})
location: faker.address.country(),
});
// Returns a HelixSpec
```


### Arguments

| Argument | Type | Description |
| --- | --- | --- |
| `shape` | `object` | Object containing key/value pairs to construct the fixture data. |


| Argument | Type | Description |
| -------- | -------- | ---------------------------------------------------------------- |
| `shape` | `object` | Object containing key/value pairs to construct the fixture data. |

### Methods

HelixSpec contains a handful of methods:

* [extend](./extend.md)
* [beforeGenerate](./beforeGenerate.md)
* [generate](./generate.md)
* [afterGenerate](./afterGenerate.md)
* [seed](./seed.md)
- [extend](./extend.md)
- [beforeGenerate](./beforeGenerate.md)
- [generate](./generate.md)
- [afterGenerate](./afterGenerate.md)
- [seed](./seed.md)
33 changes: 15 additions & 18 deletions docs/api/HelixSpec/afterGenerate.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,37 @@

A hook to adjust the fixture output (`object`) of the HelixSpec that is called right after the fixture is [generated](./generate.md).


### Arguments

| Argument | Type | Description |
| --- | --- | --- |
| `callback` | `function` | Callback function to adjust the fixture data. |
| `data` | `object` | Generated fixture data passed into the `callback`. |

| Argument | Type | Description |
| ---------- | ---------- | -------------------------------------------------- |
| `callback` | `function` | Callback function to adjust the fixture data. |
| `data` | `object` | Generated fixture data passed into the `callback`. |

### Returns

`HelixSpec`: Returns itself.


### Example

```js
const Dinosaur = createSpec({
id: faker.random.number(),
id: faker.datatype.number(),
name: faker.name.firstName(),
location: faker.address.country()
})
location: faker.address.country(),
});

Dinosaur.afterGenerate(data => {
const { name } = data
Dinosaur.afterGenerate((data) => {
const { name } = data;
return {
name,
location: 'Mexico',
status: 'Happy',
email: '[email protected]'
}
})
location: "Mexico",
status: "Happy",
email: "[email protected]",
};
});

Dinosaur.generate()
Dinosaur.generate();
// {
// name: 'Alice',
// location: 'Mexico'
Expand Down
31 changes: 14 additions & 17 deletions docs/api/HelixSpec/beforeGenerate.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,38 @@

A hook to adjust the shape (`object`) of the HelixSpec that is called right before the fixture is [generated](./generate.md).


### Arguments

| Argument | Type | Description |
| --- | --- | --- |
| Argument | Type | Description |
| ---------- | ---------- | -------------------------------------------- |
| `callback` | `function` | Callback function to adjust the Helix shape. |
| `shape` | `object` | Helix shape passed into the `callback`. |

| `shape` | `object` | Helix shape passed into the `callback`. |

### Returns

`HelixSpec`: Returns itself.


### Example

```js
const Dinosaur = createSpec({
id: faker.random.number(),
id: faker.datatype.number(),
name: faker.name.firstName(),
location: faker.address.country()
})
location: faker.address.country(),
});

Dinosaur.beforeGenerate(shape => {
const { id, name } = shape
Dinosaur.beforeGenerate((shape) => {
const { id, name } = shape;
return {
id,
name,
location: 'Mexico',
status: 'Happy',
email: faker.internet.email()
}
})
location: "Mexico",
status: "Happy",
email: faker.internet.email(),
};
});

Dinosaur.generate()
Dinosaur.generate();
// {
// id: 1231,
// name: 'Alice',
Expand Down
22 changes: 10 additions & 12 deletions docs/api/HelixSpec/extend.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,33 @@ Extends the spec shape of the HelixSpec.

### Arguments

| Argument | Type | Description |
| --- | --- | --- |
| `specs` | `object` | Merges the additional objects with the initial spec object. |

| Argument | Type | Description |
| -------- | -------- | ----------------------------------------------------------- |
| `specs` | `object` | Merges the additional objects with the initial spec object. |

### Returns

`HelixSpec`: Return itself.


### Example

To extend the initial spec shape, pass in a new `object` as an argument. Additional `objects` can be passed in as additional arguments.

```js
const Dinosaur = createSpec({
id: faker.random.number(),
id: faker.datatype.number(),
name: faker.name.firstName(),
location: faker.address.country()
})
location: faker.address.country(),
});

Dinosaur.extend({
company: 'Jurassic Parkland',
color: faker.commerce.color()
})
company: "Jurassic Parkland",
color: faker.commerce.color(),
});

// Dinosaur's spec shape will now be:
// {
// id: faker.random.number(),
// id: faker.datatype.number(),
// name: faker.name.firstName(),
// location: faker.address.country(),
// company: 'Jurassic Parkland',
Expand Down
23 changes: 9 additions & 14 deletions docs/api/HelixSpec/generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,56 @@

Returns an object in the shape of the HelixSpec, rendered with the appropriate [Faker](https://github.com/marak/Faker.js/) fields.


### Arguments

| Argument | Type | Description |
| --- | --- | --- |
| `count` | `number` | Generates `n` number of fixture objects. Returns an `array`. |
| Argument | Type | Description |
| ---------- | -------- | ------------------------------------------------------------------------------------------------ |
| `count` | `number` | Generates `n` number of fixture objects. Returns an `array`. |
| `maxCount` | `number` | Generates a random amount between `count` and `maxCount` of fixture objects. Returns an `array`. |


### Returns

`object` | `array`: Rendered fixture object. Returns an array of rendered fixture objects if `count` is used.


### Example

```js
const Dinosaur = createSpec({
id: faker.random.number(),
id: faker.datatype.number(),
name: faker.name.firstName(),
location: faker.address.country()
})
location: faker.address.country(),
});

Dinosaur.generate()
Dinosaur.generate();
// {
// id: 1231,
// name: 'Alice',
// location: 'Canada'
// }
```


#### Generating multiple fixtures

You can generate an array of fixtures by passing in a `number` for the `count` argument.

**Example**

```js
Dinosaur.generate(2)
Dinosaur.generate(2);
// [
// { id: 55079, name: 'Antone', location: 'Pitcairn Islands' },
// { id: 83994, name: 'Eileen', location: 'Brazil' }
// ]
```


#### Generating a random amount of fixtures

You can generate an array containing a random amount of fixtures between two `numbers` by passing in the `count` and `maxCount` arguments.

**Example**

```js
Dinosaur.generate(1, 5)
Dinosaur.generate(1, 5);
// [
// { id: 76619, name: 'Tess', location: 'Jordan' },
// { id: 60633, name: 'Madeline', location: 'Uzbekistan' },
Expand Down
14 changes: 6 additions & 8 deletions docs/api/HelixSpec/seed.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,25 @@ Sets the [Faker](https://github.com/marak/Faker.js/#setting-a-randomness-seed) r

### Arguments

| Argument | Type | Description |
| --- | --- | --- |
| Argument | Type | Description |
| ----------- | -------- | ----------------------------------------------------- |
| `seedValue` | `number` | Seed value to determine the rendered fixture results. |


### Returns

`HelixSpec`: Renders itself.


### Example

To seed your fixture, use the `.seed()` method **before** you use `.generate()`. These methods can even be chained together!

```js
const Dinosaur = createSpec({
id: faker.random.number(),
id: faker.datatype.number(),
name: faker.name.firstName(),
location: faker.address.country()
})
location: faker.address.country(),
});

Dinosaur.seed(3).generate()
Dinosaur.seed(3).generate();
// { id: 55079, name: 'Antone', location: 'Pitcairn Islands' }
```
Loading

0 comments on commit ccb4aae

Please sign in to comment.