include node_modules so release .zip is deployable

This commit is contained in:
2023-11-24 17:44:25 -05:00
parent 6c86cfe5d2
commit 8b11c41267
8963 changed files with 874175 additions and 1 deletions
Generated Vendored Executable
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Vladimir Kruzhkov @morglod
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.
Generated Vendored Executable
+96
View File
@@ -0,0 +1,96 @@
[![NPM Version](https://badge.fury.io/js/tseep.svg?style=flat)](https://www.npmjs.com/package/tseep)
[![GitHub stars](https://img.shields.io/github/stars/Morglod/tseep.svg?style=social&label=Star)](https://GitHub.com/Morglod/tseep/)
# tseep
Because there are N fastest event emitters. And we are fastest (feb 2023) 😏.
Up to **x12** faster than `eventemitter3` in terms of "classic api event emitters" (currently fastest for not classic too).
---
- Fully typed args of `emit` method based on events map
- Fully implements `NodeJS.EventEmitter` type & standart, provides interface
- Worlds fastest pure-js `EventEmitter`
- Fully tested with eventemitter3 tests
- No external deps
[how it works](./docs/how_it_works_en.md)
## Benchmarks
emit-multiple-listeners:
```
tseep x 40,569,711 ops/sec <---
EventEmitter1 x 4,498,223 ops/sec
EventEmitter2 x 4,536,296 ops/sec
EventEmitter3 x 5,852,395 ops/sec
fastemitter x 6,127,215 ops/sec
event-emitter x 3,449,595 ops/sec
contra/emitter x 2,186,002 ops/sec
tsee x 5,231,167 ops/sec
emitix x 6,549,983 ops/sec
Fastest is [ 'tseep' ]
```
[benchmarks](./benchmarks/README.md)
Make an issue to include yours event emitter, lets find the fastest!
## Install & use
```
npm i tseep
```
Simple usage:
```ts
import { EventEmitter } from "tseep";
const events = new EventEmitter<{
foo: (a: number, b: string) => void;
}>();
// foo's arguments is fully type checked
events.emit("foo", 123, "hello world");
```
## Api
`EventEmitter<T>` where `T` extends `{ [eventName]: Call signature }`.
`EventEmitter.emit`'s args is fully typed based on events map.
!! **`__proto__`** event name is restricted (type guard exists) !!
```ts
// Listener = (...args: any[]) => Promise<any>|void
// EventMap extends { [event in (string|symbol)]: Listener }
class EventEmitter<EventMap> {
readonly maxListeners: number;
readonly _eventsCount: number;
emit(event: EventKey, ...args: ArgsN<EventMap[EventKey]>): boolean;
on(event: EventKey, listener: EventMap[EventKey]): this;
once(event: EventKey, listener: EventMap[EventKey]): this;
addListener(event: EventKey, listener: EventMap[EventKey], argsNum?: ArgsNum<EventMap[EventKey]>): this;
removeListener(event: EventKey, listener: EventMap[EventKey]): this;
hasListeners(event: EventKey): boolean;
prependListener(event: EventKey, listener: EventMap[EventKey]): this;
prependOnceListener(event: EventKey, listener: EventMap[EventKey]): this;
off(event: EventKey, listener: EventMap[EventKey]): this;
removeAllListeners(event?: EventKey): this;
setMaxListeners(n: number): this;
getMaxListeners(): number;
listeners(event: EventKey): EventMap[EventKey][];
rawListeners(event: EventKey): EventMap[EventKey][];
eventNames(): Array<string | symbol>;
listenerCount(type: EventKey): number;
}
```
## License
MIT
+31
View File
@@ -0,0 +1,31 @@
import { DefaultEventMap, IEventEmitter } from './index';
import { TaskCollection } from './task-collection';
import { ArgsNum } from './utils';
/** Implemented event emitter */
export declare class EventEmitter<EventMap extends DefaultEventMap = DefaultEventMap> implements IEventEmitter<EventMap> {
events: {
[eventName in keyof EventMap]?: TaskCollection<EventMap[eventName]>;
};
onceEvents: {
[eventName in keyof EventMap]?: (EventMap[eventName][]) | EventMap[eventName];
};
_symbolKeys: Set<symbol>;
maxListeners: number;
get _eventsCount(): number;
emit: <EventKey extends keyof EventMap>(event: EventKey, ...args: Parameters<EventMap[EventKey]>) => boolean;
on: <EventKey extends keyof EventMap = string>(event: EventKey, listener: EventMap[EventKey]) => this;
once: <EventKey extends keyof EventMap = string>(event: EventKey, listener: EventMap[EventKey]) => this;
addListener: <EventKey extends keyof EventMap = string>(event: EventKey, listener: EventMap[EventKey], argsNum?: ArgsNum<EventMap[EventKey]>) => this;
removeListener: <EventKey extends keyof EventMap = string>(event: EventKey, listener: EventMap[EventKey]) => this;
hasListeners: <EventKey extends keyof EventMap = string>(event: EventKey) => boolean;
prependListener: <EventKey extends keyof EventMap = string>(event: EventKey, listener: EventMap[EventKey]) => this;
prependOnceListener: <EventKey extends keyof EventMap = string>(event: EventKey, listener: EventMap[EventKey]) => this;
off: <EventKey extends keyof EventMap = string>(event: EventKey, listener: EventMap[EventKey]) => this;
removeAllListeners: <EventKey extends keyof EventMap = string>(event?: EventKey) => this;
setMaxListeners: (n: number) => this;
getMaxListeners: () => number;
listeners: <EventKey extends keyof EventMap = string>(event: EventKey) => EventMap[EventKey][];
rawListeners: <EventKey extends keyof EventMap = string>(event: EventKey) => EventMap[EventKey][];
eventNames: () => Array<string | symbol>;
listenerCount: <EventKey extends keyof EventMap = string>(type: EventKey) => number;
}
+254
View File
@@ -0,0 +1,254 @@
"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EventEmitter = void 0;
var task_collection_1 = require("./task-collection");
var utils_1 = require("./utils");
function emit(event, a, b, c, d, e) {
var ev = this.events[event];
if (ev) {
if (ev.length === 0)
return false;
if (ev.argsNum < 6) {
ev.call(a, b, c, d, e);
}
else {
ev.call.apply(undefined, arguments);
}
return true;
}
return false;
}
function emitHasOnce(event, a, b, c, d, e) {
var ev = this.events[event];
if (ev) {
if (ev.length === 0)
return false;
if (ev.argsNum < 6) {
ev.call(a, b, c, d, e);
}
else {
ev.call.apply(undefined, arguments);
}
}
var oev = this.onceEvents[event];
if (oev) {
if (typeof oev === 'function') {
this.onceEvents[event] = undefined;
if (arguments.length < 6) {
oev(a, b, c, d, e);
}
else {
oev.apply(undefined, arguments);
}
}
else {
var fncs = oev;
this.onceEvents[event] = undefined;
if (arguments.length < 6) {
for (var i = 0; i < fncs.length; ++i)
fncs[i](a, b, c, d, e);
}
else {
for (var i = 0; i < fncs.length; ++i)
fncs[i].apply(undefined, arguments);
}
}
return true;
}
return !!ev;
}
/** Implemented event emitter */
var EventEmitter = /** @class */ (function () {
function EventEmitter() {
this.events = (0, utils_1.nullObj)();
this.onceEvents = (0, utils_1.nullObj)();
this._symbolKeys = new Set;
this.maxListeners = Infinity;
}
Object.defineProperty(EventEmitter.prototype, "_eventsCount", {
get: function () {
return this.eventNames().length;
},
enumerable: false,
configurable: true
});
return EventEmitter;
}());
exports.EventEmitter = EventEmitter;
function once(event, listener) {
if (this.emit === emit) {
this.emit = emitHasOnce;
}
switch (typeof this.onceEvents[event]) {
case 'undefined':
this.onceEvents[event] = listener;
if (typeof event === 'symbol')
this._symbolKeys.add(event);
break;
case 'function':
this.onceEvents[event] = [this.onceEvents[event], listener];
break;
case 'object':
this.onceEvents[event].push(listener);
}
return this;
}
function addListener(event, listener, argsNum) {
if (argsNum === void 0) { argsNum = listener.length; }
if (typeof listener !== 'function')
throw new TypeError('The listener must be a function');
var evtmap = this.events[event];
if (!evtmap) {
this.events[event] = new task_collection_1.TaskCollection(argsNum, true, listener, false);
if (typeof event === 'symbol')
this._symbolKeys.add(event);
}
else {
evtmap.push(listener);
evtmap.growArgsNum(argsNum);
if (this.maxListeners !== Infinity && this.maxListeners <= evtmap.length)
console.warn("Maximum event listeners for \"".concat(String(event), "\" event!"));
}
return this;
}
function removeListener(event, listener) {
var evt = this.events[event];
if (evt) {
evt.removeLast(listener);
}
var evto = this.onceEvents[event];
if (evto) {
if (typeof evto === 'function') {
this.onceEvents[event] = undefined;
}
else if (typeof evto === 'object') {
if (evto.length === 1 && evto[0] === listener) {
this.onceEvents[event] = undefined;
}
else {
(0, task_collection_1._fast_remove_single)(evto, evto.lastIndexOf(listener));
}
}
}
return this;
}
function hasListeners(event) {
return this.events[event] && !!this.events[event].length;
}
function prependListener(event, listener, argsNum) {
if (argsNum === void 0) { argsNum = listener.length; }
if (typeof listener !== 'function')
throw new TypeError('The listener must be a function');
var evtmap = this.events[event];
if (!evtmap || !(evtmap instanceof task_collection_1.TaskCollection)) {
evtmap = this.events[event] = new task_collection_1.TaskCollection(argsNum, true, listener, false);
if (typeof event === 'symbol')
this._symbolKeys.add(event);
}
else {
evtmap.insert(0, listener);
evtmap.growArgsNum(argsNum);
if (this.maxListeners !== Infinity && this.maxListeners <= evtmap.length)
console.warn("Maximum event listeners for \"".concat(String(event), "\" event!"));
}
return this;
}
function prependOnceListener(event, listener) {
if (this.emit === emit) {
this.emit = emitHasOnce;
}
var evtmap = this.onceEvents[event];
if (!evtmap || typeof evtmap !== 'object') {
evtmap = this.onceEvents[event] = [listener];
if (typeof event === 'symbol')
this._symbolKeys.add(event);
}
else {
// FIXME:
throw new Error('FIXME');
// evtmap.unshift(listener);
if (this.maxListeners !== Infinity && this.maxListeners <= evtmap.length)
console.warn("Maximum event listeners for \"".concat(String(event), "\" once event!"));
}
return this;
}
function removeAllListeners(event) {
if (event === undefined) {
this.events = (0, utils_1.nullObj)();
this.onceEvents = (0, utils_1.nullObj)();
this._symbolKeys = new Set;
}
else {
this.events[event] = undefined;
this.onceEvents[event] = undefined;
if (typeof event === 'symbol')
this._symbolKeys.delete(event);
}
return this;
}
function setMaxListeners(n) {
this.maxListeners = n;
return this;
}
function getMaxListeners() {
return this.maxListeners;
}
function listeners(event) {
if (this.emit === emit)
return this.events[event] ? this.events[event].tasksAsArray().slice() : [];
else {
if (this.events[event] && this.onceEvents[event]) {
return __spreadArray(__spreadArray([], this.events[event].tasksAsArray(), true), (typeof this.onceEvents[event] === 'function' ? [this.onceEvents[event]] : this.onceEvents[event]), true);
}
else if (this.events[event])
return this.events[event].tasksAsArray();
else if (this.onceEvents[event])
return (typeof this.onceEvents[event] === 'function' ? [this.onceEvents[event]] : this.onceEvents[event]);
else
return [];
}
}
function eventNames() {
var _this = this;
if (this.emit === emit) {
var keys = Object.keys(this.events);
return __spreadArray(__spreadArray([], keys, true), Array.from(this._symbolKeys), true).filter(function (x) { return (x in _this.events) && _this.events[x] && _this.events[x].length; });
}
else {
var keys = Object.keys(this.events).filter(function (x) { return _this.events[x] && _this.events[x].length; });
var keysO = Object.keys(this.onceEvents).filter(function (x) { return _this.onceEvents[x] && _this.onceEvents[x].length; });
return __spreadArray(__spreadArray(__spreadArray([], keys, true), keysO, true), Array.from(this._symbolKeys).filter(function (x) { return (((x in _this.events) && _this.events[x] && _this.events[x].length) ||
((x in _this.onceEvents) && _this.onceEvents[x] && _this.onceEvents[x].length)); }), true);
}
}
function listenerCount(type) {
if (this.emit === emit)
return this.events[type] && this.events[type].length || 0;
else
return (this.events[type] && this.events[type].length || 0) + (this.onceEvents[type] && this.onceEvents[type].length || 0);
}
EventEmitter.prototype.emit = emit;
EventEmitter.prototype.on = addListener;
EventEmitter.prototype.once = once;
EventEmitter.prototype.addListener = addListener;
EventEmitter.prototype.removeListener = removeListener;
EventEmitter.prototype.hasListeners = hasListeners;
EventEmitter.prototype.prependListener = prependListener;
EventEmitter.prototype.prependOnceListener = prependOnceListener;
EventEmitter.prototype.off = removeListener;
EventEmitter.prototype.removeAllListeners = removeAllListeners;
EventEmitter.prototype.setMaxListeners = setMaxListeners;
EventEmitter.prototype.getMaxListeners = getMaxListeners;
EventEmitter.prototype.listeners = listeners;
EventEmitter.prototype.eventNames = eventNames;
EventEmitter.prototype.listenerCount = listenerCount;
//# sourceMappingURL=ee.js.map
+1
View File
File diff suppressed because one or more lines are too long
+2
View File
@@ -0,0 +1,2 @@
export * from './types';
export * from './ee';
+19
View File
@@ -0,0 +1,19 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./types"), exports);
__exportStar(require("./ee"), exports);
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,uCAAqB"}
+1
View File
@@ -0,0 +1 @@
export {};
+41
View File
@@ -0,0 +1,41 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var tseep = __importStar(require("./"));
var ee = new tseep.EventEmitter();
function handler(a, b, c) {
if (arguments.length > 10)
throw new Error('aaa');
}
for (var i = 0; i < 9999999999; ++i) {
for (var j = 0; j < 99999; ++j) {
ee.on('foo', handler);
}
for (var j = 0; j < 99999; ++j) {
ee.off('foo', handler);
}
}
console.log('ok');
//# sourceMappingURL=opt-playground.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"opt-playground.js","sourceRoot":"","sources":["../src/opt-playground.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wCAA4B;AAE5B,IAAM,EAAE,GAAG,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;AAEpC,SAAS,OAAO,CAAC,CAAM,EAAC,CAAM,EAAC,CAAM;IACjC,IAAI,SAAS,CAAC,MAAM,GAAG,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;AACtD,CAAC;AAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,EAAE,EAAE,CAAC,EAAE;IACjC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,EAAE,CAAC,EAAE;QAC5B,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;KACzB;IACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,EAAE,CAAC,EAAE;QAC5B,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;KAC1B;CACJ;AAED,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC"}
+3
View File
@@ -0,0 +1,3 @@
export declare function patchEE3(): void;
export declare function patchEvents(): void;
export declare function patchAll(): void;
+34
View File
@@ -0,0 +1,34 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.patchAll = exports.patchEvents = exports.patchEE3 = void 0;
var ee_1 = require("./ee");
function patchEE3() {
try {
var ee3 = require('eventemitter3');
if (ee3) {
ee3.EventEmitter = ee_1.EventEmitter;
}
}
catch (err) {
console.error(err);
}
}
exports.patchEE3 = patchEE3;
function patchEvents() {
try {
var ee = require('events');
if (ee) {
ee.EventEmitter = ee_1.EventEmitter;
}
}
catch (err) {
console.error(err);
}
}
exports.patchEvents = patchEvents;
function patchAll() {
patchEE3();
patchEvents();
}
exports.patchAll = patchAll;
//# sourceMappingURL=patch.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../src/patch.ts"],"names":[],"mappings":";;;AAAA,2BAAoC;AAEpC,SAAgB,QAAQ;IACpB,IAAI;QACA,IAAM,GAAG,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;QACrC,IAAI,GAAG,EAAE;YACL,GAAG,CAAC,YAAY,GAAG,iBAAY,CAAC;SACnC;KACJ;IAAC,OAAM,GAAG,EAAE;QACT,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;KACtB;AACL,CAAC;AATD,4BASC;AAED,SAAgB,WAAW;IACvB,IAAI;QACA,IAAM,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC7B,IAAI,EAAE,EAAE;YACJ,EAAE,CAAC,YAAY,GAAG,iBAAY,CAAC;SAClC;KACJ;IAAC,OAAM,GAAG,EAAE;QACT,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;KACtB;AACL,CAAC;AATD,kCASC;AAED,SAAgB,QAAQ;IACpB,QAAQ,EAAE,CAAC;IACX,WAAW,EAAE,CAAC;AAClB,CAAC;AAHD,4BAGC"}
+5
View File
@@ -0,0 +1,5 @@
import { ArgsNum } from "../utils";
export declare const BAKED_EMPTY_FUNC: () => void;
export declare function bakeCollection<Func extends (...args: any) => void>(collection: Func[], fixedArgsNum: ArgsNum<Func>): (...args: Parameters<Func>) => void;
export declare function bakeCollectionAwait<Func extends (...args: any) => void>(collection: Func[], fixedArgsNum: ArgsNum<Func>): (...args: Parameters<Func>) => Promise<void>;
export declare function bakeCollectionVariadic<Func extends (...args: any) => void>(collection: Func[]): (...args: Parameters<Func>) => void;
+120
View File
@@ -0,0 +1,120 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.bakeCollectionVariadic = exports.bakeCollectionAwait = exports.bakeCollection = exports.BAKED_EMPTY_FUNC = void 0;
exports.BAKED_EMPTY_FUNC = (function () { });
var FORLOOP_FALLBACK = 1500;
function generateArgsDefCode(numArgs) {
var argsDefCode = '';
if (numArgs === 0)
return argsDefCode;
for (var i = 0; i < numArgs - 1; ++i) {
argsDefCode += ('arg' + String(i) + ', ');
}
argsDefCode += ('arg' + String(numArgs - 1));
return argsDefCode;
}
function generateBodyPartsCode(argsDefCode, collectionLength) {
var funcDefCode = '', funcCallCode = '';
for (var i = 0; i < collectionLength; ++i) {
funcDefCode += "var f".concat(i, " = collection[").concat(i, "];\n");
funcCallCode += "f".concat(i, "(").concat(argsDefCode, ")\n");
}
return { funcDefCode: funcDefCode, funcCallCode: funcCallCode };
}
function generateBodyPartsVariadicCode(collectionLength) {
var funcDefCode = '', funcCallCode = '';
for (var i = 0; i < collectionLength; ++i) {
funcDefCode += "var f".concat(i, " = collection[").concat(i, "];\n");
funcCallCode += "f".concat(i, ".apply(undefined, arguments)\n");
}
return { funcDefCode: funcDefCode, funcCallCode: funcCallCode };
}
function bakeCollection(collection, fixedArgsNum) {
if (collection.length === 0)
return exports.BAKED_EMPTY_FUNC;
else if (collection.length === 1)
return collection[0];
var funcFactoryCode;
if (collection.length < FORLOOP_FALLBACK) {
var argsDefCode = generateArgsDefCode(fixedArgsNum);
var _a = generateBodyPartsCode(argsDefCode, collection.length), funcDefCode = _a.funcDefCode, funcCallCode = _a.funcCallCode;
funcFactoryCode = "(function(collection) {\n ".concat(funcDefCode, "\n collection = undefined;\n return (function(").concat(argsDefCode, ") {\n ").concat(funcCallCode, "\n });\n })");
}
else {
var argsDefCode = generateArgsDefCode(fixedArgsNum);
// loop unroll
if (collection.length % 10 === 0) {
funcFactoryCode = "(function(collection) {\n return (function(".concat(argsDefCode, ") {\n for (var i = 0; i < collection.length; i += 10) {\n collection[i](").concat(argsDefCode, ");\n collection[i+1](").concat(argsDefCode, ");\n collection[i+2](").concat(argsDefCode, ");\n collection[i+3](").concat(argsDefCode, ");\n collection[i+4](").concat(argsDefCode, ");\n collection[i+5](").concat(argsDefCode, ");\n collection[i+6](").concat(argsDefCode, ");\n collection[i+7](").concat(argsDefCode, ");\n collection[i+8](").concat(argsDefCode, ");\n collection[i+9](").concat(argsDefCode, ");\n }\n });\n })");
}
else if (collection.length % 4 === 0) {
funcFactoryCode = "(function(collection) {\n return (function(".concat(argsDefCode, ") {\n for (var i = 0; i < collection.length; i += 4) {\n collection[i](").concat(argsDefCode, ");\n collection[i+1](").concat(argsDefCode, ");\n collection[i+2](").concat(argsDefCode, ");\n collection[i+3](").concat(argsDefCode, ");\n }\n });\n })");
}
else if (collection.length % 3 === 0) {
funcFactoryCode = "(function(collection) {\n return (function(".concat(argsDefCode, ") {\n for (var i = 0; i < collection.length; i += 3) {\n collection[i](").concat(argsDefCode, ");\n collection[i+1](").concat(argsDefCode, ");\n collection[i+2](").concat(argsDefCode, ");\n }\n });\n })");
}
else {
funcFactoryCode = "(function(collection) {\n return (function(".concat(argsDefCode, ") {\n for (var i = 0; i < collection.length; ++i) {\n collection[i](").concat(argsDefCode, ");\n }\n });\n })");
}
}
{
// isolate
var bakeCollection_1 = undefined;
var fixedArgsNum_1 = undefined;
var bakeCollectionVariadic_1 = undefined;
var bakeCollectionAwait_1 = undefined;
var funcFactory = eval(funcFactoryCode);
return funcFactory(collection);
}
}
exports.bakeCollection = bakeCollection;
function bakeCollectionAwait(collection, fixedArgsNum) {
if (collection.length === 0)
return exports.BAKED_EMPTY_FUNC;
else if (collection.length === 1)
return collection[0];
var funcFactoryCode;
if (collection.length < FORLOOP_FALLBACK) {
var argsDefCode = generateArgsDefCode(fixedArgsNum);
var _a = generateBodyPartsCode(argsDefCode, collection.length), funcDefCode = _a.funcDefCode, funcCallCode = _a.funcCallCode;
funcFactoryCode = "(function(collection) {\n ".concat(funcDefCode, "\n collection = undefined;\n return (function(").concat(argsDefCode, ") {\n return Promise.all([ ").concat(funcCallCode, " ]);\n });\n })");
}
else {
var argsDefCode = generateArgsDefCode(fixedArgsNum);
funcFactoryCode = "(function(collection) {\n return (function(".concat(argsDefCode, ") {\n var promises = Array(collection.length);\n for (var i = 0; i < collection.length; ++i) {\n promises[i] = collection[i](").concat(argsDefCode, ");\n }\n return Promise.all(promises);\n });\n })");
}
{
// isolate
var bakeCollection_2 = undefined;
var fixedArgsNum_2 = undefined;
var bakeCollectionVariadic_2 = undefined;
var bakeCollectionAwait_2 = undefined;
var funcFactory = eval(funcFactoryCode);
return funcFactory(collection);
}
}
exports.bakeCollectionAwait = bakeCollectionAwait;
function bakeCollectionVariadic(collection) {
if (collection.length === 0)
return exports.BAKED_EMPTY_FUNC;
else if (collection.length === 1)
return collection[0];
var funcFactoryCode;
if (collection.length < FORLOOP_FALLBACK) {
var _a = generateBodyPartsVariadicCode(collection.length), funcDefCode = _a.funcDefCode, funcCallCode = _a.funcCallCode;
funcFactoryCode = "(function(collection) {\n ".concat(funcDefCode, "\n collection = undefined;\n return (function() {\n ").concat(funcCallCode, "\n });\n })");
}
else {
funcFactoryCode = "(function(collection) {\n return (function() {\n for (var i = 0; i < collection.length; ++i) {\n collection[i].apply(undefined, arguments);\n }\n });\n })";
}
{
// isolate
var bakeCollection_3 = undefined;
var fixedArgsNum = undefined;
var bakeCollectionVariadic_3 = undefined;
var bakeCollectionAwait_3 = undefined;
var funcFactory = eval(funcFactoryCode);
return funcFactory(collection);
}
}
exports.bakeCollectionVariadic = bakeCollectionVariadic;
//# sourceMappingURL=bake-collection.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"bake-collection.js","sourceRoot":"","sources":["../../src/task-collection/bake-collection.ts"],"names":[],"mappings":"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"}
+1
View File
@@ -0,0 +1 @@
export * from './task-collection';
+18
View File
@@ -0,0 +1,18 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./task-collection"), exports);
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/task-collection/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC"}
+33
View File
@@ -0,0 +1,33 @@
import { ArgsNum } from '../utils';
export declare function _fast_remove_single(arr: any[], index: number): void;
export declare class TaskCollection<Func extends (...args: any) => void, AwaitTasks extends true | false = false> {
readonly awaitTasks: AwaitTasks;
constructor(argsNum: ArgsNum<Func>, autoRebuild?: boolean, initialTasks?: (Func[]) | Func | null, awaitTasks?: AwaitTasks);
/** DO NOT CHANGE DIRECTLY */
_tasks: (Func[]) | Func | null;
/** cached */
length: number;
/** auto rebuild on first emit call; otherwise autorebuild on every change */
firstEmitBuildStrategy: boolean;
readonly argsNum: ArgsNum<Func>;
autoRebuild: boolean;
readonly growArgsNum: typeof growArgsNum;
setAutoRebuild: typeof setAutoRebuild;
call: (...args: Parameters<Func>) => (AwaitTasks extends true ? Promise<void> : void);
rebuild: () => void;
push: (...func: Func[]) => void;
/** remove last matched task from tasks */
removeLast: (func: Func) => void;
insert: (index: number, ...func: Func[]) => void;
setTasks: (tasks: Func[]) => void;
tasksAsArray: () => Func[];
/** this autorebuilds */
readonly clear: typeof clear;
/** this autorebuilds */
readonly fastClear: typeof fastClear;
}
declare function fastClear<Func extends (...args: any) => void, AwaitTasks extends true | false = false>(this: TaskCollection<Func, AwaitTasks>): void;
declare function clear<Func extends (...args: any) => void, AwaitTasks extends true | false = false>(this: TaskCollection<Func, AwaitTasks>): void;
declare function growArgsNum<Func extends (...args: any) => void, AwaitTasks extends true | false = false>(this: TaskCollection<Func, AwaitTasks>, argsNum: number): void;
declare function setAutoRebuild<Func extends (...args: any) => void, AwaitTasks extends true | false = false>(this: TaskCollection<Func, AwaitTasks>, newVal: boolean): void;
export {};
+313
View File
@@ -0,0 +1,313 @@
"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TaskCollection = exports._fast_remove_single = void 0;
var bake_collection_1 = require("./bake-collection");
function push_norebuild(a, b /*, ...func: Func[] */) {
var len = this.length;
if (len > 1) { // tasks is array
if (b) { // if multiple args
var _a;
(_a = this._tasks).push.apply(_a, arguments);
this.length += arguments.length;
}
else { // if single arg (most often case)
this._tasks.push(a);
this.length++;
}
}
else { // tasks is (function or null)
if (b) { // if multiple args
if (len === 1) { // if this._tasks is function
var newAr = Array(1 + arguments.length);
newAr.push(newAr);
newAr.push.apply(newAr, arguments);
this._tasks = newAr;
}
else {
var newAr = Array(arguments.length);
newAr.push.apply(newAr, arguments);
this._tasks = newAr;
}
this.length += arguments.length;
}
else { // if single arg (most often case)
if (len === 1)
this._tasks = [this._tasks, a];
else
this._tasks = a;
this.length++;
}
}
}
function push_rebuild(a, b /*, ...func: Func[] */) {
var len = this.length;
if (len > 1) { // tasks is array
if (b) { // if multiple args
var _a;
(_a = this._tasks).push.apply(_a, arguments);
this.length += arguments.length;
}
else { // if single arg (most often case)
this._tasks.push(a);
this.length++;
}
}
else { // tasks is (function or null)
if (b) { // if multiple args
if (len === 1) { // if this._tasks is function
var newAr = Array(1 + arguments.length);
newAr.push(newAr);
newAr.push.apply(newAr, arguments);
this._tasks = newAr;
}
else {
var newAr = Array(arguments.length);
newAr.push.apply(newAr, arguments);
this._tasks = newAr;
}
this.length += arguments.length;
}
else { // if single arg (most often case)
if (len === 1)
this._tasks = [this._tasks, a];
else
this._tasks = a;
this.length++;
}
}
if (this.firstEmitBuildStrategy)
this.call = rebuild_on_first_call;
else
this.rebuild();
}
function _fast_remove_single(arr, index) {
if (index === -1)
return;
if (index === 0)
arr.shift();
else if (index === arr.length - 1)
arr.length = arr.length - 1;
else
arr.splice(index, 1);
}
exports._fast_remove_single = _fast_remove_single;
function removeLast_norebuild(a) {
if (this.length === 0)
return;
if (this.length === 1) {
if (this._tasks === a) {
this.length = 0;
}
}
else {
_fast_remove_single(this._tasks, this._tasks.lastIndexOf(a));
if (this._tasks.length === 1) {
this._tasks = this._tasks[0];
this.length = 1;
}
else
this.length = this._tasks.length;
}
}
function removeLast_rebuild(a) {
if (this.length === 0)
return;
if (this.length === 1) {
if (this._tasks === a) {
this.length = 0;
}
if (this.firstEmitBuildStrategy) {
this.call = bake_collection_1.BAKED_EMPTY_FUNC;
return;
}
else {
this.rebuild();
return;
}
}
else {
_fast_remove_single(this._tasks, this._tasks.lastIndexOf(a));
if (this._tasks.length === 1) {
this._tasks = this._tasks[0];
this.length = 1;
}
else
this.length = this._tasks.length;
}
if (this.firstEmitBuildStrategy)
this.call = rebuild_on_first_call;
else
this.rebuild();
}
function insert_norebuild(index) {
var _b;
var func = [];
for (var _i = 1; _i < arguments.length; _i++) {
func[_i - 1] = arguments[_i];
}
if (this.length === 0) {
this._tasks = func;
this.length = 1;
}
else if (this.length === 1) {
func.unshift(this._tasks);
this._tasks = func;
this.length = this._tasks.length;
}
else {
(_b = this._tasks).splice.apply(_b, __spreadArray([index, 0], func, false));
this.length = this._tasks.length;
}
}
function insert_rebuild(index) {
var _b;
var func = [];
for (var _i = 1; _i < arguments.length; _i++) {
func[_i - 1] = arguments[_i];
}
if (this.length === 0) {
this._tasks = func;
this.length = 1;
}
else if (this.length === 1) {
func.unshift(this._tasks);
this._tasks = func;
this.length = this._tasks.length;
}
else {
(_b = this._tasks).splice.apply(_b, __spreadArray([index, 0], func, false));
this.length = this._tasks.length;
}
if (this.firstEmitBuildStrategy)
this.call = rebuild_on_first_call;
else
this.rebuild();
}
function rebuild_noawait() {
if (this.length === 0)
this.call = bake_collection_1.BAKED_EMPTY_FUNC;
else if (this.length === 1)
this.call = this._tasks;
else
this.call = (0, bake_collection_1.bakeCollection)(this._tasks, this.argsNum);
}
function rebuild_await() {
if (this.length === 0)
this.call = bake_collection_1.BAKED_EMPTY_FUNC;
else if (this.length === 1)
this.call = this._tasks;
else
this.call = (0, bake_collection_1.bakeCollectionAwait)(this._tasks, this.argsNum);
}
function rebuild_on_first_call() {
this.rebuild();
this.call.apply(undefined, arguments);
}
var TaskCollection = /** @class */ (function () {
function TaskCollection(argsNum, autoRebuild, initialTasks, awaitTasks) {
if (autoRebuild === void 0) { autoRebuild = true; }
if (initialTasks === void 0) { initialTasks = null; }
if (awaitTasks === void 0) { awaitTasks = false; }
this.awaitTasks = awaitTasks;
this.call = bake_collection_1.BAKED_EMPTY_FUNC;
this.argsNum = argsNum;
this.firstEmitBuildStrategy = true;
if (awaitTasks)
this.rebuild = rebuild_await.bind(this);
else
this.rebuild = rebuild_noawait.bind(this);
this.setAutoRebuild(autoRebuild);
if (initialTasks) {
if (typeof initialTasks === 'function') {
this._tasks = initialTasks;
this.length = 1;
}
else {
this._tasks = initialTasks;
this.length = initialTasks.length;
}
}
else {
this._tasks = null;
this.length = 0;
}
if (autoRebuild)
this.rebuild();
}
return TaskCollection;
}());
exports.TaskCollection = TaskCollection;
function fastClear() {
this._tasks = null;
this.length = 0;
this.call = bake_collection_1.BAKED_EMPTY_FUNC;
}
function clear() {
this._tasks = null;
this.length = 0;
this.call = bake_collection_1.BAKED_EMPTY_FUNC;
}
function growArgsNum(argsNum) {
if (this.argsNum < argsNum) {
this.argsNum = argsNum;
if (this.firstEmitBuildStrategy)
this.call = rebuild_on_first_call;
else
this.rebuild();
}
}
function setAutoRebuild(newVal) {
if (newVal) {
this.push = push_rebuild.bind(this);
this.insert = insert_rebuild.bind(this);
this.removeLast = removeLast_rebuild.bind(this);
}
else {
this.push = push_norebuild.bind(this);
this.insert = insert_norebuild.bind(this);
this.removeLast = removeLast_norebuild.bind(this);
}
}
;
function tasksAsArray() {
if (this.length === 0)
return [];
if (this.length === 1)
return [this._tasks];
return this._tasks;
}
function setTasks(tasks) {
if (tasks.length === 0) {
this.length = 0;
this.call = bake_collection_1.BAKED_EMPTY_FUNC;
}
else if (tasks.length === 1) {
this.length = 1;
this.call = tasks[0];
this._tasks = tasks[0];
}
else {
this.length = tasks.length;
this._tasks = tasks;
if (this.firstEmitBuildStrategy)
this.call = rebuild_on_first_call;
else
this.rebuild();
}
}
TaskCollection.prototype.fastClear = fastClear;
TaskCollection.prototype.clear = clear;
TaskCollection.prototype.growArgsNum = growArgsNum;
TaskCollection.prototype.setAutoRebuild = setAutoRebuild;
TaskCollection.prototype.tasksAsArray = tasksAsArray;
TaskCollection.prototype.setTasks = setTasks;
//# sourceMappingURL=task-collection.js.map
File diff suppressed because one or more lines are too long
+5
View File
@@ -0,0 +1,5 @@
export type NoReadonly<T extends {
[x: string]: any;
}> = {
-readonly [X in keyof T]: T[X];
};
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=utils.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/task-collection/utils.ts"],"names":[],"mappings":""}
+27
View File
@@ -0,0 +1,27 @@
export type Listener = (...args: any[]) => Promise<any> | void;
export type DefaultEventMap = {
[event in (string | symbol)]: Listener;
} & {
/**
* __proto__ key not allowed due to implementation
* add prefix, if you want to use this keyword
*/
__proto__?: never;
};
export interface IEventEmitter<EventMap extends DefaultEventMap = DefaultEventMap> {
emit<EventKey extends keyof EventMap>(event: EventKey, ...args: Parameters<EventMap[EventKey]>): boolean;
on<EventKey extends keyof EventMap = string>(event: EventKey, listener: EventMap[EventKey]): this;
once<EventKey extends keyof EventMap = string>(event: EventKey, listener: EventMap[EventKey]): this;
addListener<EventKey extends keyof EventMap = string>(event: EventKey, listener: EventMap[EventKey]): this;
removeListener<EventKey extends keyof EventMap = string>(event: EventKey, listener: EventMap[EventKey]): this;
prependListener<EventKey extends keyof EventMap = string>(event: EventKey, listener: EventMap[EventKey]): this;
prependOnceListener<EventKey extends keyof EventMap = string>(event: EventKey, listener: EventMap[EventKey]): this;
off<EventKey extends keyof EventMap = string>(event: EventKey, listener: EventMap[EventKey]): this;
removeAllListeners<EventKey extends keyof EventMap = string>(event?: EventKey): this;
setMaxListeners(n: number): this;
getMaxListeners(): number;
listeners<EventKey extends keyof EventMap = string>(event: EventKey): EventMap[EventKey][];
rawListeners<EventKey extends keyof EventMap = string>(event: EventKey): EventMap[EventKey][];
eventNames(): Array<string | symbol>;
listenerCount<EventKey extends keyof EventMap = string>(type: EventKey): number;
}
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
+2
View File
@@ -0,0 +1,2 @@
export declare function nullObj(): {};
export type ArgsNum<T extends (...args: any[]) => any> = T extends (...args: infer K) => any ? K["length"] : never;
+11
View File
@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.nullObj = void 0;
function nullObj() {
var x = {};
x.__proto__ = null;
x.prototype = null;
return x;
}
exports.nullObj = nullObj;
//# sourceMappingURL=utils.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AACA,SAAgB,OAAO;IACnB,IAAM,CAAC,GAAG,EAAE,CAAC;IACZ,CAAS,CAAC,SAAS,GAAG,IAAI,CAAC;IAC3B,CAAS,CAAC,SAAS,GAAG,IAAI,CAAC;IAC5B,OAAO,CAAC,CAAC;AACb,CAAC;AALD,0BAKC"}
Generated Vendored Executable
+40
View File
@@ -0,0 +1,40 @@
{
"name": "tseep",
"version": "1.1.3",
"description": "Fastest event emitter in the world",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"test": "jest",
"build": "tsc",
"task_collection_dev_benchmark": "node lib/task-collection/tools/benchmark__bake-collection__num-funcs.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Morglod/tseep.git"
},
"keywords": [
"types",
"ts",
"typescript",
"tsargs",
"events",
"eventemitter",
"event-listener",
"eventlistener",
"listener",
"emit"
],
"author": "morglod",
"license": "MIT",
"bugs": {
"url": "https://github.com/Morglod/tseep/issues"
},
"homepage": "https://github.com/Morglod/tseep#readme",
"devDependencies": {
"@types/jest": "^29.5.0",
"assume": "^2.2.0",
"jest": "^29.5.0",
"typescript": "^5.0.4"
}
}
Generated Vendored Executable
+60
View File
@@ -0,0 +1,60 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": [ "es2018", "dom" ], /* Specify library files to be included in the compilation. */
"skipLibCheck": true,
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./lib", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
// "strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
}
}