-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,46 @@ | ||
# ts-module-boilerplate | ||
# Searilie | ||
|
||
[![Greenkeeper badge](https://badges.greenkeeper.io/crazyfactory/ts-module-boilerplate.svg)](https://greenkeeper.io/) | ||
[![Build Status](https://travis-ci.org/crazyfactory/ts-module-boilerplate.svg)](https://travis-ci.org/crazyfactory/ts-module-boilerplate) | ||
[![GitHub issues](https://img.shields.io/github/issues/crazyfactory/ts-module-boilerplate.svg)](https://github.com/crazyfactory/ts-module-boilerplate/issues) | ||
[![codecov](https://codecov.io/gh/crazyfactory/ts-module-boilerplate/branch/master/graph/badge.svg)](https://codecov.io/gh/crazyfactory/ts-module-boilerplate) | ||
[![devDependencies Status](https://david-dm.org/crazyfactory/ts-module-boilerplate/dev-status.svg)](https://david-dm.org/crazyfactory/ts-module-boilerplate?type=dev) | ||
[![dependencies Status](https://david-dm.org/crazyfactory/ts-module-boilerplate/status.svg)](https://david-dm.org/crazyfactory/ts-module-boilerplate) | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/fossapps/Searilie.svg)](https://greenkeeper.io/) | ||
[![Build Status](https://travis-ci.org/fossapps/Searilie.svg)](https://travis-ci.org/fossapps/Searilie) | ||
[![GitHub issues](https://img.shields.io/github/issues/fossapps/Searilie.svg)](https://github.com/fossapps/Searilie/issues) | ||
[![codecov](https://codecov.io/gh/fossapps/Searilie/branch/master/graph/badge.svg)](https://codecov.io/gh/fossapps/Searilie) | ||
[![devDependencies Status](https://david-dm.org/fossapps/Searilie/dev-status.svg)](https://david-dm.org/fossapps/Searilie?type=dev) | ||
[![dependencies Status](https://david-dm.org/fossapps/Searilie/status.svg)](https://david-dm.org/fossapps/Searilie) | ||
|
||
This boilerplate allows the quick creation of npm modules written in Typescript. | ||
This library tries to encode data to a very small payload, useful when you want to add data to url query parameters | ||
|
||
- Typescript 3.x | ||
- creates an ES5 bundle | ||
- creates a TypeScript declaration bundle | ||
- packs it for npm usage | ||
- uses jest for testing | ||
- uses travis and semantic-release for deployment | ||
- uses linting, coverage and git hooks to increase code quality. | ||
- is configured to support wallaby | ||
# Limitations | ||
- It can only store array of objects | ||
- each object on array must have same keys (name and number of keys) | ||
- it can only serialize string and number values nothing else | ||
- while decoding we need to pass a spec for our object | ||
|
||
## Usage | ||
## Example: | ||
```typescript | ||
import {Searilie} from "./src/Searilie" | ||
import {TinyCompressor} from "./src/adapters/TinyCompressor" | ||
const serialization = new Searilie(new TinyCompressor()); // or use CSVCompressor | ||
console.log(serialization.encode([{a: "k", b: 5}, {a: "c", b: 9}])); // Ak5c9 | ||
``` | ||
|
||
Initially you should: | ||
## Tiny compressor: | ||
can only compress 1 character values, but produces tiny payloads, | ||
|
||
- clone this repository | ||
- update `package.json` (name, repository and description) | ||
- create your own `README.md` (from the `README.tpl.md`-file) | ||
- uncomment `after_success` block in `.travis.yml` to activate semantic-release | ||
## CSVCompressor | ||
separates data using , and ; producing larger payloads, but it can support more than 1 character payloads: | ||
```typescript | ||
import {Searilie} from "./src/Searilie" | ||
import {CSVCompressor} from "./src/adapters/CSVCompressor"; | ||
const serialization = new Searilie(new CSVCompressor()); | ||
console.log(serialization.encode([{a: "kick", b: 51}, {a: "cat", b: 92}])); // Bkick,51;cat,92 | ||
``` | ||
|
||
Afterwards you can start implementing classes and tests :) | ||
## deserialization | ||
the first character on encoded payload denotes which compressor was used, we need to use the same compressor to ensure we don't load everything at once, we don't import everything and check it for you. | ||
```typescript | ||
import {Searilie, ValueType} from "./src/Searilie" | ||
import {CSVCompressor} from "./src/adapters/CSVCompressor"; | ||
const serialization = new Searilie(new CSVCompressor()); | ||
console.log(serialization.decode("Bkick,51;cat,92", {a: ValueType.String, b: ValueType.Number})); // [{a: "kick", b: 51}, {a: "cat", b: 92}] | ||
console.log(serialization.decode("Bkick,51;cat,92", {myKey: ValueType.String, newKey: ValueType.Number})); // [{myKey: "kick", newKey: 51}, {myKey: "cat", newKey: 92}] | ||
``` |