Commit f064c792 authored by Muddsair Sharif's avatar Muddsair Sharif
Browse files

Initial commit

parents
Pipeline #8 canceled with stages
var Writer = require(__dirname + '/../');
module.exports = function() {
var writer = new Writer();
writer.addInt32(10);
writer.addInt16(5);
writer.addCString('test');
writer.flush('X');
};
if(!module.parent) {
module.exports();
console.log('benchmark ok');
}
//binary data writer tuned for creating
//postgres message packets as effeciently as possible by reusing the
//same buffer to avoid memcpy and limit memory allocations
var Writer = module.exports = function(size) {
this.size = size || 1024;
this.buffer = Buffer(this.size + 5);
this.offset = 5;
this.headerPosition = 0;
};
//resizes internal buffer if not enough size left
Writer.prototype._ensure = function(size) {
var remaining = this.buffer.length - this.offset;
if(remaining < size) {
var oldBuffer = this.buffer;
// exponential growth factor of around ~ 1.5
// https://stackoverflow.com/questions/2269063/buffer-growth-strategy
var newSize = oldBuffer.length + (oldBuffer.length >> 1) + size;
this.buffer = new Buffer(newSize);
oldBuffer.copy(this.buffer);
}
};
Writer.prototype.addInt32 = function(num) {
this._ensure(4);
this.buffer[this.offset++] = (num >>> 24 & 0xFF);
this.buffer[this.offset++] = (num >>> 16 & 0xFF);
this.buffer[this.offset++] = (num >>> 8 & 0xFF);
this.buffer[this.offset++] = (num >>> 0 & 0xFF);
return this;
};
Writer.prototype.addInt16 = function(num) {
this._ensure(2);
this.buffer[this.offset++] = (num >>> 8 & 0xFF);
this.buffer[this.offset++] = (num >>> 0 & 0xFF);
return this;
};
//for versions of node requiring 'length' as 3rd argument to buffer.write
var writeString = function(buffer, string, offset, len) {
buffer.write(string, offset, len);
};
//overwrite function for older versions of node
if(Buffer.prototype.write.length === 3) {
writeString = function(buffer, string, offset, len) {
buffer.write(string, offset);
};
}
Writer.prototype.addCString = function(string) {
//just write a 0 for empty or null strings
if(!string) {
this._ensure(1);
} else {
var len = Buffer.byteLength(string);
this._ensure(len + 1); //+1 for null terminator
writeString(this.buffer, string, this.offset, len);
this.offset += len;
}
this.buffer[this.offset++] = 0; // null terminator
return this;
};
Writer.prototype.addChar = function(c) {
this._ensure(1);
writeString(this.buffer, c, this.offset, 1);
this.offset++;
return this;
};
Writer.prototype.addString = function(string) {
string = string || "";
var len = Buffer.byteLength(string);
this._ensure(len);
this.buffer.write(string, this.offset);
this.offset += len;
return this;
};
Writer.prototype.getByteLength = function() {
return this.offset - 5;
};
Writer.prototype.add = function(otherBuffer) {
this._ensure(otherBuffer.length);
otherBuffer.copy(this.buffer, this.offset);
this.offset += otherBuffer.length;
return this;
};
Writer.prototype.clear = function() {
this.offset = 5;
this.headerPosition = 0;
this.lastEnd = 0;
};
//appends a header block to all the written data since the last
//subsequent header or to the beginning if there is only one data block
Writer.prototype.addHeader = function(code, last) {
var origOffset = this.offset;
this.offset = this.headerPosition;
this.buffer[this.offset++] = code;
//length is everything in this packet minus the code
this.addInt32(origOffset - (this.headerPosition+1));
//set next header position
this.headerPosition = origOffset;
//make space for next header
this.offset = origOffset;
if(!last) {
this._ensure(5);
this.offset += 5;
}
};
Writer.prototype.join = function(code) {
if(code) {
this.addHeader(code, true);
}
return this.buffer.slice(code ? 0 : 5, this.offset);
};
Writer.prototype.flush = function(code) {
var result = this.join(code);
this.clear();
return result;
};
{
"_args": [
[
{
"raw": "buffer-writer@1.0.1",
"scope": null,
"escapedName": "buffer-writer",
"name": "buffer-writer",
"rawSpec": "1.0.1",
"spec": "1.0.1",
"type": "version"
},
"C:\\Users\\Giuliano\\Desktop\\nasaproject\\node_modules\\pg"
]
],
"_from": "buffer-writer@1.0.1",
"_id": "buffer-writer@1.0.1",
"_inCache": true,
"_location": "/buffer-writer",
"_nodeVersion": "5.5.0",
"_npmOperationalInternal": {
"host": "packages-5-east.internal.npmjs.com",
"tmp": "tmp/buffer-writer-1.0.1.tgz_1455554615929_0.2564993395935744"
},
"_npmUser": {
"name": "brianc",
"email": "brian.m.carlson@gmail.com"
},
"_npmVersion": "3.3.12",
"_phantomChildren": {},
"_requested": {
"raw": "buffer-writer@1.0.1",
"scope": null,
"escapedName": "buffer-writer",
"name": "buffer-writer",
"rawSpec": "1.0.1",
"spec": "1.0.1",
"type": "version"
},
"_requiredBy": [
"/pg"
],
"_resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-1.0.1.tgz",
"_shasum": "22a936901e3029afcd7547eb4487ceb697a3bf08",
"_shrinkwrap": null,
"_spec": "buffer-writer@1.0.1",
"_where": "C:\\Users\\Giuliano\\Desktop\\nasaproject\\node_modules\\pg",
"author": {
"name": "Brian M. Carlson"
},
"bugs": {
"url": "https://github.com/brianc/node-buffer-writer/issues"
},
"dependencies": {},
"description": "a fast, efficient buffer writer",
"devDependencies": {
"async": "~0.2.6",
"bench": "~0.3.5",
"benchmark": "~1.0.0",
"cloned": "0.0.1",
"microtime": "~0.3.3",
"mocha": "~1.8.1",
"okay": "0.0.2",
"rmdir": "~1.0.0"
},
"directories": {},
"dist": {
"shasum": "22a936901e3029afcd7547eb4487ceb697a3bf08",
"tarball": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-1.0.1.tgz"
},
"gitHead": "d7c48cb142d87d76662954359bf1abcd25144329",
"homepage": "https://github.com/brianc/node-buffer-writer#readme",
"keywords": [
"buffer",
"writer",
"builder"
],
"license": "MIT",
"main": "index.js",
"maintainers": [
{
"name": "brianc",
"email": "brian.m.carlson@gmail.com"
}
],
"name": "buffer-writer",
"optionalDependencies": {},
"readme": "# buffer-writer\n\n[![Build Status](https://secure.travis-ci.org/brianc/node-buffer-writer.png?branch=master)](http://travis-ci.org/brianc/node-buffer-writer)\n\nFast & efficient buffer writer used to keep memory usage low by internally recycling a single large buffer.\n\nUsed as the binary protocol writer in [node-postgres](https://github.com/brianc/node-postgres)\n\nSince postgres requires big endian encoding, this only writes big endian numbers for now, but can & probably will easily be extended to write little endian as well.\n\nI'll admit this has a few postgres specific things I might need to take out in the future, such as `addHeader`\n\n## api\n\n`var writer = new (require('buffer-writer')());`\n\n### writer.addInt32(num)\n\nWrites a 4-byte big endian binary encoded number to the end of the buffer.\n\n### writer.addInt16(num)\n\nWrites a 2-byte big endian binary encoded number to the end of the buffer.\n\n### writer.addCString(string)\n\nWrites a string to the buffer `utf8` encoded and adds a null character (`\\0`) at the end.\n\n### var buffer = writer.addHeader(char)\n\nWrites the 5 byte PostgreSQL required header to the beginning of the buffer. (1 byte for character, 1 BE Int32 for length of the buffer)\n\n### var buffer = writer.join()\n\nCollects all data in the writer and joins it into a single, new buffer.\n\n### var buffer = writer.flush(char)\n\nWrites the 5 byte postgres required message header, collects all data in the writer and joins it into a single, new buffer, and then resets the writer.\n\n## thoughts\n\nThis is kind of node-postgres specific. If you're interested in using this for a more general purpose thing, lemme know.\nI would love to work with you on getting this more reusable for your needs.\n\n## license\n\nMIT\n",
"readmeFilename": "README.md",
"repository": {
"type": "git",
"url": "git://github.com/brianc/node-buffer-writer.git"
},
"scripts": {
"test": "mocha"
},
"version": "1.0.1"
}
var Writer = require(__dirname + "/../");
var assert = require('assert');
var util = require('util');
assert.equalBuffers = function(actual, expected) {
var spit = function(actual, expected) {
console.log("");
console.log("actual " + util.inspect(actual));
console.log("expect " + util.inspect(expected));
console.log("");
};
if(actual.length != expected.length) {
spit(actual, expected);
assert.equal(actual.length, expected.length);
}
for(var i = 0; i < actual.length; i++) {
if(actual[i] != expected[i]) {
spit(actual, expected);
}
assert.equal(actual[i],expected[i]);
}
};
suite('adding int32', function() {
var testAddingInt32 = function(int, expectedBuffer) {
test('writes ' + int, function() {
var subject = new Writer();
var result = subject.addInt32(int).join();
assert.equalBuffers(result, expectedBuffer);
});
};
testAddingInt32(0, [0, 0, 0, 0]);
testAddingInt32(1, [0, 0, 0, 1]);
testAddingInt32(256, [0, 0, 1, 0]);
test('writes largest int32', function() {
//todo need to find largest int32 when I have internet access
return false;
});
test('writing multiple int32s', function() {
var subject = new Writer();
var result = subject.addInt32(1).addInt32(10).addInt32(0).join();
assert.equalBuffers(result, [0, 0, 0, 1, 0, 0, 0, 0x0a, 0, 0, 0, 0]);
});
suite('having to resize the buffer', function() {
test('after resize correct result returned', function() {
var subject = new Writer(10);
subject.addInt32(1).addInt32(1).addInt32(1);
assert.equalBuffers(subject.join(), [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1]);
});
});
});
suite('int16', function() {
test('writes 0', function() {
var subject = new Writer();
var result = subject.addInt16(0).join();
assert.equalBuffers(result, [0,0]);
});
test('writes 400', function() {
var subject = new Writer();
var result = subject.addInt16(400).join();
assert.equalBuffers(result, [1, 0x90]);
});
test('writes many', function() {
var subject = new Writer();
var result = subject.addInt16(0).addInt16(1).addInt16(2).join();
assert.equalBuffers(result, [0, 0, 0, 1, 0, 2]);
});
test('resizes if internal buffer fills up', function() {
var subject = new Writer(3);
var result = subject.addInt16(2).addInt16(3).join();
assert.equalBuffers(result, [0, 2, 0, 3]);
});
});
suite('cString', function() {
test('writes empty cstring', function() {
var subject = new Writer();
var result = subject.addCString().join();
assert.equalBuffers(result, [0]);
});
test('writes two empty cstrings', function() {
var subject = new Writer();
var result = subject.addCString("").addCString("").join();
assert.equalBuffers(result, [0, 0]);
});
test('writes non-empty cstring', function() {
var subject = new Writer();
var result = subject.addCString("!!!").join();
assert.equalBuffers(result, [33, 33, 33, 0]);
});
test('resizes if reached end', function() {
var subject = new Writer(3);
var result = subject.addCString("!!!").join();
assert.equalBuffers(result, [33, 33, 33, 0]);
});
test('writes multiple cstrings', function() {
var subject = new Writer();
var result = subject.addCString("!").addCString("!").join();
assert.equalBuffers(result, [33, 0, 33, 0]);
});
});
test('writes char', function() {
var subject = new Writer(2);
var result = subject.addChar('a').addChar('b').addChar('c').join();
assert.equalBuffers(result, [0x61, 0x62, 0x63]);
});
test('gets correct byte length', function() {
var subject = new Writer(5);
assert.equal(subject.getByteLength(), 0);
subject.addInt32(0);
assert.equal(subject.getByteLength(), 4);
subject.addCString("!");
assert.equal(subject.getByteLength(), 6);
});
test('can add arbitrary buffer to the end', function() {
var subject = new Writer(4);
subject.addCString("!!!")
var result = subject.add(Buffer("@@@")).join();
assert.equalBuffers(result, [33, 33, 33, 0, 0x40, 0x40, 0x40]);
});
suite('can write normal string', function() {
var subject = new Writer(4);
var result = subject.addString("!").join();
assert.equalBuffers(result, [33]);
test('can write cString too', function() {
var result = subject.addCString("!").join();
assert.equalBuffers(result, [33, 33, 0]);
});
test('can resize', function() {
var result = subject.addString("!!").join();
assert.equalBuffers(result, [33, 33, 0, 33, 33]);
});
});
suite('clearing', function() {
var subject = new Writer();
subject.addCString("@!!#!#");
subject.addInt32(10401);
test('clears', function() {
subject.clear();
assert.equalBuffers(subject.join(), []);
});
test('writing more', function() {
var joinedResult = subject.addCString("!").addInt32(9).addInt16(2).join();
assert.equalBuffers(joinedResult, [33, 0, 0, 0, 0, 9, 0, 2]);
});
test('returns result', function() {
var flushedResult = subject.flush();
assert.equalBuffers(flushedResult, [33, 0, 0, 0, 0, 9, 0, 2])
});
test('clears the writer', function() {
assert.equalBuffers(subject.join(), [])
assert.equalBuffers(subject.flush(), [])
});
});
test("resizing to much larger", function() {
var subject = new Writer(2);
var string = "!!!!!!!!";
var result = subject.addCString(string).flush();
assert.equalBuffers(result, [33, 33, 33, 33, 33, 33, 33, 33, 0]);
});
suite("flush", function() {
test('added as a hex code to a full writer', function() {
var subject = new Writer(2);
var result = subject.addCString("!").flush(0x50);
assert.equalBuffers(result, [0x50, 0, 0, 0, 6, 33, 0]);
});
test('added as a hex code to a non-full writer', function() {
var subject = new Writer(10).addCString("!");
var joinedResult = subject.join(0x50);
var result = subject.flush(0x50);
assert.equalBuffers(result, [0x50, 0, 0, 0, 6, 33, 0]);
});
test('added as a hex code to a buffer which requires resizing', function() {
var result = new Writer(2).addCString("!!!!!!!!").flush(0x50);
assert.equalBuffers(result, [0x50, 0, 0, 0, 0x0D, 33, 33, 33, 33, 33, 33, 33, 33, 0]);
});
});
suite("header", function() {
test('adding two packets with headers', function() {
var subject = new Writer(10).addCString("!");
subject.addHeader(0x50);
subject.addCString("!!");
subject.addHeader(0x40);
subject.addCString("!");
var result = subject.flush(0x10);
assert.equalBuffers(result, [0x50, 0, 0, 0, 6, 33, 0, 0x40, 0, 0, 0, 7, 33, 33, 0, 0x10, 0, 0, 0, 6, 33, 0 ]);
});
});
2.4.0 / 2016-06-01
==================
* Add option "unitSeparator"
2.3.0 / 2016-02-15
==================
* Drop partial bytes on all parsed units
* Fix non-finite numbers to `.format` to return `null`
* Fix parsing byte string that looks like hex
* perf: hoist regular expressions
2.2.0 / 2015-11-13
==================
* add option "decimalPlaces"
* add option "fixedDecimals"
2.1.0 / 2015-05-21
==================
* add `.format` export
* add `.parse` export
2.0.2 / 2015-05-20
==================
* remove map recreation
* remove unnecessary object construction
2.0.1 / 2015-05-07
==================
* fix browserify require
* remove node.extend dependency
2.0.0 / 2015-04-12
==================
* add option "case"
* add option "thousandsSeparator"
* return "null" on invalid parse input
* support proper round-trip: bytes(bytes(num)) === num
* units no longer case sensitive when parsing
1.0.0 / 2014-05-05
==================
* add negative support. fixes #6
0.3.0 / 2014-03-19
==================
* added terabyte support
0.2.1 / 2013-04-01
==================
* add .component
0.2.0 / 2012-10-28
==================
* bytes(200).should.eql('200b')
0.1.0 / 2012-07-04
==================
* add bytes to string conversion [yields]
(The MIT License)
Copyright (c) 2012-2014 TJ Holowaychuk <tj@vision-media.ca>
Copyright (c) 2015 Jed Watson <jed.watson@me.com>
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.
# Bytes utility
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Build Status][travis-image]][travis-url]
Utility to parse a string bytes (ex: `1TB`) to bytes (`1099511627776`) and vice-versa.
## Usage
```js
var bytes = require('bytes');
```
#### bytes.format(number value, [options]): string|null
Format the given value in bytes into a string. If the value is negative, it is kept as such. If it is a float, it is
rounded.
**Arguments**
| Name | Type | Description |
|---------|--------|--------------------|
| value | `number` | Value in bytes |
| options | `Object` | Conversion options |
**Options**
| Property | Type | Description |
|-------------------|--------|-----------------------------------------------------------------------------------------|
| decimalPlaces | `number`&#124;`null` | Maximum number of decimal places to include in output. Default value to `2`. |
| fixedDecimals | `boolean`&#124;`null` | Whether to always display the maximum number of decimal places. Default value to `false` |
| thousandsSeparator | `string`&#124;`null` | Example of values: `' '`, `','` and `.`... Default value to `' '`. |
| unitSeparator | `string`&#124;`null` | Separator to use between number and unit. Default value to `''`. |
**Returns**
| Name | Type | Description |
|---------|-------------|-------------------------|
| results | `string`&#124;`null` | Return null upon error. String value otherwise. |
**Example**
```js
bytes(1024);
// output: '1kB'
bytes(1000);
// output: '1000B'
bytes(1000, {thousandsSeparator: ' '});
// output: '1 000B'
bytes(1024 * 1.7, {decimalPlaces: 0});
// output: '2kB'
bytes(1024, {unitSeparator: ' '});
// output: '1 kB'
```
#### bytes.parse(string value): number|null
Parse the string value into an integer in bytes. If no unit is given, it is assumed the value is in bytes.
Supported units and abbreviations are as follows and are case-insensitive:
* "b" for bytes
* "kb" for kilobytes
* "mb" for megabytes
* "gb" for gigabytes
* "tb" for terabytes
The units are in powers of two, not ten. This means 1kb = 1024b according to this parser.
**Arguments**
| Name | Type | Description |
|---------------|--------|--------------------|
| value | `string` | String to parse. |
**Returns**
| Name | Type | Description |
|---------|-------------|-------------------------|
| results | `number`&#124;`null` | Return null upon error. Value in bytes otherwise. |
**Example**
```js
bytes('1kB');
// output: 1024
bytes('1024');
// output: 1024
```
## Installation
```bash
npm install bytes --save
component install visionmedia/bytes.js
```
## License
[![npm](https://img.shields.io/npm/l/express.svg)](https://github.com/visionmedia/bytes.js/blob/master/LICENSE)
[downloads-image]: https://img.shields.io/npm/dm/bytes.svg
[downloads-url]: https://npmjs.org/package/bytes
[npm-image]: https://img.shields.io/npm/v/bytes.svg
[npm-url]: https://npmjs.org/package/bytes
[travis-image]: https://img.shields.io/travis/visionmedia/bytes.js/master.svg
[travis-url]: https://travis-ci.org/visionmedia/bytes.js
/*!
* bytes
* Copyright(c) 2012-2014 TJ Holowaychuk
* Copyright(c) 2015 Jed Watson
* MIT Licensed
*/
'use strict';
/**
* Module exports.
* @public
*/
module.exports = bytes;
module.exports.format = format;
module.exports.parse = parse;
/**
* Module variables.
* @private
*/
var formatThousandsRegExp = /\B(?=(\d{3})+(?!\d))/g;
var formatDecimalsRegExp = /(?:\.0*|(\.[^0]+)0+)$/;
var map = {
b: 1,
kb: 1 << 10,
mb: 1 << 20,
gb: 1 << 30,
tb: ((1 << 30) * 1024)
};
// TODO: use is-finite module?
var numberIsFinite = Number.isFinite || function (v) { return typeof v === 'number' && isFinite(v); };
var parseRegExp = /^((-|\+)?(\d+(?:\.\d+)?)) *(kb|mb|gb|tb)$/i;
/**
* Convert the given value in bytes into a string or parse to string to an integer in bytes.
*
* @param {string|number} value
* @param {{
* case: [string],
* decimalPlaces: [number]
* fixedDecimals: [boolean]
* thousandsSeparator: [string]
* unitSeparator: [string]
* }} [options] bytes options.
*
* @returns {string|number|null}
*/
function bytes(value, options) {
if (typeof value === 'string') {
return parse(value);
}
if (typeof value === 'number') {
return format(value, options);
}
return null;
}
/**
* Format the given value in bytes into a string.
*
* If the value is negative, it is kept as such. If it is a float,
* it is rounded.
*
* @param {number} value
* @param {object} [options]
* @param {number} [options.decimalPlaces=2]
* @param {number} [options.fixedDecimals=false]
* @param {string} [options.thousandsSeparator=]
* @param {string} [options.unitSeparator=]
*
* @returns {string|null}
* @public
*/
function format(value, options) {
if (!numberIsFinite(value)) {
return null;
}
var mag = Math.abs(value);
var thousandsSeparator = (options && options.thousandsSeparator) || '';
var unitSeparator = (options && options.unitSeparator) || '';
var decimalPlaces = (options && options.decimalPlaces !== undefined) ? options.decimalPlaces : 2;
var fixedDecimals = Boolean(options && options.fixedDecimals);
var unit = 'B';
if (mag >= map.tb) {
unit = 'TB';
} else if (mag >= map.gb) {
unit = 'GB';
} else if (mag >= map.mb) {
unit = 'MB';
} else if (mag >= map.kb) {
unit = 'kB';
}
var val = value / map[unit.toLowerCase()];
var str = val.toFixed(decimalPlaces);
if (!fixedDecimals) {
str = str.replace(formatDecimalsRegExp, '$1');
}
if (thousandsSeparator) {
str = str.replace(formatThousandsRegExp, thousandsSeparator);
}
return str + unitSeparator + unit;
}
/**
* Parse the string value into an integer in bytes.
*
* If no unit is given, it is assumed the value is in bytes.
*
* @param {number|string} val
*
* @returns {number|null}
* @public
*/
function parse(val) {
if (typeof val === 'number' && !isNaN(val)) {
return val;
}
if (typeof val !== 'string') {
return null;
}
// Test if the string passed is valid
var results = parseRegExp.exec(val);
var floatValue;
var unit = 'b';
if (!results) {
// Nothing could be extracted from the given string
floatValue = parseInt(val, 10);
unit = 'b'
} else {
// Retrieve the value and the unit
floatValue = parseFloat(results[1]);
unit = results[4].toLowerCase();
}
return Math.floor(map[unit] * floatValue);
}
{
"_args": [
[
{
"raw": "bytes@2.4.0",
"scope": null,
"escapedName": "bytes",
"name": "bytes",
"rawSpec": "2.4.0",
"spec": "2.4.0",
"type": "version"
},
"C:\\Users\\Giuliano\\Desktop\\nasaproject\\project2\\node_modules\\body-parser"
]
],
"_from": "bytes@2.4.0",
"_id": "bytes@2.4.0",
"_inCache": true,
"_location": "/bytes",
"_npmOperationalInternal": {
"host": "packages-16-east.internal.npmjs.com",
"tmp": "tmp/bytes-2.4.0.tgz_1464812473023_0.6271433881483972"
},
"_npmUser": {
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
"_npmVersion": "1.4.28",
"_phantomChildren": {},
"_requested": {
"raw": "bytes@2.4.0",
"scope": null,
"escapedName": "bytes",
"name": "bytes",
"rawSpec": "2.4.0",
"spec": "2.4.0",
"type": "version"
},
"_requiredBy": [
"/body-parser",
"/raw-body"
],
"_resolved": "https://registry.npmjs.org/bytes/-/bytes-2.4.0.tgz",
"_shasum": "7d97196f9d5baf7f6935e25985549edd2a6c2339",
"_shrinkwrap": null,
"_spec": "bytes@2.4.0",
"_where": "C:\\Users\\Giuliano\\Desktop\\nasaproject\\project2\\node_modules\\body-parser",
"author": {
"name": "TJ Holowaychuk",
"email": "tj@vision-media.ca",
"url": "http://tjholowaychuk.com"
},
"bugs": {
"url": "https://github.com/visionmedia/bytes.js/issues"
},
"component": {
"scripts": {
"bytes/index.js": "index.js"
}
},
"contributors": [
{
"name": "Jed Watson",
"email": "jed.watson@me.com"
},
{
"name": "Théo FIDRY",
"email": "theo.fidry@gmail.com"
}
],
"dependencies": {},
"description": "Utility to parse a string bytes to bytes and vice-versa",
"devDependencies": {
"mocha": "1.21.5"
},
"directories": {},
"dist": {
"shasum": "7d97196f9d5baf7f6935e25985549edd2a6c2339",
"tarball": "https://registry.npmjs.org/bytes/-/bytes-2.4.0.tgz"
},
"files": [
"History.md",
"LICENSE",
"Readme.md",
"index.js"
],
"gitHead": "2a598442bdfa796df8d01a96cc54495cda550e70",
"homepage": "https://github.com/visionmedia/bytes.js#readme",
"keywords": [
"byte",
"bytes",
"utility",
"parse",
"parser",
"convert",
"converter"
],
"license": "MIT",
"maintainers": [
{
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
{
"name": "tjholowaychuk",
"email": "tj@vision-media.ca"
}
],
"name": "bytes",
"optionalDependencies": {},
"readme": "# Bytes utility\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Build Status][travis-image]][travis-url]\n\nUtility to parse a string bytes (ex: `1TB`) to bytes (`1099511627776`) and vice-versa.\n\n## Usage\n\n```js\nvar bytes = require('bytes');\n```\n\n#### bytes.format(number value, [options]): string|null\n\nFormat the given value in bytes into a string. If the value is negative, it is kept as such. If it is a float, it is\n rounded.\n\n**Arguments**\n\n| Name | Type | Description |\n|---------|--------|--------------------|\n| value | `number` | Value in bytes |\n| options | `Object` | Conversion options |\n\n**Options**\n\n| Property | Type | Description |\n|-------------------|--------|-----------------------------------------------------------------------------------------|\n| decimalPlaces | `number`&#124;`null` | Maximum number of decimal places to include in output. Default value to `2`. |\n| fixedDecimals | `boolean`&#124;`null` | Whether to always display the maximum number of decimal places. Default value to `false` |\n| thousandsSeparator | `string`&#124;`null` | Example of values: `' '`, `','` and `.`... Default value to `' '`. |\n| unitSeparator | `string`&#124;`null` | Separator to use between number and unit. Default value to `''`. |\n\n**Returns**\n\n| Name | Type | Description |\n|---------|-------------|-------------------------|\n| results | `string`&#124;`null` | Return null upon error. String value otherwise. |\n\n**Example**\n\n```js\nbytes(1024);\n// output: '1kB'\n\nbytes(1000);\n// output: '1000B'\n\nbytes(1000, {thousandsSeparator: ' '});\n// output: '1 000B'\n\nbytes(1024 * 1.7, {decimalPlaces: 0});\n// output: '2kB'\n\nbytes(1024, {unitSeparator: ' '});\n// output: '1 kB'\n\n```\n\n#### bytes.parse(string value): number|null\n\nParse the string value into an integer in bytes. If no unit is given, it is assumed the value is in bytes.\n\nSupported units and abbreviations are as follows and are case-insensitive:\n\n * \"b\" for bytes\n * \"kb\" for kilobytes\n * \"mb\" for megabytes\n * \"gb\" for gigabytes\n * \"tb\" for terabytes\n\nThe units are in powers of two, not ten. This means 1kb = 1024b according to this parser.\n\n**Arguments**\n\n| Name | Type | Description |\n|---------------|--------|--------------------|\n| value | `string` | String to parse. |\n\n**Returns**\n\n| Name | Type | Description |\n|---------|-------------|-------------------------|\n| results | `number`&#124;`null` | Return null upon error. Value in bytes otherwise. |\n\n**Example**\n\n```js\nbytes('1kB');\n// output: 1024\n\nbytes('1024');\n// output: 1024\n```\n\n## Installation\n\n```bash\nnpm install bytes --save\ncomponent install visionmedia/bytes.js\n```\n\n## License \n\n[![npm](https://img.shields.io/npm/l/express.svg)](https://github.com/visionmedia/bytes.js/blob/master/LICENSE)\n\n[downloads-image]: https://img.shields.io/npm/dm/bytes.svg\n[downloads-url]: https://npmjs.org/package/bytes\n[npm-image]: https://img.shields.io/npm/v/bytes.svg\n[npm-url]: https://npmjs.org/package/bytes\n[travis-image]: https://img.shields.io/travis/visionmedia/bytes.js/master.svg\n[travis-url]: https://travis-ci.org/visionmedia/bytes.js\n",
"readmeFilename": "Readme.md",
"repository": {
"type": "git",
"url": "git+https://github.com/visionmedia/bytes.js.git"
},
"scripts": {
"test": "mocha --check-leaks --reporter spec"
},
"version": "2.4.0"
}
The MIT License (MIT)
Copyright (c) 2014-2017, Jon Schlinkert.
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.
\ No newline at end of file
# cache-base [![NPM version](https://img.shields.io/npm/v/cache-base.svg?style=flat)](https://www.npmjs.com/package/cache-base) [![NPM monthly downloads](https://img.shields.io/npm/dm/cache-base.svg?style=flat)](https://npmjs.org/package/cache-base) [![NPM total downloads](https://img.shields.io/npm/dt/cache-base.svg?style=flat)](https://npmjs.org/package/cache-base) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/cache-base.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/cache-base)
> Basic object cache with `get`, `set`, `del`, and `has` methods for node.js/javascript projects.
## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install --save cache-base
```
## Usage
```js
var Cache = require('cache-base');
// instantiate
var app = new Cache();
// set values
app.set('a', 'b');
app.set('c.d', 'e');
// get values
app.get('a');
//=> 'b'
app.get('c');
//=> {d: 'e'}
console.log(app.cache);
//=> {a: 'b'}
```
**Inherit**
```js
var util = require('util');
var Cache = require('cache-base');
function MyApp() {
Cache.call(this);
}
util.inherits(MyApp, Cache);
var app = new MyApp();
app.set('a', 'b');
app.get('a');
//=> 'b'
```
**Namespace**
Define a custom property for storing values.
```js
var Cache = require('cache-base').namespace('data');
var app = new Cache();
app.set('a', 'b');
console.log(app.data);
//=> {a: 'b'}
```
## API
### [namespace](index.js#L29)
Create a `Cache` constructor that when instantiated will store values on the given `prop`.
**Params**
* `prop` **{String}**: The property name to use for storing values.
* `returns` **{Function}**: Returns a custom `Cache` constructor
**Example**
```js
var Cache = require('cache-base').namespace('data');
var cache = new Cache();
cache.set('foo', 'bar');
//=> {data: {foo: 'bar'}}
```
### [Cache](index.js#L43)
Create a new `Cache`. Internally the `Cache` constructor is created using the `namespace` function, with `cache` defined as the storage object.
**Params**
* `cache` **{Object}**: Optionally pass an object to initialize with.
**Example**
```js
var app = new Cache();
```
### [.set](index.js#L84)
Assign `value` to `key`. Also emits `set` with the key and value.
**Params**
* `key` **{String}**
* `value` **{any}**
* `returns` **{Object}**: Returns the instance for chaining.
**Events**
* `emits`: `set` with `key` and `value` as arguments.
**Example**
```js
app.on('set', function(key, val) {
// do something when `set` is emitted
});
app.set(key, value);
// also takes an object or array
app.set({name: 'Halle'});
app.set([{foo: 'bar'}, {baz: 'quux'}]);
console.log(app);
//=> {name: 'Halle', foo: 'bar', baz: 'quux'}
```
### [.union](index.js#L114)
Union `array` to `key`. Also emits `set` with the key and value.
**Params**
* `key` **{String}**
* `value` **{any}**
* `returns` **{Object}**: Returns the instance for chaining.
**Example**
```js
app.union('a.b', ['foo']);
app.union('a.b', ['bar']);
console.log(app.get('a'));
//=> {b: ['foo', 'bar']}
```
### [.get](index.js#L144)
Return the value of `key`. Dot notation may be used to get [nested property values](https://github.com/jonschlinkert/get-value).
**Params**
* `key` **{String}**: The name of the property to get. Dot-notation may be used.
* `returns` **{any}**: Returns the value of `key`
**Events**
* `emits`: `get` with `key` and `value` as arguments.
**Example**
```js
app.set('a.b.c', 'd');
app.get('a.b');
//=> {c: 'd'}
app.get(['a', 'b']);
//=> {c: 'd'}
```
### [.has](index.js#L171)
Return true if app has a stored value for `key`, false only if value is `undefined`.
**Params**
* `key` **{String}**
* `returns` **{Boolean}**
**Events**
* `emits`: `has` with `key` and true or false as arguments.
**Example**
```js
app.set('foo', 'bar');
app.has('foo');
//=> true
```
### [.del](index.js#L199)
Delete one or more properties from the instance.
**Params**
* `key` **{String|Array}**: Property name or array of property names.
* `returns` **{Object}**: Returns the instance for chaining.
**Events**
* `emits`: `del` with the `key` as the only argument.
**Example**
```js
app.del(); // delete all
// or
app.del('foo');
// or
app.del(['foo', 'bar']);
```
### [.clear](index.js#L218)
Reset the entire cache to an empty object.
**Example**
```js
app.clear();
```
### [.visit](index.js#L235)
Visit `method` over the properties in the given object, or map
visit over the object-elements in an array.
**Params**
* `method` **{String}**: The name of the `base` method to call.
* `val` **{Object|Array}**: The object or array to iterate over.
* `returns` **{Object}**: Returns the instance for chaining.
## About
### Related projects
* [base-methods](https://www.npmjs.com/package/base-methods): base-methods is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… [more](https://github.com/jonschlinkert/base-methods) | [homepage](https://github.com/jonschlinkert/base-methods "base-methods is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting with a handful of common methods, like `set`, `get`, `del` and `use`.")
* [get-value](https://www.npmjs.com/package/get-value): Use property paths (`a.b.c`) to get a nested value from an object. | [homepage](https://github.com/jonschlinkert/get-value "Use property paths (`a.b.c`) to get a nested value from an object.")
* [has-value](https://www.npmjs.com/package/has-value): Returns true if a value exists, false if empty. Works with deeply nested values using… [more](https://github.com/jonschlinkert/has-value) | [homepage](https://github.com/jonschlinkert/has-value "Returns true if a value exists, false if empty. Works with deeply nested values using object paths.")
* [option-cache](https://www.npmjs.com/package/option-cache): Simple API for managing options in JavaScript applications. | [homepage](https://github.com/jonschlinkert/option-cache "Simple API for managing options in JavaScript applications.")
* [set-value](https://www.npmjs.com/package/set-value): Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths. | [homepage](https://github.com/jonschlinkert/set-value "Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths.")
* [unset-value](https://www.npmjs.com/package/unset-value): Delete nested properties from an object using dot notation. | [homepage](https://github.com/jonschlinkert/unset-value "Delete nested properties from an object using dot notation.")
### Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
### Contributors
| **Commits** | **Contributor** |
| --- | --- |
| 54 | [jonschlinkert](https://github.com/jonschlinkert) |
| 2 | [wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg) |
### Building docs
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
To generate the readme, run the following command:
```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```
### Running tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
```sh
$ npm install && npm test
```
### Author
**Jon Schlinkert**
* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
### License
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).
***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on July 22, 2017._
\ No newline at end of file
'use strict';
var isObject = require('isobject');
var Emitter = require('component-emitter');
var visit = require('collection-visit');
var toPath = require('to-object-path');
var union = require('union-value');
var del = require('unset-value');
var get = require('get-value');
var has = require('has-value');
var set = require('set-value');
/**
* Create a `Cache` constructor that when instantiated will
* store values on the given `prop`.
*
* ```js
* var Cache = require('cache-base').namespace('data');
* var cache = new Cache();
*
* cache.set('foo', 'bar');
* //=> {data: {foo: 'bar'}}
* ```
* @param {String} `prop` The property name to use for storing values.
* @return {Function} Returns a custom `Cache` constructor
* @api public
*/
function namespace(prop) {
/**
* Create a new `Cache`. Internally the `Cache` constructor is created using
* the `namespace` function, with `cache` defined as the storage object.
*
* ```js
* var app = new Cache();
* ```
* @param {Object} `cache` Optionally pass an object to initialize with.
* @constructor
* @api public
*/
function Cache(cache) {
if (prop) {
this[prop] = {};
}
if (cache) {
this.set(cache);
}
}
/**
* Inherit Emitter
*/
Emitter(Cache.prototype);
/**
* Assign `value` to `key`. Also emits `set` with
* the key and value.
*
* ```js
* app.on('set', function(key, val) {
* // do something when `set` is emitted
* });
*
* app.set(key, value);
*
* // also takes an object or array
* app.set({name: 'Halle'});
* app.set([{foo: 'bar'}, {baz: 'quux'}]);
* console.log(app);
* //=> {name: 'Halle', foo: 'bar', baz: 'quux'}
* ```
*
* @name .set
* @emits `set` with `key` and `value` as arguments.
* @param {String} `key`
* @param {any} `value`
* @return {Object} Returns the instance for chaining.
* @api public
*/
Cache.prototype.set = function(key, val) {
if (Array.isArray(key) && arguments.length === 2) {
key = toPath(key);
}
if (isObject(key) || Array.isArray(key)) {
this.visit('set', key);
} else {
set(prop ? this[prop] : this, key, val);
this.emit('set', key, val);
}
return this;
};
/**
* Union `array` to `key`. Also emits `set` with
* the key and value.
*
* ```js
* app.union('a.b', ['foo']);
* app.union('a.b', ['bar']);
* console.log(app.get('a'));
* //=> {b: ['foo', 'bar']}
* ```
* @name .union
* @param {String} `key`
* @param {any} `value`
* @return {Object} Returns the instance for chaining.
* @api public
*/
Cache.prototype.union = function(key, val) {
if (Array.isArray(key) && arguments.length === 2) {
key = toPath(key);
}
var ctx = prop ? this[prop] : this;
union(ctx, key, arrayify(val));
this.emit('union', val);
return this;
};
/**
* Return the value of `key`. Dot notation may be used
* to get [nested property values][get-value].
*
* ```js
* app.set('a.b.c', 'd');
* app.get('a.b');
* //=> {c: 'd'}
*
* app.get(['a', 'b']);
* //=> {c: 'd'}
* ```
*
* @name .get
* @emits `get` with `key` and `value` as arguments.
* @param {String} `key` The name of the property to get. Dot-notation may be used.
* @return {any} Returns the value of `key`
* @api public
*/
Cache.prototype.get = function(key) {
key = toPath(arguments);
var ctx = prop ? this[prop] : this;
var val = get(ctx, key);
this.emit('get', key, val);
return val;
};
/**
* Return true if app has a stored value for `key`,
* false only if value is `undefined`.
*
* ```js
* app.set('foo', 'bar');
* app.has('foo');
* //=> true
* ```
*
* @name .has
* @emits `has` with `key` and true or false as arguments.
* @param {String} `key`
* @return {Boolean}
* @api public
*/
Cache.prototype.has = function(key) {
key = toPath(arguments);
var ctx = prop ? this[prop] : this;
var val = get(ctx, key);
var has = typeof val !== 'undefined';
this.emit('has', key, has);
return has;
};
/**
* Delete one or more properties from the instance.
*
* ```js
* app.del(); // delete all
* // or
* app.del('foo');
* // or
* app.del(['foo', 'bar']);
* ```
* @name .del
* @emits `del` with the `key` as the only argument.
* @param {String|Array} `key` Property name or array of property names.
* @return {Object} Returns the instance for chaining.
* @api public
*/
Cache.prototype.del = function(key) {
if (Array.isArray(key)) {
this.visit('del', key);
} else {
del(prop ? this[prop] : this, key);
this.emit('del', key);
}
return this;
};
/**
* Reset the entire cache to an empty object.
*
* ```js
* app.clear();
* ```
* @api public
*/
Cache.prototype.clear = function() {
if (prop) {
this[prop] = {};
}
};
/**
* Visit `method` over the properties in the given object, or map
* visit over the object-elements in an array.
*
* @name .visit
* @param {String} `method` The name of the `base` method to call.
* @param {Object|Array} `val` The object or array to iterate over.
* @return {Object} Returns the instance for chaining.
* @api public
*/
Cache.prototype.visit = function(method, val) {
visit(this, method, val);
return this;
};
return Cache;
}
/**
* Cast val to an array
*/
function arrayify(val) {
return val ? (Array.isArray(val) ? val : [val]) : [];
}
/**
* Expose `Cache`
*/
module.exports = namespace();
/**
* Expose `Cache.namespace`
*/
module.exports.namespace = namespace;
{
"_from": "cache-base@^1.0.1",
"_id": "cache-base@1.0.1",
"_inBundle": false,
"_integrity": "sha512-AKcdTnFSWATd5/GCPRxr2ChwIJ85CeyrEyjRHlKxQ56d4XJMGym0uAiKn0xbLOGOl3+yRpOTi484dVCEc5AUzQ==",
"_location": "/cache-base",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "cache-base@^1.0.1",
"name": "cache-base",
"escapedName": "cache-base",
"rawSpec": "^1.0.1",
"saveSpec": null,
"fetchSpec": "^1.0.1"
},
"_requiredBy": [
"/base"
],
"_resolved": "https://registry.npmjs.org/cache-base/-/cache-base-1.0.1.tgz",
"_shasum": "0a7f46416831c8b662ee36fe4e7c59d76f666ab2",
"_spec": "cache-base@^1.0.1",
"_where": "/Users/Chorthip/Documents/GitKraken/nasaproject/node_modules/base",
"author": {
"name": "Jon Schlinkert",
"url": "https://github.com/jonschlinkert"
},
"bugs": {
"url": "https://github.com/jonschlinkert/cache-base/issues"
},
"bundleDependencies": false,
"contributors": [
{
"name": "Jon Schlinkert",
"url": "http://twitter.com/jonschlinkert"
},
{
"url": "https://github.com/wtgtybhertgeghgtwtg"
}
],
"dependencies": {
"collection-visit": "^1.0.0",
"component-emitter": "^1.2.1",
"get-value": "^2.0.6",
"has-value": "^1.0.0",
"isobject": "^3.0.1",
"set-value": "^2.0.0",
"to-object-path": "^0.3.0",
"union-value": "^1.0.0",
"unset-value": "^1.0.0"
},
"deprecated": false,
"description": "Basic object cache with `get`, `set`, `del`, and `has` methods for node.js/javascript projects.",
"devDependencies": {
"gulp-format-md": "^1.0.0",
"mocha": "^3.4.2"
},
"engines": {
"node": ">=0.10.0"
},
"files": [
"index.js"
],
"homepage": "https://github.com/jonschlinkert/cache-base",
"keywords": [
"base",
"cache",
"config",
"data",
"get",
"has",
"hash",
"hasown",
"object",
"set",
"store"
],
"license": "MIT",
"main": "index.js",
"name": "cache-base",
"repository": {
"type": "git",
"url": "git+https://github.com/jonschlinkert/cache-base.git"
},
"scripts": {
"test": "mocha"
},
"verb": {
"run": true,
"toc": false,
"layout": "default",
"tasks": [
"readme"
],
"plugins": [
"gulp-format-md"
],
"related": {
"highligh": "base",
"list": [
"base-methods",
"get-value",
"has-value",
"option-cache",
"set-value",
"unset-value"
]
},
"reflinks": [
"verb"
],
"lint": {
"reflinks": true
}
},
"version": "1.0.1"
}
'use strict';
function preserveCamelCase(str) {
let isLastCharLower = false;
let isLastCharUpper = false;
let isLastLastCharUpper = false;
for (let i = 0; i < str.length; i++) {
const c = str[i];
if (isLastCharLower && /[a-zA-Z]/.test(c) && c.toUpperCase() === c) {
str = str.substr(0, i) + '-' + str.substr(i);
isLastCharLower = false;
isLastLastCharUpper = isLastCharUpper;
isLastCharUpper = true;
i++;
} else if (isLastCharUpper && isLastLastCharUpper && /[a-zA-Z]/.test(c) && c.toLowerCase() === c) {
str = str.substr(0, i - 1) + '-' + str.substr(i - 1);
isLastLastCharUpper = isLastCharUpper;
isLastCharUpper = false;
isLastCharLower = true;
} else {
isLastCharLower = c.toLowerCase() === c;
isLastLastCharUpper = isLastCharUpper;
isLastCharUpper = c.toUpperCase() === c;
}
}
return str;
}
module.exports = function (str) {
if (arguments.length > 1) {
str = Array.from(arguments)
.map(x => x.trim())
.filter(x => x.length)
.join('-');
} else {
str = str.trim();
}
if (str.length === 0) {
return '';
}
if (str.length === 1) {
return str.toLowerCase();
}
if (/^[a-z0-9]+$/.test(str)) {
return str;
}
const hasUpperCase = str !== str.toLowerCase();
if (hasUpperCase) {
str = preserveCamelCase(str);
}
return str
.replace(/^[_.\- ]+/, '')
.toLowerCase()
.replace(/[_.\- ]+(\w|$)/g, (m, p1) => p1.toUpperCase());
};
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
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.
{
"_from": "camelcase@^4.0.0",
"_id": "camelcase@4.1.0",
"_inBundle": false,
"_integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=",
"_location": "/camelcase",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "camelcase@^4.0.0",
"name": "camelcase",
"escapedName": "camelcase",
"rawSpec": "^4.0.0",
"saveSpec": null,
"fetchSpec": "^4.0.0"
},
"_requiredBy": [
"/boxen"
],
"_resolved": "https://registry.npmjs.org/camelcase/-/camelcase-4.1.0.tgz",
"_shasum": "d545635be1e33c542649c69173e5de6acfae34dd",
"_spec": "camelcase@^4.0.0",
"_where": "/Users/Chorthip/Documents/GitKraken/nasaproject/node_modules/boxen",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"bugs": {
"url": "https://github.com/sindresorhus/camelcase/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Convert a dash/dot/underscore/space separated string to camelCase: foo-bar → fooBar",
"devDependencies": {
"ava": "*",
"xo": "*"
},
"engines": {
"node": ">=4"
},
"files": [
"index.js"
],
"homepage": "https://github.com/sindresorhus/camelcase#readme",
"keywords": [
"camelcase",
"camel-case",
"camel",
"case",
"dash",
"hyphen",
"dot",
"underscore",
"separator",
"string",
"text",
"convert"
],
"license": "MIT",
"name": "camelcase",
"repository": {
"type": "git",
"url": "git+https://github.com/sindresorhus/camelcase.git"
},
"scripts": {
"test": "xo && ava"
},
"version": "4.1.0",
"xo": {
"esnext": true
}
}
# camelcase [![Build Status](https://travis-ci.org/sindresorhus/camelcase.svg?branch=master)](https://travis-ci.org/sindresorhus/camelcase)
> Convert a dash/dot/underscore/space separated string to camelCase: `foo-bar` → `fooBar`
## Install
```
$ npm install --save camelcase
```
## Usage
```js
const camelCase = require('camelcase');
camelCase('foo-bar');
//=> 'fooBar'
camelCase('foo_bar');
//=> 'fooBar'
camelCase('Foo-Bar');
//=> 'fooBar'
camelCase('--foo.bar');
//=> 'fooBar'
camelCase('__foo__bar__');
//=> 'fooBar'
camelCase('foo bar');
//=> 'fooBar'
console.log(process.argv[3]);
//=> '--foo-bar'
camelCase(process.argv[3]);
//=> 'fooBar'
camelCase('foo', 'bar');
//=> 'fooBar'
camelCase('__foo__', '--bar');
//=> 'fooBar'
```
## Related
- [decamelize](https://github.com/sindresorhus/decamelize) - The inverse of this module
- [uppercamelcase](https://github.com/SamVerschueren/uppercamelcase) - Like this module, but to PascalCase instead of camelCase
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)
'use strict';
module.exports = Error.captureStackTrace || function (error) {
var container = new Error();
Object.defineProperty(error, 'stack', {
configurable: true,
get: function getStack() {
var stack = container.stack;
Object.defineProperty(this, 'stack', {
value: stack
});
return stack;
}
});
};
{
"_from": "capture-stack-trace@^1.0.0",
"_id": "capture-stack-trace@1.0.0",
"_inBundle": false,
"_integrity": "sha1-Sm+gc5nCa7pH8LJJa00PtAjFVQ0=",
"_location": "/capture-stack-trace",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "capture-stack-trace@^1.0.0",
"name": "capture-stack-trace",
"escapedName": "capture-stack-trace",
"rawSpec": "^1.0.0",
"saveSpec": null,
"fetchSpec": "^1.0.0"
},
"_requiredBy": [
"/create-error-class"
],
"_resolved": "https://registry.npmjs.org/capture-stack-trace/-/capture-stack-trace-1.0.0.tgz",
"_shasum": "4a6fa07399c26bba47f0b2496b4d0fb408c5550d",
"_spec": "capture-stack-trace@^1.0.0",
"_where": "/Users/Chorthip/Documents/GitKraken/nasaproject/node_modules/create-error-class",
"author": {
"name": "Vsevolod Strukchinsky",
"email": "floatdrop@gmail.com",
"url": "github.com/floatdrop"
},
"bugs": {
"url": "https://github.com/floatdrop/capture-stack-trace/issues"
},
"bundleDependencies": false,
"dependencies": {},
"deprecated": false,
"description": "Error.captureStackTrace ponyfill",
"devDependencies": {
"mocha": "*"
},
"engines": {
"node": ">=0.10.0"
},
"files": [
"index.js"
],
"homepage": "https://github.com/floatdrop/capture-stack-trace#readme",
"keywords": [
"Error",
"captureStackTrace"
],
"license": "MIT",
"name": "capture-stack-trace",
"repository": {
"type": "git",
"url": "git+https://github.com/floatdrop/capture-stack-trace.git"
},
"scripts": {
"test": "mocha"
},
"version": "1.0.0"
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment