Welis Garagen-Anzeige
This commit is contained in:
+2
@@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
.DS_Store
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
Copyright (c) MMXIV jden <jason@denizac.org>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
# parse-data-uri
|
||||
parse a data uri into mime type and buffer
|
||||
|
||||
## usage
|
||||
```js
|
||||
var parseDataUri = require('parse-data-uri')
|
||||
|
||||
var dataUri = 'data:image/jpeg;base64,23423423...'
|
||||
|
||||
var parsed = parseDataUri(dataUri)
|
||||
|
||||
console.log(parsed)
|
||||
// {
|
||||
// mimeType: 'image/jpeg',
|
||||
// data: Buffer < 00 00 00 ... >
|
||||
// }
|
||||
|
||||
```
|
||||
|
||||
|
||||
## api
|
||||
###`parseDataUri : ( dataUri: String ) => {mimeType: String, data: Buffer}`
|
||||
|
||||
## installation
|
||||
|
||||
$ npm install parse-data-uri
|
||||
|
||||
|
||||
## running the tests
|
||||
|
||||
From package root:
|
||||
|
||||
$ npm install
|
||||
$ npm test
|
||||
|
||||
|
||||
Special thanks to @tootallnate for writing [data-uri-to-buffer](https://npm.im/data-uri-to-buffer)
|
||||
|
||||
## contributors
|
||||
|
||||
- jden <jason@denizac.org>
|
||||
|
||||
|
||||
## license
|
||||
|
||||
ISC. (c) MMXIV jden <jason@denizac.org>. See LICENSE.md
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
var toBuffer = require('data-uri-to-buffer')
|
||||
|
||||
function parseDataUri (dataUri) {
|
||||
|
||||
return {
|
||||
mimeType: normalizeMimeType(parseMimeType(dataUri)),
|
||||
data: toBuffer(dataUri)
|
||||
}
|
||||
}
|
||||
|
||||
function parseMimeType(uri) {
|
||||
return uri.substring(5, uri.indexOf(';'))
|
||||
}
|
||||
|
||||
var prefix = /^(\w+\/)+/
|
||||
function normalizeMimeType(mime) {
|
||||
mime = mime.toLowerCase()
|
||||
var once = mime.match(prefix)
|
||||
if (!once || !(once = once[1])) {
|
||||
return mime
|
||||
}
|
||||
return mime.replace(prefix, once)
|
||||
|
||||
}
|
||||
|
||||
module.exports = parseDataUri
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"raw": "parse-data-uri@^0.2.0",
|
||||
"scope": null,
|
||||
"escapedName": "parse-data-uri",
|
||||
"name": "parse-data-uri",
|
||||
"rawSpec": "^0.2.0",
|
||||
"spec": ">=0.2.0 <0.3.0",
|
||||
"type": "range"
|
||||
},
|
||||
"/Users/gerrit/Documents/node.js-Projects/tinkerforge/node_modules/get-pixels"
|
||||
]
|
||||
],
|
||||
"_from": "parse-data-uri@>=0.2.0 <0.3.0",
|
||||
"_id": "parse-data-uri@0.2.0",
|
||||
"_inCache": true,
|
||||
"_location": "/parse-data-uri",
|
||||
"_npmUser": {
|
||||
"name": "jden",
|
||||
"email": "jason@denizac.org"
|
||||
},
|
||||
"_npmVersion": "1.4.3",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"raw": "parse-data-uri@^0.2.0",
|
||||
"scope": null,
|
||||
"escapedName": "parse-data-uri",
|
||||
"name": "parse-data-uri",
|
||||
"rawSpec": "^0.2.0",
|
||||
"spec": ">=0.2.0 <0.3.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/get-pixels"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/parse-data-uri/-/parse-data-uri-0.2.0.tgz",
|
||||
"_shasum": "bf04d851dd5c87b0ab238e5d01ace494b604b4c9",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "parse-data-uri@^0.2.0",
|
||||
"_where": "/Users/gerrit/Documents/node.js-Projects/tinkerforge/node_modules/get-pixels",
|
||||
"author": {
|
||||
"name": "jden",
|
||||
"email": "jason@denizac.org"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/jden/node-parse-data-uri/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"data-uri-to-buffer": "0.0.3"
|
||||
},
|
||||
"description": "parse a data uri into mime type and buffer",
|
||||
"devDependencies": {
|
||||
"mochi": "0.1.0"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "bf04d851dd5c87b0ab238e5d01ace494b604b4c9",
|
||||
"tarball": "https://registry.npmjs.org/parse-data-uri/-/parse-data-uri-0.2.0.tgz"
|
||||
},
|
||||
"homepage": "https://github.com/jden/node-parse-data-uri",
|
||||
"keywords": [
|
||||
"mime",
|
||||
"data uri",
|
||||
"datauri"
|
||||
],
|
||||
"license": "ISC",
|
||||
"main": "index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "jden",
|
||||
"email": "jason@denizac.org"
|
||||
}
|
||||
],
|
||||
"name": "parse-data-uri",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/jden/node-parse-data-uri.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha"
|
||||
},
|
||||
"version": "0.2.0"
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
var mochi = require('mochi')
|
||||
var test = require('fs').readFileSync(__dirname + '/test.datauri').toString()
|
||||
|
||||
|
||||
describe('parse-data-uri', function () {
|
||||
var parseDataUri = require('../')
|
||||
|
||||
it('works with crazy messed up mime types', function () {
|
||||
var t = test.replace('image/gif','image/image/gif')
|
||||
// this is a test case i've seen from some datauris in the wild
|
||||
parseDataUri(t).mimeType
|
||||
.should.equal('image/gif')
|
||||
})
|
||||
|
||||
it('returns an object', function () {
|
||||
|
||||
parseDataUri(test)
|
||||
.should.have.keys(['mimeType', 'data'])
|
||||
|
||||
})
|
||||
|
||||
it('parses mime type', function () {
|
||||
|
||||
parseDataUri(test).mimeType
|
||||
.should.equal('image/gif')
|
||||
|
||||
})
|
||||
|
||||
it('decodes the buffer', function () {
|
||||
|
||||
parseDataUri(test).data.constructor
|
||||
.should.equal(Buffer)
|
||||
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user