# @jsweb/sourcedata

> Simple dynamic JS datasource object, useful to combine with observables like Vue

Latest version **1.1.0** (published 2018-06-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @jsweb/sourcedata
pnpm add @jsweb/sourcedata
yarn add @jsweb/sourcedata
bun add @jsweb/sourcedata
```

## 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.1.0 |
| Published | 2018-06-26 |
| First published | 2018-06-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Alex Bruno Cáceres |
| Maintainers | alexbruno |
| Keywords | data, source, object, js, javascript |

## Links

- npm: https://www.npmjs.com/package/@jsweb/sourcedata
- Repository: https://gitlab.com/webjs/sourcedata
- Issues: https://gitlab.com/webjs/sourcedata/issues
- npm.io page: https://npm.io/package/@jsweb/sourcedata

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.1.0 (latest) — 2018-06-26
- 1.0.8 — 2018-06-26

## README

# @jsweb/sourcedata
Simple dynamic JS datasource object, useful to combine with observables like Vue

***

## Installation

You can install it with NPM, Yarn or via Unpkg CDN

### CDN
```html
<script src="https://unpkg.com/@jsweb/sourcedata"></script>
```

## Usage

It's possible to use **sourcedata** with module loaders or globally.

### ES6

```javascript
import SourceData from '@jsweb/sourcedata'
```

### CommonJS

```javascript
let SourceData = require('@jsweb/sourcedata')
```

### CDN

If you install it via CDN, `sourcedata` object will be available at global window scope.

## Instance

**sourcedata** contains a class object that can be instantiated to a variable.

```javascript
let sdata = new SourceData(opt)
```

An `opt` object can setup SourceData as follows (default values):

```javascript
let sdata = new SourceData({
	source: [],	// Array with initial data.
	size: 0	    // Page size, items per page. 0 = no pagination
})

// Or simply: let sdata = new SourceData
```

## Properties

- **total**: total data items count
- **size**: the page size, items per page
- **pages**: pages count
- **page**: current page number
- **data**: result data items (filtered and/or sorted, if any)
- **view**: current page items
- **prev**: previews page number (or 0 if none)
- **next**: next page number (or 0 if none)

## Methods

- **setData(arr)**: set a new Array data to instance
- **pgPrev()**: navigates to previews page
- **pgNext()**: navigates to next page
- **pgFirst()**: navigates to first page
- **pgLast()**: navigates to last page
- **filter(fn)**: native JS Array.filter method to filter data (opt in)
- **sort(fn)**: native JS Array.sort method to sort data (opt in)
- **getItem(fn)**: gets an item with native JS Array.find method, returns { index: i, value: item }
- **setItem(obj)**: replaces an item value, obj argument needs to be like { index: i, value: item }
- **addItem(item)**: adds new item to data source using native JS Array.push
- **delItem(index)**: deletes an item from data source using native JS Array.splice
- **items(method, arg)**: executes a `method` with `arg`, `method` can be `filter`, `sort`, `get`, `set`, `add`, `del`,

## TODO

- ~~Filter/Sort items~~
- ~~Get/Set items~~
- ~~Add/Del items~~
- Observable events

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