aboutsummaryrefslogtreecommitdiff
path: root/node_modules/to-buffer
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/to-buffer')
-rw-r--r--node_modules/to-buffer/.travis.yml9
-rw-r--r--node_modules/to-buffer/LICENSE21
-rw-r--r--node_modules/to-buffer/README.md23
-rw-r--r--node_modules/to-buffer/index.js14
-rw-r--r--node_modules/to-buffer/package.json24
-rw-r--r--node_modules/to-buffer/test.js26
6 files changed, 117 insertions, 0 deletions
diff --git a/node_modules/to-buffer/.travis.yml b/node_modules/to-buffer/.travis.yml
new file mode 100644
index 0000000..ac46872
--- /dev/null
+++ b/node_modules/to-buffer/.travis.yml
@@ -0,0 +1,9 @@
+sudo: false
+
+language: node_js
+
+node_js:
+ - "5"
+ - "4"
+ - "0.12"
+ - "0.10"
diff --git a/node_modules/to-buffer/LICENSE b/node_modules/to-buffer/LICENSE
new file mode 100644
index 0000000..bae9da7
--- /dev/null
+++ b/node_modules/to-buffer/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2016 Mathias Buus
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/node_modules/to-buffer/README.md b/node_modules/to-buffer/README.md
new file mode 100644
index 0000000..fe334a4
--- /dev/null
+++ b/node_modules/to-buffer/README.md
@@ -0,0 +1,23 @@
+# to-buffer
+
+Pass in a string, get a buffer back. Pass in a buffer, get the same buffer back.
+
+```
+npm install to-buffer
+```
+
+[![build status](https://travis-ci.org/mafintosh/to-buffer.svg?branch=master)](https://travis-ci.org/mafintosh/to-buffer)
+
+## Usage
+
+``` js
+var toBuffer = require('to-buffer')
+console.log(toBuffer('hi')) // <Buffer 68 69>
+console.log(toBuffer(Buffer('hi'))) // <Buffer 68 69>
+console.log(toBuffer('6869', 'hex')) // <Buffer 68 69>
+console.log(toBuffer(43)) // throws
+```
+
+## License
+
+MIT
diff --git a/node_modules/to-buffer/index.js b/node_modules/to-buffer/index.js
new file mode 100644
index 0000000..9bd4978
--- /dev/null
+++ b/node_modules/to-buffer/index.js
@@ -0,0 +1,14 @@
+module.exports = toBuffer
+
+var makeBuffer = Buffer.from && Buffer.from !== Uint8Array.from ? Buffer.from : bufferFrom
+
+function bufferFrom (buf, enc) {
+ return new Buffer(buf, enc)
+}
+
+function toBuffer (buf, enc) {
+ if (Buffer.isBuffer(buf)) return buf
+ if (typeof buf === 'string') return makeBuffer(buf, enc)
+ if (Array.isArray(buf)) return makeBuffer(buf)
+ throw new Error('Input should be a buffer or a string')
+}
diff --git a/node_modules/to-buffer/package.json b/node_modules/to-buffer/package.json
new file mode 100644
index 0000000..fdc9c61
--- /dev/null
+++ b/node_modules/to-buffer/package.json
@@ -0,0 +1,24 @@
+{
+ "name": "to-buffer",
+ "version": "1.1.1",
+ "description": "Pass in a string, get a buffer back. Pass in a buffer, get the same buffer back",
+ "main": "index.js",
+ "dependencies": {},
+ "devDependencies": {
+ "standard": "^6.0.5",
+ "tape": "^4.4.0"
+ },
+ "scripts": {
+ "test": "standard && tape test.js"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/mafintosh/to-buffer.git"
+ },
+ "author": "Mathias Buus (@mafintosh)",
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/mafintosh/to-buffer/issues"
+ },
+ "homepage": "https://github.com/mafintosh/to-buffer"
+}
diff --git a/node_modules/to-buffer/test.js b/node_modules/to-buffer/test.js
new file mode 100644
index 0000000..f5e97d6
--- /dev/null
+++ b/node_modules/to-buffer/test.js
@@ -0,0 +1,26 @@
+var tape = require('tape')
+var toBuffer = require('./')
+
+tape('buffer returns buffer', function (t) {
+ t.same(toBuffer(Buffer('hi')), Buffer('hi'))
+ t.end()
+})
+
+tape('string returns buffer', function (t) {
+ t.same(toBuffer('hi'), Buffer('hi'))
+ t.end()
+})
+
+tape('string + enc returns buffer', function (t) {
+ t.same(toBuffer('6869', 'hex'), Buffer('hi'))
+ t.end()
+})
+
+tape('other input throws', function (t) {
+ try {
+ toBuffer(42)
+ } catch (err) {
+ t.same(err.message, 'Input should be a buffer or a string')
+ t.end()
+ }
+})