Initial commit
This commit is contained in:
14
node_modules/left-pad/COPYING
generated
vendored
Normal file
14
node_modules/left-pad/COPYING
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
Version 2, December 2004
|
||||
|
||||
Copyright (C) 2014 Azer Koçulu <azer@roadbeats.com>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified
|
||||
copies of this license document, and changing it is allowed as long
|
||||
as the name is changed.
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
||||
|
||||
52
node_modules/left-pad/index.js
generated
vendored
Normal file
52
node_modules/left-pad/index.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
/* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details. */
|
||||
'use strict';
|
||||
module.exports = leftPad;
|
||||
|
||||
var cache = [
|
||||
'',
|
||||
' ',
|
||||
' ',
|
||||
' ',
|
||||
' ',
|
||||
' ',
|
||||
' ',
|
||||
' ',
|
||||
' ',
|
||||
' '
|
||||
];
|
||||
|
||||
function leftPad (str, len, ch) {
|
||||
// convert `str` to a `string`
|
||||
str = str + '';
|
||||
// `len` is the `pad`'s length now
|
||||
len = len - str.length;
|
||||
// doesn't need to pad
|
||||
if (len <= 0) return str;
|
||||
// `ch` defaults to `' '`
|
||||
if (!ch && ch !== 0) ch = ' ';
|
||||
// convert `ch` to a `string` cuz it could be a number
|
||||
ch = ch + '';
|
||||
// cache common use cases
|
||||
if (ch === ' ' && len < 10) return cache[len] + str;
|
||||
// `pad` starts with an empty string
|
||||
var pad = '';
|
||||
// loop
|
||||
while (true) {
|
||||
// add `ch` to `pad` if `len` is odd
|
||||
if (len & 1) pad += ch;
|
||||
// divide `len` by 2, ditch the remainder
|
||||
len >>= 1;
|
||||
// "double" the `ch` so this operation count grows logarithmically on `len`
|
||||
// each time `ch` is "doubled", the `len` would need to be "doubled" too
|
||||
// similar to finding a value in binary search tree, hence O(log(n))
|
||||
if (len) ch += ch;
|
||||
// `len` is 0, exit the loop
|
||||
else break;
|
||||
}
|
||||
// pad `str`!
|
||||
return pad + str;
|
||||
}
|
||||
24
node_modules/left-pad/package.json
generated
vendored
Normal file
24
node_modules/left-pad/package.json
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "left-pad",
|
||||
"version": "1.3.0",
|
||||
"description": "String left pad",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"devDependencies": {
|
||||
"benchmark": "^2.1.0",
|
||||
"fast-check": "0.0.8",
|
||||
"tape": "*"
|
||||
},
|
||||
"repository": {
|
||||
"url": "git@github.com:stevemao/left-pad.git",
|
||||
"type": "git"
|
||||
},
|
||||
"author": "azer",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "Cameron Westland",
|
||||
"email": "camwest@gmail.com"
|
||||
}
|
||||
],
|
||||
"license": "WTFPL"
|
||||
}
|
||||
17
node_modules/left-pad/perf/O(n).js
generated
vendored
Normal file
17
node_modules/left-pad/perf/O(n).js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (str, len, ch) {
|
||||
str = str + '';
|
||||
|
||||
len = len - str.length;
|
||||
if (len <= 0) return str;
|
||||
|
||||
if (!ch && ch !== 0) ch = ' ';
|
||||
ch = ch + '';
|
||||
|
||||
while (len--) {
|
||||
str = ch + str;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
13
node_modules/left-pad/perf/es6Repeat.js
generated
vendored
Normal file
13
node_modules/left-pad/perf/es6Repeat.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (str, len, ch) {
|
||||
str = str + '';
|
||||
|
||||
len = len - str.length;
|
||||
if (len <= 0) return str;
|
||||
|
||||
if (!ch && ch !== 0) ch = ' ';
|
||||
ch = ch + '';
|
||||
|
||||
return ch.repeat(len) + str;
|
||||
};
|
||||
40
node_modules/left-pad/perf/perf.js
generated
vendored
Normal file
40
node_modules/left-pad/perf/perf.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
'use strict';
|
||||
var oN = require('./O(n)');
|
||||
var es6Repeat = require('./es6Repeat');
|
||||
var current = require('../');
|
||||
|
||||
var Benchmark = require('benchmark');
|
||||
|
||||
var str = "abcd"
|
||||
var len = 100;
|
||||
|
||||
function buildSuite (note, fns, args) {
|
||||
console.log(note);
|
||||
var suite = new Benchmark.Suite;
|
||||
|
||||
Object.keys(fns).forEach(function (name) {
|
||||
suite.add(name, function () {
|
||||
fns[name].apply(null, args);
|
||||
});
|
||||
});
|
||||
suite.on('cycle', function (event) {
|
||||
console.log(String(event.target));
|
||||
}).on('complete', function () {
|
||||
console.log('Fastest is ' + this.filter('fastest').map('name'));
|
||||
});
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
||||
var fns = {
|
||||
'O(n)': oN,
|
||||
'ES6 Repeat': es6Repeat,
|
||||
'Current': current
|
||||
};
|
||||
|
||||
buildSuite('-> pad 100 spaces to str of len 4', fns, ['abcd', 104, ' ']).run();
|
||||
buildSuite('-> pad 10 spaces to str of len 4', fns, ['abcd', 14, ' ']).run();
|
||||
buildSuite('-> pad 9 spaces to str of len 4', fns, ['abcd', 13, ' ']).run();
|
||||
buildSuite('-> pad 100 to str of len 100', fns, ['0012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789123456789', 200, ' ']).run();
|
||||
buildSuite('-> pad 10 to str of len 100', fns, ['0012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789123456789', 110, ' ']).run();
|
||||
buildSuite('-> pad 9 to str of len 100', fns, ['0012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789123456789', 109, ' ']).run();
|
||||
Reference in New Issue
Block a user