From e5957f24dab2962a09f7a2746d3381bafcba9553 Mon Sep 17 00:00:00 2001 From: Chinenye Onuegbu Date: Wed, 21 Nov 2018 15:11:34 +0100 Subject: [PATCH] Half-baked --- node_modules/is-number/LICENSE | 21 ++ node_modules/is-number/README.md | 135 ++++++++++ node_modules/is-number/index.js | 21 ++ node_modules/is-number/package.json | 113 ++++++++ node_modules/kind-of/CHANGELOG.md | 157 +++++++++++ node_modules/kind-of/LICENSE | 21 ++ node_modules/kind-of/README.md | 365 ++++++++++++++++++++++++++ node_modules/kind-of/index.js | 129 +++++++++ node_modules/kind-of/package.json | 143 ++++++++++ node_modules/math-random/.npmignore | 1 + node_modules/math-random/.travis.yml | 6 + node_modules/math-random/browser.js | 17 ++ node_modules/math-random/node.js | 13 + node_modules/math-random/package.json | 58 ++++ node_modules/math-random/readme.md | 26 ++ node_modules/math-random/test.js | 26 ++ node_modules/randomatic/LICENSE | 21 ++ node_modules/randomatic/README.md | 193 ++++++++++++++ node_modules/randomatic/index.js | 95 +++++++ node_modules/randomatic/package.json | 136 ++++++++++ package-lock.json | 25 ++ package.json | 1 + src/context.ts | 132 +++++++++- src/modules/randomatic.d.ts | 5 + src/worker.ts | 42 ++- 25 files changed, 1888 insertions(+), 14 deletions(-) create mode 100644 node_modules/is-number/LICENSE create mode 100644 node_modules/is-number/README.md create mode 100644 node_modules/is-number/index.js create mode 100644 node_modules/is-number/package.json create mode 100644 node_modules/kind-of/CHANGELOG.md create mode 100644 node_modules/kind-of/LICENSE create mode 100644 node_modules/kind-of/README.md create mode 100644 node_modules/kind-of/index.js create mode 100644 node_modules/kind-of/package.json create mode 100644 node_modules/math-random/.npmignore create mode 100644 node_modules/math-random/.travis.yml create mode 100644 node_modules/math-random/browser.js create mode 100644 node_modules/math-random/node.js create mode 100644 node_modules/math-random/package.json create mode 100644 node_modules/math-random/readme.md create mode 100644 node_modules/math-random/test.js create mode 100644 node_modules/randomatic/LICENSE create mode 100644 node_modules/randomatic/README.md create mode 100644 node_modules/randomatic/index.js create mode 100644 node_modules/randomatic/package.json create mode 100644 src/modules/randomatic.d.ts diff --git a/node_modules/is-number/LICENSE b/node_modules/is-number/LICENSE new file mode 100644 index 0000000..3f2eca1 --- /dev/null +++ b/node_modules/is-number/LICENSE @@ -0,0 +1,21 @@ +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. diff --git a/node_modules/is-number/README.md b/node_modules/is-number/README.md new file mode 100644 index 0000000..6436992 --- /dev/null +++ b/node_modules/is-number/README.md @@ -0,0 +1,135 @@ +# is-number [![NPM version](https://img.shields.io/npm/v/is-number.svg?style=flat)](https://www.npmjs.com/package/is-number) [![NPM monthly downloads](https://img.shields.io/npm/dm/is-number.svg?style=flat)](https://npmjs.org/package/is-number) [![NPM total downloads](https://img.shields.io/npm/dt/is-number.svg?style=flat)](https://npmjs.org/package/is-number) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/is-number.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/is-number) + +> Returns true if the value is a number. comprehensive tests. + +Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. + +## Install + +Install with [npm](https://www.npmjs.com/): + +```sh +$ npm install --save is-number +``` + +## Usage + +To understand some of the rationale behind the decisions made in this library (and to learn about some oddities of number evaluation in JavaScript), [see this gist](https://gist.github.com/jonschlinkert/e30c70c713da325d0e81). + +```js +var isNumber = require('is-number'); +``` + +### true + +See the [tests](./test.js) for more examples. + +```js +isNumber(5e3) //=> 'true' +isNumber(0xff) //=> 'true' +isNumber(-1.1) //=> 'true' +isNumber(0) //=> 'true' +isNumber(1) //=> 'true' +isNumber(1.1) //=> 'true' +isNumber(10) //=> 'true' +isNumber(10.10) //=> 'true' +isNumber(100) //=> 'true' +isNumber('-1.1') //=> 'true' +isNumber('0') //=> 'true' +isNumber('012') //=> 'true' +isNumber('0xff') //=> 'true' +isNumber('1') //=> 'true' +isNumber('1.1') //=> 'true' +isNumber('10') //=> 'true' +isNumber('10.10') //=> 'true' +isNumber('100') //=> 'true' +isNumber('5e3') //=> 'true' +isNumber(parseInt('012')) //=> 'true' +isNumber(parseFloat('012')) //=> 'true' +``` + +### False + +See the [tests](./test.js) for more examples. + +```js +isNumber('foo') //=> 'false' +isNumber([1]) //=> 'false' +isNumber([]) //=> 'false' +isNumber(function () {}) //=> 'false' +isNumber(Infinity) //=> 'false' +isNumber(NaN) //=> 'false' +isNumber(new Array('abc')) //=> 'false' +isNumber(new Array(2)) //=> 'false' +isNumber(new Buffer('abc')) //=> 'false' +isNumber(null) //=> 'false' +isNumber(undefined) //=> 'false' +isNumber({abc: 'abc'}) //=> 'false' +``` + +## About + +
+Contributing + +Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). + +
+ +
+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 +``` + +
+ +
+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 +``` + +
+ +### Related projects + +You might also be interested in these projects: + +* [even](https://www.npmjs.com/package/even): Get the even numbered items from an array. | [homepage](https://github.com/jonschlinkert/even "Get the even numbered items from an array.") +* [is-even](https://www.npmjs.com/package/is-even): Return true if the given number is even. | [homepage](https://github.com/jonschlinkert/is-even "Return true if the given number is even.") +* [is-odd](https://www.npmjs.com/package/is-odd): Returns true if the given number is odd. | [homepage](https://github.com/jonschlinkert/is-odd "Returns true if the given number is odd.") +* [is-primitive](https://www.npmjs.com/package/is-primitive): Returns `true` if the value is a primitive. | [homepage](https://github.com/jonschlinkert/is-primitive "Returns `true` if the value is a primitive. ") +* [kind-of](https://www.npmjs.com/package/kind-of): Get the native type of a value. | [homepage](https://github.com/jonschlinkert/kind-of "Get the native type of a value.") +* [odd](https://www.npmjs.com/package/odd): Get the odd numbered items from an array. | [homepage](https://github.com/jonschlinkert/odd "Get the odd numbered items from an array.") + +### Contributors + +| **Commits** | **Contributor** | +| --- | --- | +| 38 | [jonschlinkert](https://github.com/jonschlinkert) | +| 5 | [charlike](https://github.com/charlike) | + +### 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 October 17, 2017._ \ No newline at end of file diff --git a/node_modules/is-number/index.js b/node_modules/is-number/index.js new file mode 100644 index 0000000..5221f40 --- /dev/null +++ b/node_modules/is-number/index.js @@ -0,0 +1,21 @@ +/*! + * is-number + * + * Copyright (c) 2014-2017, Jon Schlinkert. + * Released under the MIT License. + */ + +'use strict'; + +module.exports = function isNumber(num) { + var type = typeof num; + + if (type === 'string' || num instanceof String) { + // an empty string would be coerced to true with the below logic + if (!num.trim()) return false; + } else if (type !== 'number' && !(num instanceof Number)) { + return false; + } + + return (num - num + 1) >= 0; +}; diff --git a/node_modules/is-number/package.json b/node_modules/is-number/package.json new file mode 100644 index 0000000..74956d5 --- /dev/null +++ b/node_modules/is-number/package.json @@ -0,0 +1,113 @@ +{ + "_from": "is-number@^4.0.0", + "_id": "is-number@4.0.0", + "_inBundle": false, + "_integrity": "sha512-rSklcAIlf1OmFdyAqbnWTLVelsQ58uvZ66S/ZyawjWqIviTWCjg2PzVGw8WUA+nNuPTqb4wgA+NszrJ+08LlgQ==", + "_location": "/is-number", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "is-number@^4.0.0", + "name": "is-number", + "escapedName": "is-number", + "rawSpec": "^4.0.0", + "saveSpec": null, + "fetchSpec": "^4.0.0" + }, + "_requiredBy": [ + "/randomatic" + ], + "_resolved": "https://registry.npmjs.org/is-number/-/is-number-4.0.0.tgz", + "_shasum": "0026e37f5454d73e356dfe6564699867c6a7f0ff", + "_spec": "is-number@^4.0.0", + "_where": "/Users/conuegbu/Projects/async-thread/node_modules/randomatic", + "author": { + "name": "Jon Schlinkert", + "url": "https://github.com/jonschlinkert" + }, + "bugs": { + "url": "https://github.com/jonschlinkert/is-number/issues" + }, + "bundleDependencies": false, + "contributors": [ + { + "name": "Jon Schlinkert", + "url": "http://twitter.com/jonschlinkert" + }, + { + "name": "tunnckoCore", + "url": "https://i.am.charlike.online" + } + ], + "deprecated": false, + "description": "Returns true if the value is a number. comprehensive tests.", + "devDependencies": { + "benchmarked": "^2.0.0", + "chalk": "^2.1.0", + "gulp-format-md": "^1.0.0", + "mocha": "^3.0.1" + }, + "engines": { + "node": ">=0.10.0" + }, + "files": [ + "index.js" + ], + "homepage": "https://github.com/jonschlinkert/is-number", + "keywords": [ + "check", + "coerce", + "coercion", + "integer", + "is", + "is-nan", + "is-num", + "is-number", + "istype", + "kind", + "math", + "nan", + "num", + "number", + "numeric", + "test", + "type", + "typeof", + "value" + ], + "license": "MIT", + "main": "index.js", + "name": "is-number", + "repository": { + "type": "git", + "url": "git+https://github.com/jonschlinkert/is-number.git" + }, + "scripts": { + "test": "mocha" + }, + "verb": { + "related": { + "list": [ + "even", + "is-even", + "is-odd", + "is-primitive", + "kind-of", + "odd" + ] + }, + "toc": false, + "layout": "default", + "tasks": [ + "readme" + ], + "plugins": [ + "gulp-format-md" + ], + "lint": { + "reflinks": true + } + }, + "version": "4.0.0" +} diff --git a/node_modules/kind-of/CHANGELOG.md b/node_modules/kind-of/CHANGELOG.md new file mode 100644 index 0000000..fb30b06 --- /dev/null +++ b/node_modules/kind-of/CHANGELOG.md @@ -0,0 +1,157 @@ +# Release history + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). + +
+ Guiding Principles + +- Changelogs are for humans, not machines. +- There should be an entry for every single version. +- The same types of changes should be grouped. +- Versions and sections should be linkable. +- The latest version comes first. +- The release date of each versions is displayed. +- Mention whether you follow Semantic Versioning. + +
+ +
+ Types of changes + +Changelog entries are classified using the following labels _(from [keep-a-changelog](http://keepachangelog.com/)_): + +- `Added` for new features. +- `Changed` for changes in existing functionality. +- `Deprecated` for soon-to-be removed features. +- `Removed` for now removed features. +- `Fixed` for any bug fixes. +- `Security` in case of vulnerabilities. + +
+ +## [6.0.0] - 2017-10-13 + +- refactor code to be more performant +- refactor benchmarks + +## [5.1.0] - 2017-10-13 + +**Added** + +- Merge pull request #15 from aretecode/patch-1 +- adds support and tests for string & array iterators + +**Changed** + +- updates benchmarks + +## [5.0.2] - 2017-08-02 + +- Merge pull request #14 from struct78/master +- Added `undefined` check + +## [5.0.0] - 2017-06-21 + +- Merge pull request #12 from aretecode/iterator +- Set Iterator + Map Iterator +- streamline `isbuffer`, minor edits + +## [4.0.0] - 2017-05-19 + +- Merge pull request #8 from tunnckoCore/master +- update deps + +## [3.2.2] - 2017-05-16 + +- fix version + +## [3.2.1] - 2017-05-16 + +- add browserify + +## [3.2.0] - 2017-04-25 + +- Merge pull request #10 from ksheedlo/unrequire-buffer +- add `promise` support and tests +- Remove unnecessary `Buffer` check + +## [3.1.0] - 2016-12-07 + +- Merge pull request #7 from laggingreflex/err +- add support for `error` and tests +- run update + +## [3.0.4] - 2016-07-29 + +- move tests +- run update + +## [3.0.3] - 2016-05-03 + +- fix prepublish script +- remove unused dep + +## [3.0.0] - 2015-11-17 + +- add typed array support +- Merge pull request #5 from miguelmota/typed-arrays +- adds new tests + +## [2.0.1] - 2015-08-21 + +- use `is-buffer` module + +## [2.0.0] - 2015-05-31 + +- Create fallback for `Array.isArray` if used as a browser package +- Merge pull request #2 from dtothefp/patch-1 +- Merge pull request #3 from pdehaan/patch-1 +- Merge branch 'master' of https://github.com/chorks/kind-of into chorks-master +- optimizations, mostly date and regex + +## [1.1.0] - 2015-02-09 + +- adds `buffer` support +- adds tests for `buffer` + +## [1.0.0] - 2015-01-19 + +- update benchmarks +- optimizations based on benchmarks + +## [0.1.2] - 2014-10-26 + +- return `typeof` value if it's not an object. very slight speed improvement +- use `.slice` +- adds benchmarks + +## [0.1.0] - 2014-9-26 + +- first commit + +[6.0.0]: https://github.com/jonschlinkert/kind-of/compare/5.1.0...6.0.0 +[5.1.0]: https://github.com/jonschlinkert/kind-of/compare/5.0.2...5.1.0 +[5.0.2]: https://github.com/jonschlinkert/kind-of/compare/5.0.1...5.0.2 +[5.0.1]: https://github.com/jonschlinkert/kind-of/compare/5.0.0...5.0.1 +[5.0.0]: https://github.com/jonschlinkert/kind-of/compare/4.0.0...5.0.0 +[4.0.0]: https://github.com/jonschlinkert/kind-of/compare/3.2.2...4.0.0 +[3.2.2]: https://github.com/jonschlinkert/kind-of/compare/3.2.1...3.2.2 +[3.2.1]: https://github.com/jonschlinkert/kind-of/compare/3.2.0...3.2.1 +[3.2.0]: https://github.com/jonschlinkert/kind-of/compare/3.1.0...3.2.0 +[3.1.0]: https://github.com/jonschlinkert/kind-of/compare/3.0.4...3.1.0 +[3.0.4]: https://github.com/jonschlinkert/kind-of/compare/3.0.3...3.0.4 +[3.0.3]: https://github.com/jonschlinkert/kind-of/compare/3.0.0...3.0.3 +[3.0.0]: https://github.com/jonschlinkert/kind-of/compare/2.0.1...3.0.0 +[2.0.1]: https://github.com/jonschlinkert/kind-of/compare/2.0.0...2.0.1 +[2.0.0]: https://github.com/jonschlinkert/kind-of/compare/1.1.0...2.0.0 +[1.1.0]: https://github.com/jonschlinkert/kind-of/compare/1.0.0...1.1.0 +[1.0.0]: https://github.com/jonschlinkert/kind-of/compare/0.1.2...1.0.0 +[0.1.2]: https://github.com/jonschlinkert/kind-of/compare/0.1.0...0.1.2 +[0.1.0]: https://github.com/jonschlinkert/kind-of/commit/2fae09b0b19b1aadb558e9be39f0c3ef6034eb87 + +[Unreleased]: https://github.com/jonschlinkert/kind-of/compare/0.1.2...HEAD +[keep-a-changelog]: https://github.com/olivierlacan/keep-a-changelog + diff --git a/node_modules/kind-of/LICENSE b/node_modules/kind-of/LICENSE new file mode 100644 index 0000000..3f2eca1 --- /dev/null +++ b/node_modules/kind-of/LICENSE @@ -0,0 +1,21 @@ +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. diff --git a/node_modules/kind-of/README.md b/node_modules/kind-of/README.md new file mode 100644 index 0000000..4b0d4a8 --- /dev/null +++ b/node_modules/kind-of/README.md @@ -0,0 +1,365 @@ +# kind-of [![NPM version](https://img.shields.io/npm/v/kind-of.svg?style=flat)](https://www.npmjs.com/package/kind-of) [![NPM monthly downloads](https://img.shields.io/npm/dm/kind-of.svg?style=flat)](https://npmjs.org/package/kind-of) [![NPM total downloads](https://img.shields.io/npm/dt/kind-of.svg?style=flat)](https://npmjs.org/package/kind-of) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/kind-of.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/kind-of) + +> Get the native type of a value. + +Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. + +## Install + +Install with [npm](https://www.npmjs.com/): + +```sh +$ npm install --save kind-of +``` + +Install with [bower](https://bower.io/) + +```sh +$ bower install kind-of --save +``` + +## Why use this? + +1. [it's fast](#benchmarks) | [optimizations](#optimizations) +2. [better type checking](#better-type-checking) + +## Usage + +> es5, es6, and browser ready + +```js +var kindOf = require('kind-of'); + +kindOf(undefined); +//=> 'undefined' + +kindOf(null); +//=> 'null' + +kindOf(true); +//=> 'boolean' + +kindOf(false); +//=> 'boolean' + +kindOf(new Buffer('')); +//=> 'buffer' + +kindOf(42); +//=> 'number' + +kindOf('str'); +//=> 'string' + +kindOf(arguments); +//=> 'arguments' + +kindOf({}); +//=> 'object' + +kindOf(Object.create(null)); +//=> 'object' + +kindOf(new Test()); +//=> 'object' + +kindOf(new Date()); +//=> 'date' + +kindOf([1, 2, 3]); +//=> 'array' + +kindOf(/foo/); +//=> 'regexp' + +kindOf(new RegExp('foo')); +//=> 'regexp' + +kindOf(new Error('error')); +//=> 'error' + +kindOf(function () {}); +//=> 'function' + +kindOf(function * () {}); +//=> 'generatorfunction' + +kindOf(Symbol('str')); +//=> 'symbol' + +kindOf(new Map()); +//=> 'map' + +kindOf(new WeakMap()); +//=> 'weakmap' + +kindOf(new Set()); +//=> 'set' + +kindOf(new WeakSet()); +//=> 'weakset' + +kindOf(new Int8Array()); +//=> 'int8array' + +kindOf(new Uint8Array()); +//=> 'uint8array' + +kindOf(new Uint8ClampedArray()); +//=> 'uint8clampedarray' + +kindOf(new Int16Array()); +//=> 'int16array' + +kindOf(new Uint16Array()); +//=> 'uint16array' + +kindOf(new Int32Array()); +//=> 'int32array' + +kindOf(new Uint32Array()); +//=> 'uint32array' + +kindOf(new Float32Array()); +//=> 'float32array' + +kindOf(new Float64Array()); +//=> 'float64array' +``` + +## Benchmarks + +Benchmarked against [typeof](http://github.com/CodingFu/typeof) and [type-of](https://github.com/ForbesLindesay/type-of). + +```bash +# arguments (32 bytes) + kind-of x 17,024,098 ops/sec ±1.90% (86 runs sampled) + lib-type-of x 11,926,235 ops/sec ±1.34% (83 runs sampled) + lib-typeof x 9,245,257 ops/sec ±1.22% (87 runs sampled) + + fastest is kind-of (by 161% avg) + +# array (22 bytes) + kind-of x 17,196,492 ops/sec ±1.07% (88 runs sampled) + lib-type-of x 8,838,283 ops/sec ±1.02% (87 runs sampled) + lib-typeof x 8,677,848 ops/sec ±0.87% (87 runs sampled) + + fastest is kind-of (by 196% avg) + +# boolean (24 bytes) + kind-of x 16,841,600 ops/sec ±1.10% (86 runs sampled) + lib-type-of x 8,096,787 ops/sec ±0.95% (87 runs sampled) + lib-typeof x 8,423,345 ops/sec ±1.15% (86 runs sampled) + + fastest is kind-of (by 204% avg) + +# buffer (38 bytes) + kind-of x 14,848,060 ops/sec ±1.05% (86 runs sampled) + lib-type-of x 3,671,577 ops/sec ±1.49% (87 runs sampled) + lib-typeof x 8,360,236 ops/sec ±1.24% (86 runs sampled) + + fastest is kind-of (by 247% avg) + +# date (30 bytes) + kind-of x 16,067,761 ops/sec ±1.58% (86 runs sampled) + lib-type-of x 8,954,436 ops/sec ±1.40% (87 runs sampled) + lib-typeof x 8,488,307 ops/sec ±1.51% (84 runs sampled) + + fastest is kind-of (by 184% avg) + +# error (36 bytes) + kind-of x 9,634,090 ops/sec ±1.12% (89 runs sampled) + lib-type-of x 7,735,624 ops/sec ±1.32% (86 runs sampled) + lib-typeof x 7,442,160 ops/sec ±1.11% (90 runs sampled) + + fastest is kind-of (by 127% avg) + +# function (34 bytes) + kind-of x 10,031,494 ops/sec ±1.27% (86 runs sampled) + lib-type-of x 9,502,757 ops/sec ±1.17% (89 runs sampled) + lib-typeof x 8,278,985 ops/sec ±1.08% (88 runs sampled) + + fastest is kind-of (by 113% avg) + +# null (24 bytes) + kind-of x 18,159,808 ops/sec ±1.92% (86 runs sampled) + lib-type-of x 12,927,635 ops/sec ±1.01% (88 runs sampled) + lib-typeof x 7,958,234 ops/sec ±1.21% (89 runs sampled) + + fastest is kind-of (by 174% avg) + +# number (22 bytes) + kind-of x 17,846,779 ops/sec ±0.91% (85 runs sampled) + lib-type-of x 3,316,636 ops/sec ±1.19% (86 runs sampled) + lib-typeof x 2,329,477 ops/sec ±2.21% (85 runs sampled) + + fastest is kind-of (by 632% avg) + +# object-plain (47 bytes) + kind-of x 7,085,155 ops/sec ±1.05% (88 runs sampled) + lib-type-of x 8,870,930 ops/sec ±1.06% (83 runs sampled) + lib-typeof x 8,716,024 ops/sec ±1.05% (87 runs sampled) + + fastest is lib-type-of (by 112% avg) + +# regex (25 bytes) + kind-of x 14,196,052 ops/sec ±1.65% (84 runs sampled) + lib-type-of x 9,554,164 ops/sec ±1.25% (88 runs sampled) + lib-typeof x 8,359,691 ops/sec ±1.07% (87 runs sampled) + + fastest is kind-of (by 158% avg) + +# string (33 bytes) + kind-of x 16,131,428 ops/sec ±1.41% (85 runs sampled) + lib-type-of x 7,273,172 ops/sec ±1.05% (87 runs sampled) + lib-typeof x 7,382,635 ops/sec ±1.17% (85 runs sampled) + + fastest is kind-of (by 220% avg) + +# symbol (34 bytes) + kind-of x 17,011,537 ops/sec ±1.24% (86 runs sampled) + lib-type-of x 3,492,454 ops/sec ±1.23% (89 runs sampled) + lib-typeof x 7,471,235 ops/sec ±2.48% (87 runs sampled) + + fastest is kind-of (by 310% avg) + +# template-strings (36 bytes) + kind-of x 15,434,250 ops/sec ±1.46% (83 runs sampled) + lib-type-of x 7,157,907 ops/sec ±0.97% (87 runs sampled) + lib-typeof x 7,517,986 ops/sec ±0.92% (86 runs sampled) + + fastest is kind-of (by 210% avg) + +# undefined (29 bytes) + kind-of x 19,167,115 ops/sec ±1.71% (87 runs sampled) + lib-type-of x 15,477,740 ops/sec ±1.63% (85 runs sampled) + lib-typeof x 19,075,495 ops/sec ±1.17% (83 runs sampled) + + fastest is lib-typeof,kind-of + +``` + +## Optimizations + +In 7 out of 8 cases, this library is 2x-10x faster than other top libraries included in the benchmarks. There are a few things that lead to this performance advantage, none of them hard and fast rules, but all of them simple and repeatable in almost any code library: + +1. Optimize around the fastest and most common use cases first. Of course, this will change from project-to-project, but I took some time to understand how and why `typeof` checks were being used in my own libraries and other libraries I use a lot. +2. Optimize around bottlenecks - In other words, the order in which conditionals are implemented is significant, because each check is only as fast as the failing checks that came before it. Here, the biggest bottleneck by far is checking for plain objects (an object that was created by the `Object` constructor). I opted to make this check happen by process of elimination rather than brute force up front (e.g. by using something like `val.constructor.name`), so that every other type check would not be penalized it. +3. Don't do uneccessary processing - why do `.slice(8, -1).toLowerCase();` just to get the word `regex`? It's much faster to do `if (type === '[object RegExp]') return 'regex'` +4. There is no reason to make the code in a microlib as terse as possible, just to win points for making it shorter. It's always better to favor performant code over terse code. You will always only be using a single `require()` statement to use the library anyway, regardless of how the code is written. + +## Better type checking + +kind-of seems to be more consistently "correct" than other type checking libs I've looked at. For example, here are some differing results from other popular libs: + +### [typeof](https://github.com/CodingFu/typeof) lib + +Incorrectly identifies instances of custom constructors (pretty common): + +```js +var typeOf = require('typeof'); +function Test() {} +console.log(typeOf(new Test())); +//=> 'test' +``` + +Returns `object` instead of `arguments`: + +```js +function foo() { + console.log(typeOf(arguments)) //=> 'object' +} +foo(); +``` + +### [type-of](https://github.com/ForbesLindesay/type-of) lib + +Incorrectly returns `object` for generator functions, buffers, `Map`, `Set`, `WeakMap` and `WeakSet`: + +```js +function * foo() {} +console.log(typeOf(foo)); +//=> 'object' +console.log(typeOf(new Buffer(''))); +//=> 'object' +console.log(typeOf(new Map())); +//=> 'object' +console.log(typeOf(new Set())); +//=> 'object' +console.log(typeOf(new WeakMap())); +//=> 'object' +console.log(typeOf(new WeakSet())); +//=> 'object' +``` + +## About + +
+Contributing + +Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). + +
+ +
+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 +``` + +
+ +
+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 +``` + +
+ +### Related projects + +You might also be interested in these projects: + +* [is-glob](https://www.npmjs.com/package/is-glob): Returns `true` if the given string looks like a glob pattern or an extglob pattern… [more](https://github.com/jonschlinkert/is-glob) | [homepage](https://github.com/jonschlinkert/is-glob "Returns `true` if the given string looks like a glob pattern or an extglob pattern. This makes it easy to create code that only uses external modules like node-glob when necessary, resulting in much faster code execution and initialization time, and a bet") +* [is-number](https://www.npmjs.com/package/is-number): Returns true if the value is a number. comprehensive tests. | [homepage](https://github.com/jonschlinkert/is-number "Returns true if the value is a number. comprehensive tests.") +* [is-primitive](https://www.npmjs.com/package/is-primitive): Returns `true` if the value is a primitive. | [homepage](https://github.com/jonschlinkert/is-primitive "Returns `true` if the value is a primitive. ") + +### Contributors + +| **Commits** | **Contributor** | +| --- | --- | +| 98 | [jonschlinkert](https://github.com/jonschlinkert) | +| 3 | [aretecode](https://github.com/aretecode) | +| 2 | [miguelmota](https://github.com/miguelmota) | +| 1 | [dtothefp](https://github.com/dtothefp) | +| 1 | [ianstormtaylor](https://github.com/ianstormtaylor) | +| 1 | [ksheedlo](https://github.com/ksheedlo) | +| 1 | [pdehaan](https://github.com/pdehaan) | +| 1 | [laggingreflex](https://github.com/laggingreflex) | +| 1 | [charlike-old](https://github.com/charlike-old) | + +### Author + +**Jon Schlinkert** + +* [linkedin/in/jonschlinkert](https://linkedin.com/in/jonschlinkert) +* [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 December 01, 2017._ \ No newline at end of file diff --git a/node_modules/kind-of/index.js b/node_modules/kind-of/index.js new file mode 100644 index 0000000..aa2bb39 --- /dev/null +++ b/node_modules/kind-of/index.js @@ -0,0 +1,129 @@ +var toString = Object.prototype.toString; + +module.exports = function kindOf(val) { + if (val === void 0) return 'undefined'; + if (val === null) return 'null'; + + var type = typeof val; + if (type === 'boolean') return 'boolean'; + if (type === 'string') return 'string'; + if (type === 'number') return 'number'; + if (type === 'symbol') return 'symbol'; + if (type === 'function') { + return isGeneratorFn(val) ? 'generatorfunction' : 'function'; + } + + if (isArray(val)) return 'array'; + if (isBuffer(val)) return 'buffer'; + if (isArguments(val)) return 'arguments'; + if (isDate(val)) return 'date'; + if (isError(val)) return 'error'; + if (isRegexp(val)) return 'regexp'; + + switch (ctorName(val)) { + case 'Symbol': return 'symbol'; + case 'Promise': return 'promise'; + + // Set, Map, WeakSet, WeakMap + case 'WeakMap': return 'weakmap'; + case 'WeakSet': return 'weakset'; + case 'Map': return 'map'; + case 'Set': return 'set'; + + // 8-bit typed arrays + case 'Int8Array': return 'int8array'; + case 'Uint8Array': return 'uint8array'; + case 'Uint8ClampedArray': return 'uint8clampedarray'; + + // 16-bit typed arrays + case 'Int16Array': return 'int16array'; + case 'Uint16Array': return 'uint16array'; + + // 32-bit typed arrays + case 'Int32Array': return 'int32array'; + case 'Uint32Array': return 'uint32array'; + case 'Float32Array': return 'float32array'; + case 'Float64Array': return 'float64array'; + } + + if (isGeneratorObj(val)) { + return 'generator'; + } + + // Non-plain objects + type = toString.call(val); + switch (type) { + case '[object Object]': return 'object'; + // iterators + case '[object Map Iterator]': return 'mapiterator'; + case '[object Set Iterator]': return 'setiterator'; + case '[object String Iterator]': return 'stringiterator'; + case '[object Array Iterator]': return 'arrayiterator'; + } + + // other + return type.slice(8, -1).toLowerCase().replace(/\s/g, ''); +}; + +function ctorName(val) { + return val.constructor ? val.constructor.name : null; +} + +function isArray(val) { + if (Array.isArray) return Array.isArray(val); + return val instanceof Array; +} + +function isError(val) { + return val instanceof Error || (typeof val.message === 'string' && val.constructor && typeof val.constructor.stackTraceLimit === 'number'); +} + +function isDate(val) { + if (val instanceof Date) return true; + return typeof val.toDateString === 'function' + && typeof val.getDate === 'function' + && typeof val.setDate === 'function'; +} + +function isRegexp(val) { + if (val instanceof RegExp) return true; + return typeof val.flags === 'string' + && typeof val.ignoreCase === 'boolean' + && typeof val.multiline === 'boolean' + && typeof val.global === 'boolean'; +} + +function isGeneratorFn(name, val) { + return ctorName(name) === 'GeneratorFunction'; +} + +function isGeneratorObj(val) { + return typeof val.throw === 'function' + && typeof val.return === 'function' + && typeof val.next === 'function'; +} + +function isArguments(val) { + try { + if (typeof val.length === 'number' && typeof val.callee === 'function') { + return true; + } + } catch (err) { + if (err.message.indexOf('callee') !== -1) { + return true; + } + } + return false; +} + +/** + * If you need to support Safari 5-7 (8-10 yr-old browser), + * take a look at https://github.com/feross/is-buffer + */ + +function isBuffer(val) { + if (val.constructor && typeof val.constructor.isBuffer === 'function') { + return val.constructor.isBuffer(val); + } + return false; +} diff --git a/node_modules/kind-of/package.json b/node_modules/kind-of/package.json new file mode 100644 index 0000000..4564735 --- /dev/null +++ b/node_modules/kind-of/package.json @@ -0,0 +1,143 @@ +{ + "_from": "kind-of@^6.0.0", + "_id": "kind-of@6.0.2", + "_inBundle": false, + "_integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==", + "_location": "/kind-of", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "kind-of@^6.0.0", + "name": "kind-of", + "escapedName": "kind-of", + "rawSpec": "^6.0.0", + "saveSpec": null, + "fetchSpec": "^6.0.0" + }, + "_requiredBy": [ + "/randomatic" + ], + "_resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", + "_shasum": "01146b36a6218e64e58f3a8d66de5d7fc6f6d051", + "_spec": "kind-of@^6.0.0", + "_where": "/Users/conuegbu/Projects/async-thread/node_modules/randomatic", + "author": { + "name": "Jon Schlinkert", + "url": "https://github.com/jonschlinkert" + }, + "bugs": { + "url": "https://github.com/jonschlinkert/kind-of/issues" + }, + "bundleDependencies": false, + "contributors": [ + { + "name": "David Fox-Powell", + "url": "https://dtothefp.github.io/me" + }, + { + "name": "James", + "url": "https://twitter.com/aretecode" + }, + { + "name": "Jon Schlinkert", + "url": "http://twitter.com/jonschlinkert" + }, + { + "name": "Ken Sheedlo", + "url": "kensheedlo.com" + }, + { + "name": "laggingreflex", + "url": "https://github.com/laggingreflex" + }, + { + "name": "Miguel Mota", + "url": "https://miguelmota.com" + }, + { + "name": "Peter deHaan", + "url": "http://about.me/peterdehaan" + }, + { + "name": "tunnckoCore", + "url": "https://i.am.charlike.online" + } + ], + "deprecated": false, + "description": "Get the native type of a value.", + "devDependencies": { + "benchmarked": "^2.0.0", + "browserify": "^14.4.0", + "gulp-format-md": "^1.0.0", + "mocha": "^4.0.1", + "write": "^1.0.3" + }, + "engines": { + "node": ">=0.10.0" + }, + "files": [ + "index.js" + ], + "homepage": "https://github.com/jonschlinkert/kind-of", + "keywords": [ + "arguments", + "array", + "boolean", + "check", + "date", + "function", + "is", + "is-type", + "is-type-of", + "kind", + "kind-of", + "number", + "object", + "of", + "regexp", + "string", + "test", + "type", + "type-of", + "typeof", + "types" + ], + "license": "MIT", + "main": "index.js", + "name": "kind-of", + "repository": { + "type": "git", + "url": "git+https://github.com/jonschlinkert/kind-of.git" + }, + "scripts": { + "prepublish": "browserify -o browser.js -e index.js -s index --bare", + "test": "mocha" + }, + "verb": { + "toc": false, + "layout": "default", + "tasks": [ + "readme" + ], + "plugins": [ + "gulp-format-md" + ], + "lint": { + "reflinks": true + }, + "related": { + "list": [ + "is-glob", + "is-number", + "is-primitive" + ] + }, + "reflinks": [ + "type-of", + "typeof", + "verb" + ] + }, + "version": "6.0.2" +} diff --git a/node_modules/math-random/.npmignore b/node_modules/math-random/.npmignore new file mode 100644 index 0000000..8d87b1d --- /dev/null +++ b/node_modules/math-random/.npmignore @@ -0,0 +1 @@ +node_modules/* diff --git a/node_modules/math-random/.travis.yml b/node_modules/math-random/.travis.yml new file mode 100644 index 0000000..054c803 --- /dev/null +++ b/node_modules/math-random/.travis.yml @@ -0,0 +1,6 @@ +language: node_js +node_js: + - "6" + - "4" + - "0.12" + - "0.10" diff --git a/node_modules/math-random/browser.js b/node_modules/math-random/browser.js new file mode 100644 index 0000000..cde412e --- /dev/null +++ b/node_modules/math-random/browser.js @@ -0,0 +1,17 @@ +module.exports = (function (global) { + var uint32 = 'Uint32Array' in global + var crypto = global.crypto || global.msCrypto + var rando = crypto && typeof crypto.getRandomValues === 'function' + var good = uint32 && crypto && rando + if (!good) return Math.random + + var arr = new Uint32Array(1) + var max = Math.pow(2, 32) + function random () { + crypto.getRandomValues(arr) + return arr[0] / max + } + + random.cryptographic = true + return random +})(typeof self !== 'undefined' ? self : window) diff --git a/node_modules/math-random/node.js b/node_modules/math-random/node.js new file mode 100644 index 0000000..da6783e --- /dev/null +++ b/node_modules/math-random/node.js @@ -0,0 +1,13 @@ +var crypto = require('crypto') +var max = Math.pow(2, 32) + +module.exports = random +module.exports.cryptographic = true + +function random () { + var buf = crypto + .randomBytes(4) + .toString('hex') + + return parseInt(buf, 16) / max +} diff --git a/node_modules/math-random/package.json b/node_modules/math-random/package.json new file mode 100644 index 0000000..038dec4 --- /dev/null +++ b/node_modules/math-random/package.json @@ -0,0 +1,58 @@ +{ + "_from": "math-random@^1.0.1", + "_id": "math-random@1.0.1", + "_inBundle": false, + "_integrity": "sha1-izqsWIuKZuSXXjzepn97sylgH6w=", + "_location": "/math-random", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "math-random@^1.0.1", + "name": "math-random", + "escapedName": "math-random", + "rawSpec": "^1.0.1", + "saveSpec": null, + "fetchSpec": "^1.0.1" + }, + "_requiredBy": [ + "/randomatic" + ], + "_resolved": "https://registry.npmjs.org/math-random/-/math-random-1.0.1.tgz", + "_shasum": "8b3aac588b8a66e4975e3cdea67f7bb329601fac", + "_spec": "math-random@^1.0.1", + "_where": "/Users/conuegbu/Projects/async-thread/node_modules/randomatic", + "author": { + "name": "Michael Rhodes" + }, + "browser": "browser.js", + "bugs": { + "url": "https://github.com/michaelrhodes/math-random/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "a drop-in replacement for Math.random that uses cryptographically secure random number generation, where available", + "devDependencies": { + "array-unique": "~0.2.1", + "tape": "~4.2.2" + }, + "homepage": "https://github.com/michaelrhodes/math-random", + "keywords": [ + "Math.random", + "crypto.getRandomValues" + ], + "license": "MIT", + "main": "node.js", + "name": "math-random", + "repository": { + "type": "git", + "url": "git+ssh://git@github.com/michaelrhodes/math-random.git" + }, + "scripts": { + "test": "tape test.js" + }, + "testling": { + "files": "test.js" + }, + "version": "1.0.1" +} diff --git a/node_modules/math-random/readme.md b/node_modules/math-random/readme.md new file mode 100644 index 0000000..17beb70 --- /dev/null +++ b/node_modules/math-random/readme.md @@ -0,0 +1,26 @@ +# math-random + +math-random is an drop-in replacement for Math.random that uses cryptographically secure random number generation, where available. It works in both browser and node environments. + +[![Build status](https://travis-ci.org/michaelrhodes/math-random.svg?branch=master)](https://travis-ci.org/michaelrhodes/math-random) + +## Install + +```sh +npm install math-random +``` + +### Usage + +```js +var random = require('math-random') + +console.log(random()) +=> 0.584293719381094 + +console.log(random.cryptographic) +=> true || undefined +``` + +### License +[MIT](http://opensource.org/licenses/MIT) diff --git a/node_modules/math-random/test.js b/node_modules/math-random/test.js new file mode 100644 index 0000000..b7706b7 --- /dev/null +++ b/node_modules/math-random/test.js @@ -0,0 +1,26 @@ +var test = require('tape') +var unique = require('array-unique') +var random = require('./') + +test('it works', function (assert) { + var number, l = 1000, cache = [] + + for (var i = 0; i < l; i++) { + number = random() + if (number <= 0) { + assert.fail('a random number was less than or equal to zero') + assert.end() + return + } + if (number >= 1) { + assert.fail('a random number was greater than or equal to one') + assert.end() + return + } + cache.push(number) + } + + assert.pass('all ' + l + ' random numbers were greater than zero and less than one') + assert.equal(cache.length, unique(cache).length, 'all ' + l + ' random numbers were unique') + assert.end() +}) diff --git a/node_modules/randomatic/LICENSE b/node_modules/randomatic/LICENSE new file mode 100644 index 0000000..38a4a0b --- /dev/null +++ b/node_modules/randomatic/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2013-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. diff --git a/node_modules/randomatic/README.md b/node_modules/randomatic/README.md new file mode 100644 index 0000000..292e642 --- /dev/null +++ b/node_modules/randomatic/README.md @@ -0,0 +1,193 @@ +# randomatic [![NPM version](https://img.shields.io/npm/v/randomatic.svg?style=flat)](https://www.npmjs.com/package/randomatic) [![NPM monthly downloads](https://img.shields.io/npm/dm/randomatic.svg?style=flat)](https://npmjs.org/package/randomatic) [![NPM total downloads](https://img.shields.io/npm/dt/randomatic.svg?style=flat)](https://npmjs.org/package/randomatic) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/randomatic.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/randomatic) + +> Generate randomized strings of a specified length using simple character sequences. The original generate-password. + +Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. + +## Install + +Install with [npm](https://www.npmjs.com/): + +```sh +$ npm install --save randomatic +``` + +## Usage + +```js +var randomize = require('randomatic'); +``` + +## API + +```js +randomize(pattern, length, options); +randomize.isCrypto; +``` + +* `pattern` **{String}**: (required) The pattern to use for randomizing +* `length` **{Number}**: (optional) The length of the string to generate +* `options` **{Object}**: (optional) See available [options](#options) +* `randomize.isCrypto` will be `true` when a cryptographically secure function is being used to generate random numbers. The value will be `false` when the function in use is `Math.random`. + +### pattern + +> The pattern to use for randomizing + +Patterns can contain any combination of the below characters, specified in any order. + +**Example:** + +To generate a 10-character randomized string using all available characters: + +```js +randomize('*', 10); +//=> 'x2_^-5_T[$' + +randomize('Aa0!', 10); +//=> 'LV3u~BSGhw' +``` + +* `a`: Lowercase alpha characters (`abcdefghijklmnopqrstuvwxyz'`) +* `A`: Uppercase alpha characters (`ABCDEFGHIJKLMNOPQRSTUVWXYZ'`) +* `0`: Numeric characters (`0123456789'`) +* `!`: Special characters (`~!@#$%^&()_+-={}[];\',.`) +* `*`: All characters (all of the above combined) +* `?`: Custom characters (pass a string of custom characters to the options) + +### length + +> The length of the string to generate + +**Examples:** + +* `randomize('A', 5)` will generate a 5-character, uppercase, alphabetical, randomized string, e.g. `KDJWJ`. +* `randomize('0', 2)` will generate a 2-digit random number +* `randomize('0', 3)` will generate a 3-digit random number +* `randomize('0', 12)` will generate a 12-digit random number +* `randomize('A0', 16)` will generate a 16-character, alpha-numeric randomized string + +If `length` is left undefined, the length of the pattern in the first parameter will be used. For example: + +* `randomize('00')` will generate a 2-digit random number +* `randomize('000')` will generate a 3-digit random number +* `randomize('0000')` will generate a 4-digit random number... +* `randomize('AAAAA')` will generate a 5-character, uppercase alphabetical random string... + +These are just examples, [see the tests](./test.js) for more use cases and examples. + +## options + +> These are options that can be passed as the third argument. + +#### chars + +Type: `String` + +Default: `undefined` + +Define a custom string to be randomized. + +**Example:** + +* `randomize('?', 20, {chars: 'jonschlinkert'})` will generate a 20-character randomized string from the letters contained in `jonschlinkert`. +* `randomize('?', {chars: 'jonschlinkert'})` will generate a 13-character randomized string from the letters contained in `jonschlinkert`. + +#### exclude + +Type: `String|Array` + +Default: `undefined` + +Specify a string or array of characters can are excluded from the possible characters used to generate the randomized string. + +**Example:** + +* `randomize('*', 20, { exclude: '0oOiIlL1' })` will generate a 20-character randomized string using all of possible characters except for `0oOiIlL1`. + +## Usage Examples + +* `randomize('A', 4)` (_whitespace insenstive_) would result in randomized 4-digit uppercase letters, like, `ZAKH`, `UJSL`... etc. +* `randomize('AAAA')` is equivelant to `randomize('A', 4)` +* `randomize('AAA0')` and `randomize('AA00')` and `randomize('A0A0')` are equivelant to `randomize('A0', 4)` +* `randomize('aa')`: results in double-digit, randomized, lower-case letters (`abcdefghijklmnopqrstuvwxyz`) +* `randomize('AAA')`: results in triple-digit, randomized, upper-case letters (`ABCDEFGHIJKLMNOPQRSTUVWXYZ`) +* `randomize('0', 6)`: results in six-digit, randomized numbers (`0123456789`) +* `randomize('!', 5)`: results in single-digit randomized, _valid_ non-letter characters (`~!@#$%^&()_+-={}[] +* `randomize('A!a0', 9)`: results in nine-digit, randomized characters (any of the above) + +_The order in which the characters are defined is insignificant._ + +## About + +
+Contributing + +Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). + +
+ +
+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 +``` + +
+ +
+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 +``` + +
+ +### Related projects + +You might also be interested in these projects: + +* [pad-left](https://www.npmjs.com/package/pad-left): Left pad a string with zeros or a specified string. Fastest implementation. | [homepage](https://github.com/jonschlinkert/pad-left "Left pad a string with zeros or a specified string. Fastest implementation.") +* [pad-right](https://www.npmjs.com/package/pad-right): Right pad a string with zeros or a specified string. Fastest implementation. | [homepage](https://github.com/jonschlinkert/pad-right "Right pad a string with zeros or a specified string. Fastest implementation.") +* [repeat-string](https://www.npmjs.com/package/repeat-string): Repeat the given string n times. Fastest implementation for repeating a string. | [homepage](https://github.com/jonschlinkert/repeat-string "Repeat the given string n times. Fastest implementation for repeating a string.") + +### Contributors + +| **Commits** | **Contributor** | +| --- | --- | +| 56 | [jonschlinkert](https://github.com/jonschlinkert) | +| 6 | [doowb](https://github.com/doowb) | +| 4 | [kivlor](https://github.com/kivlor) | +| 2 | [realityking](https://github.com/realityking) | +| 2 | [ywpark1](https://github.com/ywpark1) | +| 1 | [TrySound](https://github.com/TrySound) | +| 1 | [drag0s](https://github.com/drag0s) | +| 1 | [paulmillr](https://github.com/paulmillr) | +| 1 | [sunknudsen](https://github.com/sunknudsen) | +| 1 | [faizulhaque-tp](https://github.com/faizulhaque-tp) | +| 1 | [michaelrhodes](https://github.com/michaelrhodes) | + +### Author + +**Jon Schlinkert** + +* [GitHub Profile](https://github.com/jonschlinkert) +* [Twitter Profile](https://twitter.com/jonschlinkert) +* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) + +### License + +Copyright © 2018, [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.8.0, on October 23, 2018._ \ No newline at end of file diff --git a/node_modules/randomatic/index.js b/node_modules/randomatic/index.js new file mode 100644 index 0000000..dc636fb --- /dev/null +++ b/node_modules/randomatic/index.js @@ -0,0 +1,95 @@ +/*! + * randomatic + * + * Copyright (c) 2014-2017, Jon Schlinkert. + * Released under the MIT License. + */ + +'use strict'; + +var isNumber = require('is-number'); +var typeOf = require('kind-of'); +var mathRandom = require('math-random'); + +/** + * Expose `randomatic` + */ + +module.exports = randomatic; +module.exports.isCrypto = !!mathRandom.cryptographic; + +/** + * Available mask characters + */ + +var type = { + lower: 'abcdefghijklmnopqrstuvwxyz', + upper: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', + number: '0123456789', + special: '~!@#$%^&()_+-={}[];\',.' +}; + +type.all = type.lower + type.upper + type.number + type.special; + +/** + * Generate random character sequences of a specified `length`, + * based on the given `pattern`. + * + * @param {String} `pattern` The pattern to use for generating the random string. + * @param {String} `length` The length of the string to generate. + * @param {String} `options` + * @return {String} + * @api public + */ + +function randomatic(pattern, length, options) { + if (typeof pattern === 'undefined') { + throw new Error('randomatic expects a string or number.'); + } + + var custom = false; + if (arguments.length === 1) { + if (typeof pattern === 'string') { + length = pattern.length; + + } else if (isNumber(pattern)) { + options = {}; + length = pattern; + pattern = '*'; + } + } + + if (typeOf(length) === 'object' && length.hasOwnProperty('chars')) { + options = length; + pattern = options.chars; + length = pattern.length; + custom = true; + } + + var opts = options || {}; + var mask = ''; + var res = ''; + + // Characters to be used + if (pattern.indexOf('?') !== -1) mask += opts.chars; + if (pattern.indexOf('a') !== -1) mask += type.lower; + if (pattern.indexOf('A') !== -1) mask += type.upper; + if (pattern.indexOf('0') !== -1) mask += type.number; + if (pattern.indexOf('!') !== -1) mask += type.special; + if (pattern.indexOf('*') !== -1) mask += type.all; + if (custom) mask += pattern; + + // Characters to exclude + if (opts.exclude) { + var exclude = typeOf(opts.exclude) === 'string' ? opts.exclude : opts.exclude.join(''); + exclude = exclude.replace(new RegExp('[\\]]+', 'g'), ''); + mask = mask.replace(new RegExp('[' + exclude + ']+', 'g'), ''); + + if(opts.exclude.indexOf(']') !== -1) mask = mask.replace(new RegExp('[\\]]+', 'g'), ''); + } + + while (length--) { + res += mask.charAt(parseInt(mathRandom() * mask.length, 10)); + } + return res; +}; diff --git a/node_modules/randomatic/package.json b/node_modules/randomatic/package.json new file mode 100644 index 0000000..72cb936 --- /dev/null +++ b/node_modules/randomatic/package.json @@ -0,0 +1,136 @@ +{ + "_from": "randomatic", + "_id": "randomatic@3.1.1", + "_inBundle": false, + "_integrity": "sha512-TuDE5KxZ0J461RVjrJZCJc+J+zCkTb1MbH9AQUq68sMhOMcy9jLcb3BrZKgp9q9Ncltdg4QVqWrH02W2EFFVYw==", + "_location": "/randomatic", + "_phantomChildren": {}, + "_requested": { + "type": "tag", + "registry": true, + "raw": "randomatic", + "name": "randomatic", + "escapedName": "randomatic", + "rawSpec": "", + "saveSpec": null, + "fetchSpec": "latest" + }, + "_requiredBy": [ + "#USER", + "/" + ], + "_resolved": "https://registry.npmjs.org/randomatic/-/randomatic-3.1.1.tgz", + "_shasum": "b776efc59375984e36c537b2f51a1f0aff0da1ed", + "_spec": "randomatic", + "_where": "/Users/conuegbu/Projects/async-thread", + "author": { + "name": "Jon Schlinkert", + "url": "https://github.com/jonschlinkert" + }, + "bugs": { + "url": "https://github.com/jonschlinkert/randomatic/issues" + }, + "bundleDependencies": false, + "contributors": [ + { + "name": "Bogdan Chadkin", + "url": "https://github.com/TrySound" + }, + { + "name": "Dragos Fotescu", + "url": "http://dragosfotescu.com" + }, + { + "name": "Faiz ul haque", + "url": "http://www.10pearls.com" + }, + { + "name": "Jon Schlinkert", + "url": "http://twitter.com/jonschlinkert" + }, + { + "name": "Michael Rhodes", + "url": "http://michaelrhod.es" + }, + { + "name": "Paul Miller", + "url": "https://paulmillr.com" + }, + { + "name": "Rouven Weßling", + "url": "www.rouvenwessling.de" + }, + { + "name": "Sun Knudsen", + "url": "https://sunknudsen.com" + } + ], + "dependencies": { + "is-number": "^4.0.0", + "kind-of": "^6.0.0", + "math-random": "^1.0.1" + }, + "deprecated": false, + "description": "Generate randomized strings of a specified length using simple character sequences. The original generate-password.", + "devDependencies": { + "ansi-bold": "^0.1.1", + "benchmarked": "^1.1.1", + "glob": "^7.1.2", + "gulp-format-md": "^0.1.12", + "mocha": "^3.4.2" + }, + "engines": { + "node": ">= 0.10.0" + }, + "files": [ + "index.js" + ], + "homepage": "https://github.com/jonschlinkert/randomatic", + "keywords": [ + "alpha", + "alpha-numeric", + "alphanumeric", + "characters", + "chars", + "generate", + "generate-password", + "numeric", + "password", + "rand", + "random", + "randomatic", + "randomize", + "randomized" + ], + "license": "MIT", + "main": "index.js", + "name": "randomatic", + "repository": { + "type": "git", + "url": "git+https://github.com/jonschlinkert/randomatic.git" + }, + "scripts": { + "test": "mocha" + }, + "verb": { + "toc": false, + "layout": "default", + "tasks": [ + "readme" + ], + "plugins": [ + "gulp-format-md" + ], + "related": { + "list": [ + "pad-left", + "pad-right", + "repeat-string" + ] + }, + "lint": { + "reflinks": true + } + }, + "version": "3.1.1" +} diff --git a/package-lock.json b/package-lock.json index ad4eced..40e5731 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,31 @@ "integrity": "sha512-53ElVDSnZeFUUFIYzI8WLQ25IhWzb6vbddNp8UHlXQyU0ET2RhV5zg0NfubzU7iNMh5bBXb0htCzfvrSVNgzaQ==", "dev": true }, + "is-number": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-4.0.0.tgz", + "integrity": "sha512-rSklcAIlf1OmFdyAqbnWTLVelsQ58uvZ66S/ZyawjWqIviTWCjg2PzVGw8WUA+nNuPTqb4wgA+NszrJ+08LlgQ==" + }, + "kind-of": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", + "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==" + }, + "math-random": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/math-random/-/math-random-1.0.1.tgz", + "integrity": "sha1-izqsWIuKZuSXXjzepn97sylgH6w=" + }, + "randomatic": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/randomatic/-/randomatic-3.1.1.tgz", + "integrity": "sha512-TuDE5KxZ0J461RVjrJZCJc+J+zCkTb1MbH9AQUq68sMhOMcy9jLcb3BrZKgp9q9Ncltdg4QVqWrH02W2EFFVYw==", + "requires": { + "is-number": "^4.0.0", + "kind-of": "^6.0.0", + "math-random": "^1.0.1" + } + }, "tslib": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", diff --git a/package.json b/package.json index a3e5cb0..5d798d2 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "@types/node": "^10.12.2" }, "dependencies": { + "randomatic": "^3.1.1", "tslib": "^1.9.3" } } diff --git a/src/context.ts b/src/context.ts index 26d34f9..742a4a1 100644 --- a/src/context.ts +++ b/src/context.ts @@ -1,46 +1,160 @@ import {cpus} from 'os'; +import randomatic = require('randomatic'); import { ThreadedFunction } from 'src/index'; import {Worker} from 'worker_threads'; const CPU_COUNT = cpus.length; +const WORKER_FILE = __dirname + '/worker'; -export function createContext(): ThreadContext { - const workerFile = __dirname + '/worker'; +export enum Actions { + CREATE_FUNCTION, + CREATE_FUNCTION_FAIL, + CREATE_FUNCTION_SUCCEED, +} - const threads = Array(CPU_COUNT).fill(0).map(() => { - return new Worker(workerFile); +export function createContext(): ThreadContext { + let threads: WorkerThread[] | null = Array(CPU_COUNT).fill(0).map(() => { + return new WorkerThread(); }); function ensureNotDestroyed() { - if (threads.length === 0) { + if (threads === null || threads.length === 0) { throw new Error('This context has been destroyed already'); } } return { createThreadedFunction(fn: (...args: A) => R): ThreadedFunction { - + // Create a unique identifier for this function + ensureNotDestroyed(); + const fnId = randomatic('Aa0', 32); + threads!.forEach((thread) => { + thread.postMessage({ + action: Actions.CREATE_FUNCTION, + id: fnId, + definition: fn.toString(), + }); + }); }, async destroyContext() { ensureNotDestroyed(); - const terminateAll = threads.map((thread) => { + const terminateAll = threads!.map((thread) => { return new Promise((res, rej) => { - thread.terminate((err: Error) => { + thread.terminate((err: Error, exitCode: number) => { if (err) { rej(err); } + + res(exitCode); }); }); }); await Promise.all(terminateAll); - threads.splice(0, threads.length); + threads = null; } }; } +function generateFunctionId(): CallId { + return randomatic('Aa0', 8); +} + +interface CallId extends String {} + +interface FunctionId extends String {} + +type FunctionCreateLog = Map; + +type CallLog = Map; + +type CallbackPair = { + fail: (reason?: unknown) => unknown; + success: (result: unknown) => unknown; +}; + +class WorkerThread { + private worker: Worker | null; + + private callLog: CallLog = new Map(); + + private functionCreateLog: FunctionCreateLog = new Map(); + + constructor() { + this.worker = new Worker(WORKER_FILE); + this.setupListeners(); + } + + private setupListeners() { + this.ensureNotDestroyed(); + this.worker!.on('message', (message: ThreadMessage) => { + switch(message.action) { + case Actions.CREATE_FUNCTION_FAIL: + this.createFunctionFail(message.fnId, message.error); + break; + case Actions.CREATE_FUNCTION_SUCCEED: + } + }); + } + + private createFunctionFail(functionId: CallId, error: string) { + const callbacks = this.callLog.get(functionId); + + if (!callbacks) { + // callback not found, log error and fail silently + console.error('Function creation failed, but callback not found'); + return; + } + + this.callLog.delete(functionId); + callbacks.fail() + } + + private createFunctionSucceed(functionId: CallId) { + const callbacks = this.callLog.get(functionId); + + if (!callbacks) { + // callback not found, log error and fail silently + console.error('Function creation succeeded, but callback not found'); + return; + } + + this.callLog.delete(functionId); + callbacks.fail() + } + + ensureNotDestroyed() { + if (this.worker === null) { + throw new Error('This thread has been destroyed already'); + } + } + + createFunction(fn: Function) { + const fnId = generateFunctionId(); + + return new Promise((res, rej) => { + this.ensureNotDestroyed(); + this.worker!.postMessage({ + action: Actions.CREATE_FUNCTION, + id: fnId, + definition: fn.toString(), + }); + + this.callLog.set(fnId, { + fail: rej, + success: res, + }); + }); + } +} + export interface ThreadContext { createThreadedFunction(fn: (...args: A) => R): ThreadedFunction; destroyContext(): Promise; } + +export type ThreadMessage = { + action: Actions; + [key: string]: any; +}; diff --git a/src/modules/randomatic.d.ts b/src/modules/randomatic.d.ts new file mode 100644 index 0000000..b959c01 --- /dev/null +++ b/src/modules/randomatic.d.ts @@ -0,0 +1,5 @@ +declare module 'randomatic' { + export = randomatic; + + function randomatic(pattern: string, length?: number): string; +} diff --git a/src/worker.ts b/src/worker.ts index 67c8f61..fb4da61 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -1,8 +1,40 @@ -export function createContext(): ThreadContext { +import { isMainThread, parentPort } from 'worker_threads'; +import { ThreadMessage, Actions } from './context'; +if (isMainThread || !parentPort) { + throw new Error('Worker must not be a main thread'); } -export interface ThreadContext { - createThreadedFunction(fn: (...args: A) => R): ThreadedFunction; - destroyContext(): void; -} +const functions: {[k: string]: Function} = {}; + +parentPort.on('message', (message: ThreadMessage) => { + switch(message.action) { + case Actions.CREATE_FUNCTION: + try { + const id = message.id; + + if (!id) { + throw new Error('Invalid functon ID'); + } + + if (functions[id]) { + throw new Error(`Function with ID ${id} already exists`); + } + + functions[id] = eval(message.definition); + + parentPort!.postMessage({ + action: Actions.CREATE_FUNCTION_FAIL, + id: message.id, + }); + } catch (e) { + parentPort!.postMessage({ + action: Actions.CREATE_FUNCTION_SUCCEED, + id: message.id, + }); + } + break; + default: + throw new Error('Invalid message received'); + } +});