# data-schema

> Defines & manages the properties – the columns – of tabular data using json-schema

Latest version **1.4.4** (published 2016-03-25) · 0 weekly downloads

## Install

```sh
npm install data-schema
pnpm add data-schema
yarn add data-schema
bun add data-schema
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.4 |
| Published | 2016-03-25 |
| First published | 2015-05-28 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Maintainers | sethvincent |

## Links

- npm: https://www.npmjs.com/package/data-schema
- Repository: https://github.com/sethvincent/data-schema
- Homepage: https://github.com/sethvincent/data-schema#readme
- Issues: https://github.com/sethvincent/data-schema/issues
- npm.io page: https://npm.io/package/data-schema

## Dependencies (6)

- [cuid](https://npm.io/package/cuid.md) ^1.2.5
- [extend](https://npm.io/package/extend.md) ^2.0.1
- [is-cuid](https://npm.io/package/is-cuid.md) ^1.0.0
- [isarray](https://npm.io/package/isarray.md) 0.0.1
- [type-of](https://npm.io/package/type-of.md) ^2.0.1
- [is-my-json-valid](https://npm.io/package/is-my-json-valid.md) ^2.12.0

## Recent versions

- 1.4.4 (latest) — 2016-03-25
- 1.4.3 — 2015-09-02
- 1.4.2 — 2015-08-31
- 1.4.1 — 2015-06-22
- 1.4.0 — 2015-06-22
- 1.3.1 — 2015-06-22
- 1.3.0 — 2015-06-21
- 1.2.0 — 2015-06-20
- 1.1.3 — 2015-05-28
- 1.1.2 — 2015-05-28
- 1.1.1 — 2015-05-28
- 1.1.0 — 2015-05-28
- 1.0.0 — 2015-05-28

## README

# data-schema

Defines & manages the properties – the columns – of tabular data using json-schema

## install

```
npm i --save data-schema
```

## properties format

Properties are stored in this format:

```
{
  'unique key': {
    type: 'type of the property. string, integer, etc.'
    key: 'unique key',
    name: 'Human identifier, renamable',
    default: 'a default value'
  }
}
```

You end up with a json-schema that looks something like this:

```
{ 
  title: 'Tabular data properties',
  type: 'array',
  items: { 
    type: 'object',
    properties: {
      cia8qzipj0000bawmt4s9hm30: [Object],
      cia8qzipl0001bawmf0b2cqv2: [Object],
      cia8qzipl0002bawmhhnpmh4j: [Object],
      cia8qzipm0004bawmvc0bgl8v: [Object] 
    } 
  } 
}
```

## Validating

Internally this module uses [is-my-json-valid](http://npmjs.org/is-my-json-valid) to validate data.

## Usage & API

## `var dataSchema = require('data-schema')`

### `var schema = dataSchema(options)`

**options:**  
  - schema: the full json schema object for the tabular data
  - static: default is false. if true, properties can't be added, removed, or updated

## Methods

## `schema.create(property)`

Example:

```
schema.create({
  name: 'example'
  type: 'string'
})
```

## `schema.get(key)`

Example:

```
var property = schema.get(key)
```

## `schema.update(property)`

Example:

```
var property = schema.update({
  key: 'the key',
  name: 'new name'
})
```

key is required for updating a property

## `schema.delete(key)`

Example:

```
schema.delete(key)
```

## `schema.validate(data)`

Example:

```
var property = schema.create({
  name: 'validatethis',
  type: 'string'
})

var validated = schema.validateProperty(property.key, 'this is a string')

validated // -> true
```

## `schema.validateProperty(key, value)`

```
var data = [
  {
    'test': 'string',
    'validatethis': 'string'
  }
]

var validated = schema.validate({
  test: 'cool',
  validatethis: 'ok'
})

validated // -> true
```

## `schema.all()`

Returns object of all properties

## `schema.newRow()`

Returns object with keys for all properties in the schema and default values

## `schema.addProperty(property)`

Add a property. Will create a new one or update an existing one depending on if the property has a key.

## `schema.addProperties(properties)`

Add an array or object of properties to the schema. Internally uses `schema.addProperty()`.

## Properties

## `schema.schema`

The json schema representation of your tabular data.

## License

MIT

---
_Source: https://npm.io/package/data-schema · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
