mirror of
https://github.com/nolanlawson/blob-util.git
synced 2025-12-08 19:46:19 +00:00
readme
This commit is contained in:
parent
e3872d26d5
commit
10e89cd0a1
86
README.md
86
README.md
@ -1,10 +1,18 @@
|
|||||||
PouchDB Plugin Seed
|
blob-util
|
||||||
=====
|
=====
|
||||||
|
|
||||||
[](https://travis-ci.org/pouchdb/plugin-seed)
|
[](https://travis-ci.org/nolanlawson/blob-util)
|
||||||
|
|
||||||
Fork this project to build your first PouchDB plugin. It contains everything you need to test in Node, WebSQL, and IndexedDB. It also includes a Travis config file so you
|
You know what's cool? [HTML5 Blobs](https://developer.mozilla.org/en-US/docs/Web/API/Blob?redirectlocale=en-US&redirectslug=DOM%2FBlob).
|
||||||
can automatically run the tests in Travis.
|
|
||||||
|
You know what's hard to work with? Yeah, you guessed it.
|
||||||
|
|
||||||
|
If you just want to work with binary data in the browser and not pull your hair out, then this is the library for you.
|
||||||
|
|
||||||
|
This library offers various utilities for transforming Blobs between different formats (base 64, data URL, image), and it works
|
||||||
|
cross-browser.
|
||||||
|
|
||||||
|
This library is also a good pairing with the attachment API in [PouchDB](http://pouchdb.com).
|
||||||
|
|
||||||
Building
|
Building
|
||||||
----
|
----
|
||||||
@ -13,54 +21,11 @@ Building
|
|||||||
|
|
||||||
Your plugin is now located at `dist/pouchdb.mypluginname.js` and `dist/pouchdb.mypluginname.min.js` and is ready for distribution.
|
Your plugin is now located at `dist/pouchdb.mypluginname.js` and `dist/pouchdb.mypluginname.min.js` and is ready for distribution.
|
||||||
|
|
||||||
Getting Started
|
|
||||||
-------
|
|
||||||
|
|
||||||
**First**, change the `name` in `package.json` to whatever you want to call your plugin. Change the `build` script so that it writes to the desired filename (e.g. `pouchdb.mypluginname.js`). Also, change the authors, description, git repo, etc.
|
|
||||||
|
|
||||||
**Next**, modify the `index.js` to do whatever you want your plugin to do. Right now it just adds a `pouch.sayHello()` function that says hello:
|
|
||||||
|
|
||||||
```js
|
|
||||||
exports.sayHello = utils.toPromise(function (callback) {
|
|
||||||
callback(null, 'hello');
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
**Optionally**, you can add some tests in `tests/test.js`. These tests will be run both in the local database and a remote CouchDB, which is expected to be running at localhost:5984 in "Admin party" mode.
|
|
||||||
|
|
||||||
The sample test is:
|
|
||||||
|
|
||||||
```js
|
|
||||||
|
|
||||||
it('should say hello', function () {
|
|
||||||
return db.sayHello().then(function (response) {
|
|
||||||
response.should.equal('hello');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
----
|
----
|
||||||
|
|
||||||
### In Node
|
|
||||||
|
|
||||||
This will run the tests in Node using LevelDB:
|
|
||||||
|
|
||||||
npm test
|
|
||||||
|
|
||||||
You can also check for 100% code coverage using:
|
|
||||||
|
|
||||||
npm run coverage
|
|
||||||
|
|
||||||
If you don't like the coverage results, change the values from 100 to something else in `package.json`, or add `/*istanbul ignore */` comments.
|
|
||||||
|
|
||||||
|
|
||||||
If you have mocha installed globally you can run single test with:
|
|
||||||
```
|
|
||||||
TEST_DB=local mocha --reporter spec --grep search_phrase
|
|
||||||
```
|
|
||||||
|
|
||||||
The `TEST_DB` environment variable specifies the database that PouchDB should use (see `package.json`).
|
|
||||||
|
|
||||||
### In the browser
|
### In the browser
|
||||||
|
|
||||||
@ -75,29 +40,4 @@ You can run e.g.
|
|||||||
CLIENT=selenium:firefox npm test
|
CLIENT=selenium:firefox npm test
|
||||||
CLIENT=selenium:phantomjs npm test
|
CLIENT=selenium:phantomjs npm test
|
||||||
|
|
||||||
This will run the tests automatically and the process will exit with a 0 or a 1 when it's done. Firefox uses IndexedDB, and PhantomJS uses WebSQL.
|
This will run the tests automatically and the process will exit with a 0 or a 1 when it's done. Firefox uses IndexedDB, and PhantomJS uses WebSQL.
|
||||||
|
|
||||||
What to tell your users
|
|
||||||
--------
|
|
||||||
|
|
||||||
Below is some boilerplate you can use for when you want a real README for your users.
|
|
||||||
|
|
||||||
To use this plugin, include it after `pouchdb.js` in your HTML page:
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script src="pouchdb.js"></script>
|
|
||||||
<script src="pouchdb.mypluginname.js"></script>
|
|
||||||
```
|
|
||||||
|
|
||||||
Or to use it in Node.js, just npm install it:
|
|
||||||
|
|
||||||
```
|
|
||||||
npm install pouchdb-myplugin
|
|
||||||
```
|
|
||||||
|
|
||||||
And then attach it to the `PouchDB` object:
|
|
||||||
|
|
||||||
```js
|
|
||||||
var PouchDB = require('pouchdb');
|
|
||||||
PouchDB.plugin(require('pouchdb-myplugin'));
|
|
||||||
```
|
|
||||||
Loading…
x
Reference in New Issue
Block a user