datauri
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -1,1 +0,1 @@ | ||
{"version":"1.0.1","repository":{"type":"git","url":"git://github.com/heldr/datauri.git"},"engines":{"node":">= 0.10"},"keywords":["datauri","data uri","data","uri","data-uri","optimization","uri","optimize","inline","png","jpg","woff","base64"],"author":"Helder Santana","license":"MIT","name":"datauri","dependencies":{"image-size":"^0.3.5","mimer":"^0.2.1","semver":"^5.0.3"}} | ||
{"version":"1.0.2","repository":{"type":"git","url":"git://github.com/heldr/datauri.git"},"engines":{"node":">= 0.10"},"keywords":["datauri","data uri","data","uri","data-uri","optimization","uri","optimize","inline","png","jpg","woff","base64"],"author":"Helder Santana","license":"MIT","name":"datauri","dependencies":{"image-size":"^0.3.5","mimer":"^0.2.1","semver":"^5.0.3"}} |
210
README.md
@@ -1,9 +0,43 @@ | ||
# datauri | ||
[Module](http://npm.im/datauri) and [Client](http://npm.im/datauri-cli) to generate [Data URI scheme][datauri]. | ||
<h1 align="center"> | ||
<br /> | ||
<img width="365" src="https://cdn.rawgit.com/heldr/datauri/master/media/datauri.svg" alt="datauri" /> | ||
<br /> | ||
<br /> | ||
<br /> | ||
</h1> | ||
Node.js [Module](#module) and [Client](http://npm.im/datauri-cli) to generate [Data URI scheme](http://en.wikipedia.org/wiki/Data_URI_scheme). | ||
> The data URI scheme is a uniform resource identifier (URI) scheme that provides a way to include data in-line in web pages as if they were external resources. | ||
from: [Wikipedia](http://en.wikipedia.org/wiki/Data_URI_scheme) | ||
[![Build Status](https://travis-ci.org/heldr/grunt-smushit.svg?branch=master)](http://travis-ci.org/heldr/datauri) [![Coverage Status](https://coveralls.io/repos/heldr/datauri/badge.svg?branch=master&service=github)](https://coveralls.io/github/heldr/datauri?branch=master) [![Dependency Status](https://www.versioneye.com/user/projects/560b7b3f5a262f001e0007e2/badge.svg?style=flat)](https://www.versioneye.com/user/projects/560b7b3f5a262f001e0007e2) [![NPM version](http://img.shields.io/npm/dm/datauri.svg?style=flat)](https://www.npmjs.org/package/datauri) | ||
## MODULE | ||
MODULE | ||
------- | ||
`npm install --save datauri` | ||
1. [From file path](#readable-stream) | ||
* [Asynchronous](#readable-stream) | ||
* [Readable Stream](#readable-stream) | ||
* [Promise](#promise-node-012-works-with-es2016-asyncawait) | ||
* [Callback](#callback) | ||
* [Synchronous](#synchronous-class) | ||
* [Class](#synchronous-class) | ||
* [Function](#synchronous-function) | ||
2. [From a Buffer](#from-a-buffer) | ||
3. [From a String](#from-a-string) | ||
4. [Method chaining](#method-chaining) | ||
5. [Task plugins using datauri](#tools-using-datauri) | ||
* [npm script](#npm-script) | ||
* [gulp](#gulp) | ||
* [grunt](#grunt) | ||
6. [Develop](#develop) | ||
7. [License](#license) | ||
8. [ChangeLog](https://github.com/heldr/datauri/releases) | ||
9. [Tools using datauri](https://github.com/heldr/datauri/blob/master/README.md#tools-using-datauri) | ||
### Readable Stream | ||
```js | ||
@@ -13,14 +47,6 @@ const Datauri = require('datauri'); | ||
datauri.on('encoded', function (content) { | ||
console.log(content); //=> "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."; | ||
}); | ||
datauri.on('error', function (content) { | ||
console.log('Fail!'); | ||
}); | ||
datauri.pipe(process.stdout); | ||
datauri.encode('test/myfile.png'); | ||
``` | ||
### Readable Stream | ||
```js | ||
@@ -30,3 +56,6 @@ const Datauri = require('datauri'); | ||
datauri.pipe(process.stdout); | ||
datauri.on('encoded', content => console.log(content)); | ||
//=> "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."; | ||
datauri.on('error', err => console.log(err)); | ||
datauri.encode('test/myfile.png'); | ||
@@ -43,10 +72,8 @@ ``` | ||
DataURI('test/myfile.png') | ||
.then((content) => { | ||
console.log(content); //=> "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..." | ||
}).catch((err) => { | ||
throw err; | ||
}); | ||
.then(content => console.log(content)) | ||
//=> "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..." | ||
.catch(err => { throw err; }); | ||
``` | ||
### Callback for vintage users | ||
### Callback | ||
```js | ||
@@ -56,3 +83,3 @@ const DataURI = require('datauri'); | ||
datauri.encode('test/myfile.png', function (err, content) { | ||
datauri.encode('test/myfile.png', (err, content) => { | ||
if (err) { | ||
@@ -76,9 +103,44 @@ throw err; | ||
### Create from a string | ||
### Synchronous Class | ||
If DataURI class is instanciated with a file path, the same will be processed synchronously. | ||
```js | ||
const DataURI = require('datauri'); | ||
const datauri = new Datauri(); | ||
const Datauri = require('datauri'); | ||
let datauri = new Datauri('test/myfile.png'); | ||
datauri.format('.png', 'xkcd'); | ||
console.log(datauri.content); //=> "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..." | ||
console.log(datauri.mimetype); //=> "image/png" | ||
console.log(datauri.base64); //=> "iVBORw0KGgoAAAANSUhEUgAA..." | ||
console.log(datauri.getCSS()); //=> "\n.case {\n background-image: url('data:image/png;base64,iVBORw..." | ||
console.log(datauri.getCSS("myClass")); //=> "\n.myClass {\n background-image: url('data:image/png;base64,iVBORw..." | ||
``` | ||
### Synchronous Function | ||
```js | ||
const Datauri = require('datauri').sync; | ||
console.log(Datauri('test/myfile.png')); //=> "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..." | ||
``` | ||
or for ES2015/6 lovers | ||
```js | ||
import { sync as DataURI } from 'datauri'; | ||
console.log(DataURI('test/myfile.png')); //=> "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..." | ||
``` | ||
### From a Buffer | ||
If you already have your file as a Buffer, use this. It's much faster than passing a string. | ||
```js | ||
const Datauri = require('datauri'), | ||
const datauri = new Datauri(); | ||
//... | ||
const buffer = fs.readFileSync('./hello'); | ||
//... | ||
datauri.format('.png', buffer); | ||
console.log(datauri.content); //=> "data:image/png;base64,eGtjZA==" | ||
@@ -95,19 +157,13 @@ console.log(datauri.mimetype); //=> "image/png" | ||
### Create from a Buffer | ||
If you already have your file as a Buffer, use this. It's much faster than passing a string. | ||
### From a string | ||
```js | ||
var Datauri = require('datauri'), | ||
dUri = new Datauri(); | ||
const DataURI = require('datauri'); | ||
const datauri = new Datauri(); | ||
//... | ||
var buffer = fs.readFileSync('./hello'); | ||
//... | ||
datauri.format('.png', 'xkcd'); | ||
dUri.format('.png', buffer); | ||
console.log(dUri.content); //=> "data:image/png;base64,eGtjZA==" | ||
console.log(dUri.mimetype); //=> "image/png" | ||
console.log(dUri.base64); //=> "eGtjZA==" | ||
console.log(dUri.getCSS({ | ||
console.log(datauri.content); //=> "data:image/png;base64,eGtjZA==" | ||
console.log(datauri.mimetype); //=> "image/png" | ||
console.log(datauri.base64); //=> "eGtjZA==" | ||
console.log(datauri.getCSS({ | ||
class: "myClass", | ||
@@ -120,7 +176,7 @@ width: true, | ||
#### Chaining all stuff | ||
#### Method chaining | ||
```js | ||
//... | ||
datauri | ||
.on('encoded', function (content) { | ||
.on('encoded', content => { | ||
console.log(content); //=> "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..." | ||
@@ -134,62 +190,9 @@ console.log(this.mimetype); //=> "image/png" | ||
}) | ||
.on('error', function (content) { | ||
console.log('Fail!'); | ||
}) | ||
.on('error', err => console.error(err)) | ||
.encode('test/myfile.png'); | ||
``` | ||
### Sync (kids! Don't use it at home!) | ||
#### Sync Class | ||
If DataURI class is instanciated with a file path, the same will be processed synchronously. | ||
```js | ||
const Datauri = require('datauri'); | ||
let datauri = new Datauri('test/myfile.png'); | ||
console.log(datauri.content); //=> "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..." | ||
console.log(datauri.mimetype); //=> "image/png" | ||
console.log(datauri.base64); //=> "iVBORw0KGgoAAAANSUhEUgAA..." | ||
console.log(datauri.getCSS()); //=> "\n.case {\n background-image: url('data:image/png;base64,iVBORw..." | ||
console.log(datauri.getCSS("myClass")); //=> "\n.myClass {\n background-image: url('data:image/png;base64,iVBORw..." | ||
``` | ||
#### Sync Function | ||
```js | ||
const Datauri = require('datauri').sync; | ||
console.log(Datauri('test/myfile.png')); //=> "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..." | ||
``` | ||
or for ES2015/6 lovers | ||
```js | ||
import { sync as DataURI } from 'datauri'; | ||
console.log(DataURI('test/myfile.png')); //=> "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..." | ||
``` | ||
NPM SCRIPT AND TERMINAL CLIENT | ||
DEVELOP | ||
------- | ||
* [datauri-cli](https://npmjs.org/package/datauri-cli) | ||
GULP | ||
----- | ||
* [gulp-image-data-uri](https://github.com/adam-lynch/gulp-image-data-uri) - A [Gulp](http://github.com/gulpjs/gulp) plugin for converting images to inline data-URIs. Intended to be a simple single-purpose wrapper for [heldr/datauri](https://github.com/heldr/datauri). | ||
GRUNT | ||
----- | ||
There are a bunch of grunt plugins running on top of datauri module. | ||
* [grunt-datauri](https://npmjs.org/package/grunt-datauri) - Create base64 encoded data-uris for css from images | ||
* [grunt-imweb](https://npmjs.org/package/grunt-imweb) - IMWEB Tasks Collection For Daily Workflow. | ||
* [grunt-static-inline](https://npmjs.org/package/grunt-static-inline) - A grunt plugin to replace url from static files such as img,js,css an put inline in a template. | ||
* [grunt-data-uri](https://npmjs.org/package/grunt-data-uri) - Convert to data-uri from image path. | ||
* [grunt-inline](https://npmjs.org/package/grunt-inline) | ||
DEVELOPING | ||
---------- | ||
```CLI | ||
@@ -212,14 +215,2 @@ $ npm install | ||
## Release notes | ||
* 1.0 - async by default, native promise, streams, split between datauri and datauri-cli package | ||
* 0.8 - remove node 0.8 support | ||
* 0.7 - generate css background-image instead of background shorthand | ||
* 0.6 - io.js support | ||
* 0.5 - Format data uri from a string | ||
* 0.4 - Promises support | ||
* 0.3 - API Rewritten from the top to the bottom + full async compatibility | ||
* 0.2 - Splitted in submodules mimer and templayed | ||
* 0.1 - First release | ||
## License | ||
@@ -229,6 +220,1 @@ | ||
(c) [Helder Santana](http://heldr.com) | ||
[nodejs]: http://nodejs.org/download | ||
[iojs]: https://iojs.org/ | ||
[datauri]: http://en.wikipedia.org/wiki/Data_URI_scheme | ||
[promisesaplus]: http://promises-aplus.github.io/promises-spec/ |
21343
211