Skip to content

Commit

Permalink
release v0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Eries Trisnadi committed Dec 24, 2017
1 parent e00ad7b commit c902ced
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 10 deletions.
99 changes: 99 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Jaysn
![https://www.npmjs.org/package/jaysn](https://img.shields.io/npm/v/jaysn.svg) ![https://travis-ci.org/lowsprofile/jaysn](https://travis-ci.org/lowsprofile/jaysn.svg?branch=master) ![https://www.patreon.com/bePatron?c=1404837](https://img.shields.io/badge/donate-patreon-red.svg)

Lightweight JSON database for Node, Hybrid, and Browser.
Powered by Immutable and Superstruct.

## Getting Started
### Node / Hybrid
Install `jaysn` using node packager: yarn, or npm
```sh
# Install using yarn
yarn add jaysn

# Or, using npm
npm install jaysn --save
```
Then require it into any module
```js
const { jaysn } = require('jaysn');
const options = {use: 'File', source: 'db.json'};
const schema = {
posts: {
id: 'number',
title: 'string',
},
};
const db = jaysn(schema, options);
```

### Browser
A UMD build is also available on [unpkg](https://unpkg.com/) for testing and quick prototyping:
```html
<script src="https://unpkg.com/[email protected]/dist/immutable.min.js"></script>
<script src="https://unpkg.com/[email protected]/umd/superstruct.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/jaysn.min.js"></script>
<script>
var jaysn = Jaysn.jaysn;
var options = {use: 'LocalStorage', source: 'MyDB'};
var schema = {
posts: {
id: 'number',
title: 'string',
},
};
var db = jaysn(schema, options);
</script>
```

## Live Examples
- [RunKit example for Node/Hybrid](https://runkit.com/lowsprofile/5a3ff3aa22eb6c0011063af7)
- [JSFiddle example for Browser](https://jsfiddle.net/wdgyczx8/)

## API
### jaysn(schema, options?)
Returns an Immutable fromJS with additional properties and functions described below.

### db.write()
Writes database to file / local storage, and returns an Immutable of database state.
```js
db.set('posts', [])
.write();
// Map { posts: List [ ... ] };
```

### db.getState()
Get current database state from file / local storage.
```js
db.getState();
// Map { posts: List [ ... ] };
```

## Quick Guides
Recommended to learn [Immutable API](https://facebook.github.io/immutable-js/docs/), so after that you can know how to query and manipulate data. Here are a few example to get you started.

### Examples
Set posts.
```js
db.set('posts', [])
.write();
```

Get posts.
```js
db.get('posts');
```

Adding posts.
```js
const data = { id: 1, title: 'Hello Jaysn!'};
db.set('posts', db.get('posts').push(data))
.write();
// Map { posts: List [ Map { id: 1, title: 'Hello Jaysn!' } ] }
```

## License
MIT License © 2017-Present **[lowsprofile](https://github.com/lowsprofile)**. All rights reserved.

## Legal
This is a free and open source app. Use it at your own risk.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jaysn",
"version": "0.1.0",
"description": "A databaseless data storing with one JSON file.",
"version": "0.1.1",
"description": "Lightweight JSON database for Node, Hybrid, and browser.",
"homepage": "https://lowsprofile.github.io/jaysn/",
"repository": "lowsprofile/jaysn",
"author": "Eries Trisnadi <[email protected]> (https://eries.id)",
Expand Down
18 changes: 10 additions & 8 deletions tools/build-docs.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
const { join, resolve } = require('path');
const { readdirSync, writeFileSync, readFileSync } = require('fs');
const { readdirSync, writeFileSync, readFileSync, existsSync } = require('fs');
const { name, version } = require('../package.json');

const RESOURCES_PATH = resolve('resources');
const DOCS_PATH = join(RESOURCES_PATH, 'docs');
const pages = [];
const docs = readdirSync(DOCS_PATH);

function capitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}

docs.map(o => {
pages.push({
title: capitalize(o).replace('.md', ''),
content: readFileSync(join(DOCS_PATH, o), 'utf8'),
if (existsSync(DOCS_PATH)) {
const docs = readdirSync(DOCS_PATH);
docs.map(o => {
pages.push({
title: capitalize(o).replace('.md', ''),
content: readFileSync(join(DOCS_PATH, o), 'utf8'),
});
return o;
});
return o;
});
}

const result = JSON.stringify(
{
Expand Down

0 comments on commit c902ced

Please sign in to comment.