@flatfile/blueprint-utils
Advanced tools
Comparing version 0.0.7 to 0.0.8
{ | ||
"name": "@flatfile/blueprint-utils", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "A helper for generating valid blueprint.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
143
readme.md
# @flatfile/blueprint-utils | ||
This package offers utilities for working with blueprint easily. | ||
## Defaults `type` to `"string"` | ||
```js | ||
sheet({ | ||
name: 'Contacts', | ||
fields: [ | ||
{ | ||
key: 'name', | ||
label: 'Full Name' | ||
}, | ||
], | ||
}) | ||
``` | ||
#### Returns full Blueprint | ||
```json | ||
{ | ||
"name": "Contacts", | ||
"fields": [ | ||
{ | ||
"label": "Full Name", | ||
"key": "name", | ||
"type": "string" | ||
} | ||
] | ||
} | ||
``` | ||
## Simple strings as field specifications | ||
```js | ||
sheet({ | ||
name: 'Contacts', | ||
fields: ['name', 'email', 'phone'], | ||
}) | ||
``` | ||
#### Returns full Blueprint | ||
```json | ||
{ | ||
"name": "Contacts", | ||
"fields": [ | ||
{ | ||
"key": "name", | ||
"type": "string" | ||
}, | ||
{ | ||
"key": "email", | ||
"type": "string" | ||
}, | ||
{ | ||
"key": "phone", | ||
"type": "string" | ||
} | ||
] | ||
} | ||
``` | ||
## Provide only a label if keys aren't important | ||
```js | ||
sheet({ | ||
name: 'Contacts', | ||
fields: [ | ||
{ | ||
label: 'Name / Nombre', | ||
type: 'string', | ||
}, | ||
], | ||
}) | ||
``` | ||
#### Returns full Blueprint | ||
```json | ||
{ | ||
"name": "Contacts", | ||
"fields": [ | ||
{ | ||
"label": "Name / Nombre", | ||
"key": "Name_Nombre", | ||
"type": "string" | ||
} | ||
] | ||
} | ||
``` | ||
## Provide constraints as simple strings | ||
```js | ||
sheet({ | ||
name: 'Contacts', | ||
fields: [ | ||
{ | ||
key: 'email', | ||
label: 'Email Address', | ||
constraints: ['required', 'unique'], | ||
}, | ||
{ | ||
key: 'phone', | ||
label: 'Phone Number', | ||
constraints: 'required', | ||
}, | ||
], | ||
}) | ||
``` | ||
#### Returns full Blueprint | ||
```json | ||
{ | ||
"name": "Contacts", | ||
"fields": [ | ||
{ | ||
"label": "Email Address", | ||
"key": "email", | ||
"type": "string", | ||
"constraints": [ | ||
{ | ||
"type": "required" | ||
}, | ||
{ | ||
"type": "unique" | ||
} | ||
] | ||
}, | ||
{ | ||
"label": "Phone Number", | ||
"key": "phone", | ||
"type": "string", | ||
"constraints": [ | ||
{ | ||
"type": "required" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
``` |
9305
147