# ng.data

> simple data storage

Latest version **0.0.0-rc1** (published 2014-04-06) · 0 weekly downloads

## Install

```sh
npm install ng.data
pnpm add ng.data
yarn add ng.data
bun add ng.data
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.0-rc1 |
| Published | 2014-04-06 |
| First published | 2014-04-06 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Adam Kircher |
| Maintainers | akircher |

## Links

- npm: https://www.npmjs.com/package/ng.data
- npm.io page: https://npm.io/package/ng.data

## Recent versions

- 0.0.0-rc1 (latest) — 2014-04-06

## README

# ng.data: data persistence getter/setter
ng.data aims to make it dead simple to persist data

## api
ng.data has a very simple API
```javascript
ng.data = function(key, value, persist)
{

}
```

## get/set
ng.data is just a getter/setter
```javascript
module('example').controller('ctrl', function(data)
{
	var val = 'Hello!'

	//Store the value under key
	data('key', val)

	//Get the value: logs Hello!
	console.log(data('key'))

	//Delete the value
	data('key', undefined)
})
```

## persistance

If persist is truthy, data is persisted until deleted. On the client this is done with localStorage, on the server this is done with a JSON object.

If persist is undefined, data is persisted in memory only.  On the client this is done with sessionStorage, on the server this is done with memory (until server restart).

If persist is falsey (but not undefined), data is stored as flash data.  It will be available on the next location path change and then will be erased (this is great for alert messages)

## shorthand
Sometimes getters/setters can be annoying if you only want to manipulate data. ng.data has shorthand for these common manipulations

####incrementing
verbose
```javascript
module('example').controller('ctrl', function(data)
{
  var count = data('count')

  count += 5

  data('count', count)
})
```

shorthand
```javascript
module('example').controller('ctrl', function(data)
{
  data('count+', 5)
})
```

####decrementing
verbose
```javascript
module('example').controller('ctrl', function(data)
{
  var count = data('count')

  count -= 5

  data('count', count)
})
```
shorthand
```javascript
module('example').controller('ctrl', function(data)
{
  data('count-', 5)
})
```

#### pushing values
verbose
```javascript
module('example').controller('ctrl', function(data)
{
  var arr = data('arr')

  arr.push('Hello!')

  data('arr', arr)
})
```

shorthand
*note: this only works if arr is already an array*
```javascript
module('example').controller('ctrl', function(data)
{
  data('arr[]', 'Hello!')
})
```

#### adding properties
verbose
```javascript
module('example').controller('ctrl', function(data)
{
  var obj = data('obj')

  obj.prop = 'Hello!'

  data('obj', obj)
})
```

shorthand
*note: this only works if obj is already an object*
```javascript
module('example').controller('ctrl', function(data)
{
  data('obj.prop', 'Hello!')
})
```

## changelog
#### 0.0.0-rc1
- Initial commit

## todos
- ???

## related projects
- [ng](https://github.com/ng-/ng): angular reimagined
- [ng.seed](https://github.com/ng-/ng.seed): create a modular ng application using npm packages
- ng.cql: realtime cassandra database syncing
- [ng.auth](https://github.com/ng-/ng.auth): example authentication using ng interceptors
- [ng.crud](https://github.com/ng-/ng.crud): example demonstrating a simple crud application using ng.seed
- [ng.style](https://github.com/ng-/ng.style): beautiful html using twitter bootstrap

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