Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

asclasit

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asclasit - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

2

.vscode/launch.json

@@ -36,3 +36,3 @@ {

"algo/deque."
"func2/class."
],

@@ -39,0 +39,0 @@ "console": "integratedTerminal",

@@ -131,4 +131,23 @@ class Deque {

}
append(iter) {
for (const item of iter) this.pushOne(item);
return this._length;
}
prepend(iter) {
for (const item of iter) this.unshiftOne(item);
return this._length;
}
static from(iter, opts = {}) {
const dq = new this(opts);
if (opts.reverse) dq.prepend(iter);
else dq.append(iter);
return dq;
}
}
module.exports = Deque;

@@ -54,1 +54,15 @@ const Deque = require('./deque');

});
test('Deque: append, prepend', () => {
const dq = new Deque();
dq.append([1, 2, 3]);
dq.prepend([4, 5, 6]);
dq.append([7, 8, 9]);
dq.prepend([0, 'a']);
expect(Array.from(dq)).toEqual(['a', 0, 6, 5, 4, 1, 2, 3, 7, 8, 9]);
});
test('Deque: from', () => {
expect(Array.from(Deque.from([1, 2, 3]))).toEqual([1, 2, 3]);
expect(Array.from(Deque.from([1, 2, 3], {reverse: true}))).toEqual([3, 2, 1]);
});

@@ -12,5 +12,3 @@ // original from: https://stackoverflow.com/a/42919752

class PriorityQueue {
constructor({reverse, sort, revSort} = {}) {
this._heap = [];
constructor({reverse, sort, revSort} = {}, src) {
if (reverse) {

@@ -23,2 +21,5 @@ this._comparator = sort || defComparator;

}
if (src) this._heap = Array.from(src).sort(this._revComparator);
else this._heap = [];
}

@@ -42,4 +43,7 @@

toArray({reverse, sort, raw, keep} = {}) {
if (raw) return this._heap;
get raw() {
return this._heap;
}
toArray({reverse, sort, keep} = {}) {
let res = this._heap;

@@ -129,2 +133,11 @@

}
add(iter) {
for (const item of iter) this.pushOne(item);
}
static from(iter, opts) {
const pq = new this(opts, iter);
return pq;
}
}

@@ -131,0 +144,0 @@

@@ -15,2 +15,15 @@ const PQ = require('./priority-queue');

test('$.PQ: add', () => {
const pq = new PQ();
pq.add([6, 2, 1, 9, 0]);
expect(pq.toArray({reverse: true})).toEqual([0, 1, 2, 6, 9]);
});
test('$.PQ: from', () => {
const pq = PQ.from([6, 2, 1, 9, 0]);
pq.pushOne(-1);
expect(Array.from(pq)).toEqual([-1, 0, 1, 2, 6, 9]);
});
test('$.PQ.Limited: priority queue', () => {

@@ -37,3 +50,3 @@ const pq = new PQ.Limited();

expect(pq.peek()).toBe(6);
expect(pq.toArray({raw: true})).toEqual([6, 2, 5, 0]);
expect(pq.raw).toEqual([6, 2, 5, 0]);
expect(pq.toArray({reverse: true, keep: true})).toEqual([6, 5, 2, 0]);

@@ -53,3 +66,3 @@ expect(pq.toArray({sort: (a, b) => a & 1 ? (b & 1 ? a - b : 1) : (b & 1 ? -1 : a - b), keep: true})).toEqual([0, 2, 6, 5]);

expect(pq.peek()).toBe(5);
expect(pq.toArray({raw: true})).toEqual([5, 6, 8, 10]);
expect(pq.raw).toEqual([5, 6, 8, 10]);
expect(pq.toArray({reverse: true, keep: true})).toEqual([5, 6, 8, 10]);

@@ -56,0 +69,0 @@ expect(pq.toArray({sort: (a, b) => a & 1 ? (b & 1 ? a - b : 1) : (b & 1 ? -1 : a - b), keep: true})).toEqual([6, 8, 10, 5]);

@@ -76,5 +76,17 @@ const AsIt = require('./filter');

test('AsIt_.dbglog: debug output to console.log', async () => {
const wr = new AsIt(['test']);
wr.dbglog('AsIt.dbglog');
expect(await asItArray(wr)).toEqual(['test']);
let res;
const logs = [];
const origLog = console.log;
console.log = (...ents) => logs.push(...ents);
try {
const wr = new AsIt(['test']);
wr.dbglog('AsIt.dbglog');
res = await asItArray(wr);
} finally {
console.log = origLog;
}
expect(res).toEqual(['test']);
expect(logs).toEqual(['AsIt.dbglog', 'test']);
});

@@ -81,0 +93,0 @@

@@ -5,2 +5,13 @@ const AsIt = require('./object');

function bound() { return this; }
AsIt.chain_(async function* shim(iter) {
if (!iter[Symbol.asyncIterator] && !iter[Symbol.iterator]) {
iter = Object.create(iter);
iter[Symbol.asyncIterator] = bound;
}
for await (const item of iter) yield item;
});
AsIt.chain_(async function* from(arg, strOk) {

@@ -7,0 +18,0 @@ const iter = AsIt.getIter(arg, strOk);

@@ -16,2 +16,10 @@ const AsIt = require('./make');

test('AsIt.shim: compatible iterator', async () => {
const src = {arr: [1, 2, 3], async next() {
return {done: !this.arr.length, value: this.arr.pop()};
}};
expect(await asItArray(AsIt.shim(src))).toEqual([3, 2, 1]);
});
test('AsIt.concat: concatenate iterators', async () => {

@@ -18,0 +26,0 @@ const i1 = ['a1', 'a2'];

@@ -185,3 +185,3 @@ const $ = require('../func');

if (life && typeof life.value === 'function') {
life = life.value.call(this.from, tries);
life = {iter: life.value.call(this.from, tries)};
this.#life.set(o, life);

@@ -193,3 +193,3 @@ } else {

ready = life.next();
ready = life.cur || life.iter.next();

@@ -199,3 +199,5 @@ if (ready.constructor === Promise) {

if (this.wakeTimeout) ready = Promise.race([ready, tm = $.timeoutMsec(this.wakeTimeout, () => new WakeTimeoutError())]);
life.cur = ready;
ready = await ready;
life.cur = null;
if (tm) tm.cancel();

@@ -211,3 +213,5 @@ }

if (this.wakeTimeout) ready = Promise.race([ready, tm = $.timeoutMsec(this.wakeTimeout, () => new WakeTimeoutError())]);
life.cur = ready;
ready = await ready;
life.cur = null;
if (tm) tm.cancel();

@@ -221,2 +225,4 @@ }

this.#awake = false;
if (retr--) {

@@ -253,7 +259,10 @@ tries++;

try {
wait = life.return();
//if (life.cur) await life.cur;
wait = life.iter.return();
if (wait instanceof Promise) {
if (this.#sleepTimeout) wait = Promise.race([wait, this.#sleepTimeout]);
life.cur = wait;
await wait;
life.cur = null;
}

@@ -260,0 +269,0 @@ } catch (err) {

@@ -117,4 +117,3 @@ const $ = require('./class');

'l2method a',
'l1use',
'l2use', 'l2use',
'l2use',
'l2method b',

@@ -164,3 +163,3 @@ 'l2method c',

expect(l1.events).toEqual([
'l1conn', 'l1use', 'l1use', 'l1use', 'l1use', 'l1dc',
'l1conn', 'l1use', 'l1use', 'l1dc',
]);

@@ -187,3 +186,3 @@ });

'l1conn', 'l1use', 'l1dc',
'l1conn', 'l1use', 'l1use', 'l1use', 'l1use', 'l1dc',
'l1conn', 'l1use', 'l1use', 'l1dc',
]);

@@ -190,0 +189,0 @@ });

@@ -400,3 +400,3 @@ const $ = require('../func');

func_(function throw_(title) {
func_(function throw_(title, {exitCode} = {}) {
return function _throw(err) {

@@ -406,2 +406,3 @@ let out = !err ? err : err.stack || err.message || err.type || err.code || err;

console.error(out);
if (exitCode) process.exit(exitCode);
}

@@ -408,0 +409,0 @@ });

@@ -74,12 +74,33 @@ const Emitter = require('events');

test('$.throw_: format error message', () => {
const outs = [];
const orig = console.error;
let out;
console.error = (err) => out = err;
$.throw_('my title')(null);
expect(out).toBe('my title\nnull');
$.throw_('my title')('error');
expect(out).toBe('my title\nerror');
console.error = orig;
console.error = (err) => outs.push(err);
try {
$.throw_('my title')(null);
$.throw_('my title')('error');
} finally {
console.error = orig;
}
expect(outs).toEqual(['my title\nnull', 'my title\nerror']);
});
test('$.throw_: exit', () => {
const bumped = [];
const origExit = process.exit;
const origError = console.error;
process.exit = (code) => bumped.push(`exit ${code}`);
console.error = (...ents) => bumped.push(...ents);
try {
$.throw_('fatal', {exitCode: 1})('test');
} finally {
console.error = origError;
process.exit = origExit;
}
expect(bumped).toEqual(['fatal\ntest', 'exit 1']);
});
test('$.grabEvents: listen and store events', async () => {

@@ -86,0 +107,0 @@ const ev = new Emitter();

@@ -70,5 +70,17 @@ const Iter = require('./filter');

test('Iter_.dbglog: debug output to console.log', () => {
const wr = new Iter(['test']);
wr.dbglog('Iter.dbglog');
expect(Array.from(wr)).toEqual(['test']);
let res;
const logs = [];
const origLog = console.log;
console.log = (...ents) => logs.push(...ents);
try {
const wr = new Iter(['test']);
wr.dbglog('Iter.dbglog');
res = Array.from(wr);
} finally {
console.log = origLog;
}
expect(res).toEqual(['test']);
expect(logs).toEqual(['Iter.dbglog', 'test']);
});

@@ -75,0 +87,0 @@

@@ -5,2 +5,13 @@ const Iter = require('./object');

function bound() { return this; }
Iter.chain_(function* shim(iter) {
if (!iter[Symbol.iterator]) {
iter = Object.create(iter);
iter[Symbol.iterator] = bound;
}
for (const item of iter) yield item;
});
Iter.chain_(function* from(arg, strOk) {

@@ -7,0 +18,0 @@ const iter = Iter.getIter(arg, strOk);

@@ -9,2 +9,10 @@ const Iter = require('./make');

test('Iter.shim: compatible iterator', () => {
const src = {arr: [1, 2, 3], next() {
return {done: !this.arr.length, value: this.arr.pop()};
}};
expect(Array.from(Iter.shim(src))).toEqual([3, 2, 1]);
});
test('Iter.concat: concatenate iterators', () => {

@@ -11,0 +19,0 @@ const i1 = ['a1', 'a2'];

{
"name": "asclasit",
"version": "0.1.2",
"version": "0.1.3",
"description": "ASync CLasses + ASync ITerators",

@@ -8,3 +8,3 @@ "main": "index.js",

"diff": "gitdiff () { git diff $* -- . ':!package-lock.json'; }; gitdiff",
"test": "node --inspect --expose-gc --trace-warnings --trace-deprecation --unhandled-rejections=throw node_modules/.bin/jest --runInBand --logHeapUsage"
"test": "node --inspect --expose-gc --trace-warnings --trace-deprecation --unhandled-rejections=throw node_modules/.bin/jest --runInBand --logHeapUsage --colors"
},

@@ -33,4 +33,4 @@ "repository": {

"devDependencies": {
"jest": "^27.0.6"
"jest": "^27.2.1"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc