@opencreek/ext
Advanced tools
Comparing version 2.5.0 to 2.5.1--canary.31.6773909165.0
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -170,4 +161,3 @@ exports.Chain = exports.ObjectChain = exports.chain = exports.objChain = void 0; | ||
first() { | ||
var _a; | ||
return (_a = this.firstOrNull()) !== null && _a !== void 0 ? _a : (0, _1.error)("No first element found"); | ||
return this.firstOrNull() ?? (0, _1.error)("No first element found"); | ||
} | ||
@@ -181,7 +171,5 @@ firstOrNull() { | ||
} | ||
filterAsync(predicate) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const includes = yield this.mapAsync(predicate); | ||
return this.filter((_, index) => includes.val[index]); | ||
}); | ||
async filterAsync(predicate) { | ||
const includes = await this.mapAsync(predicate); | ||
return this.filter((_, index) => includes.val[index]); | ||
} | ||
@@ -231,3 +219,2 @@ filterNotNullish() { | ||
groupBy(selector) { | ||
var _a; | ||
const record = {}; | ||
@@ -237,3 +224,3 @@ for (const el of this.val) { | ||
if (record[key] != null) { | ||
(_a = record[key]) === null || _a === void 0 ? void 0 : _a.push(el); | ||
record[key]?.push(el); | ||
} | ||
@@ -255,3 +242,3 @@ else { | ||
// fromIndex would be converted to 0, which is NOT fine here | ||
const ret = this.val.lastIndexOf(searchElement, fromIndex !== null && fromIndex !== void 0 ? fromIndex : Infinity); | ||
const ret = this.val.lastIndexOf(searchElement, fromIndex ?? Infinity); | ||
if (ret === -1) | ||
@@ -278,4 +265,3 @@ return undefined; | ||
last() { | ||
var _a; | ||
return (_a = this.lastOrNull()) !== null && _a !== void 0 ? _a : (0, _1.error)("No last element found"); | ||
return this.lastOrNull() ?? (0, _1.error)("No last element found"); | ||
} | ||
@@ -290,7 +276,5 @@ lastOrNull() { | ||
} | ||
mapAsync(transformer) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const ret = yield Promise.all(this.val.map(transformer)); | ||
return new Chain(ret); | ||
}); | ||
async mapAsync(transformer) { | ||
const ret = await Promise.all(this.val.map(transformer)); | ||
return new Chain(ret); | ||
} | ||
@@ -297,0 +281,0 @@ mapNotNullish(transformer) { |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -29,6 +20,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}); | ||
(0, ava_1.default)("should filterAsync correctly", (t) => __awaiter(void 0, void 0, void 0, function* () { | ||
const result = yield (0, collections_1.chain)([1, 2, 3]).filterAsync((n) => __awaiter(void 0, void 0, void 0, function* () { return n !== 2; })); | ||
(0, ava_1.default)("should filterAsync correctly", async (t) => { | ||
const result = await (0, collections_1.chain)([1, 2, 3]).filterAsync(async (n) => n !== 2); | ||
t.snapshot(result.value()); | ||
})); | ||
}); | ||
(0, ava_1.default)("should findIndex correctly", (t) => { | ||
@@ -93,7 +84,7 @@ const arr = [1, 2, 3]; | ||
}); | ||
(0, ava_1.default)("should mapAsync correctly", (t) => __awaiter(void 0, void 0, void 0, function* () { | ||
const result = yield (0, collections_1.chain)([1, 2, 3]).mapAsync((n) => __awaiter(void 0, void 0, void 0, function* () { return n * 2; })); | ||
(0, ava_1.default)("should mapAsync correctly", async (t) => { | ||
const result = await (0, collections_1.chain)([1, 2, 3]).mapAsync(async (n) => n * 2); | ||
t.snapshot(result.value()); | ||
})); | ||
(0, ava_1.default)("should maxOf correctly", (t) => __awaiter(void 0, void 0, void 0, function* () { | ||
}); | ||
(0, ava_1.default)("should maxOf correctly", async (t) => { | ||
const arr = [1, 2, 3, 2]; | ||
@@ -103,4 +94,4 @@ const result = (0, collections_1.chain)(arr).maxOf((n) => n + 2); | ||
t.is((0, collections_1.chain)([]).maxOf((n) => n + 2), undefined); | ||
})); | ||
(0, ava_1.default)("should minOf correctly", (t) => __awaiter(void 0, void 0, void 0, function* () { | ||
}); | ||
(0, ava_1.default)("should minOf correctly", async (t) => { | ||
const arr = [1, 2, 3, 2]; | ||
@@ -110,3 +101,3 @@ const result = (0, collections_1.chain)(arr).minOf((n) => n + 2); | ||
t.is((0, collections_1.chain)([]).minOf((n) => n + 2), undefined); | ||
})); | ||
}); | ||
(0, ava_1.default)("should allow flattening on Chain<Array<T>>", (t) => { | ||
@@ -113,0 +104,0 @@ const arr = [[1], [2, 3]]; |
@@ -10,3 +10,3 @@ "use strict"; | ||
function error(msg, ...args) { | ||
const str = (0, strings_1.format)(msg !== null && msg !== void 0 ? msg : "", ...args); | ||
const str = (0, strings_1.format)(msg ?? "", ...args); | ||
throw new Error(str); | ||
@@ -13,0 +13,0 @@ } |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -17,11 +8,9 @@ exports.sleep = void 0; | ||
*/ | ||
function sleep(ms) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const p = new Promise((resolve) => { | ||
setTimeout(resolve, ms); | ||
}); | ||
return p; | ||
async function sleep(ms) { | ||
const p = new Promise((resolve) => { | ||
setTimeout(resolve, ms); | ||
}); | ||
return p; | ||
} | ||
exports.sleep = sleep; | ||
//# sourceMappingURL=sleep.js.map |
@@ -18,3 +18,3 @@ "use strict"; | ||
const latestTask = this.tasks[this.tasks.length - 1]; | ||
if ((latestTask === null || latestTask === void 0 ? void 0 : latestTask.elapsed) === undefined) { | ||
if (latestTask?.elapsed === undefined) { | ||
this.stop(); | ||
@@ -29,3 +29,3 @@ } | ||
const latestTask = this.tasks[this.tasks.length - 1]; | ||
if ((latestTask === null || latestTask === void 0 ? void 0 : latestTask.elapsed) === undefined) { | ||
if (latestTask?.elapsed === undefined) { | ||
latestTask.elapsed = new Date().valueOf() - latestTask.start; | ||
@@ -35,3 +35,3 @@ } | ||
getTotalElapsedTimeInMs() { | ||
return (0, collections_1.chain)(this.tasks).sumOf((it) => { var _a; return (_a = it.elapsed) !== null && _a !== void 0 ? _a : 0; }); | ||
return (0, collections_1.chain)(this.tasks).sumOf((it) => it.elapsed ?? 0); | ||
} | ||
@@ -38,0 +38,0 @@ toString() { |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -18,9 +9,9 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const StopWatch_1 = require("./StopWatch"); | ||
(0, ava_1.default)("StopWatch should time tasks and output a nice table", (t) => __awaiter(void 0, void 0, void 0, function* () { | ||
(0, ava_1.default)("StopWatch should time tasks and output a nice table", async (t) => { | ||
const sw = new StopWatch_1.StopWatch("1"); | ||
yield (0, sleep_1.sleep)(1000); | ||
await (0, sleep_1.sleep)(1000); | ||
sw.start("2"); | ||
yield (0, sleep_1.sleep)(1500); | ||
await (0, sleep_1.sleep)(1500); | ||
sw.start("3"); | ||
yield (0, sleep_1.sleep)(100); | ||
await (0, sleep_1.sleep)(100); | ||
sw.stop(); | ||
@@ -30,3 +21,3 @@ t.is(sw.tasks.length, 3); | ||
console.log(sw.toString()); | ||
})); | ||
}); | ||
//# sourceMappingURL=StopWatch.test.js.map |
@@ -17,5 +17,5 @@ "use strict"; | ||
function TODO(msg) { | ||
throw new NotYetImplementedError(msg !== null && msg !== void 0 ? msg : "TODO"); | ||
throw new NotYetImplementedError(msg ?? "TODO"); | ||
} | ||
exports.TODO = TODO; | ||
//# sourceMappingURL=todo.js.map |
{ | ||
"name": "@opencreek/ext", | ||
"version": "2.5.0", | ||
"version": "2.5.1--canary.31.6773909165.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
212729
105
3912
2