Comparing version 0.1.7 to 0.1.8
@@ -1,1 +0,2 @@ | ||
export default function contains<TL, TR>(l: TL[], r: TR[], predicate?: (l: TL, r: TR) => boolean): boolean; | ||
import { LeftRightPredicate } from './types'; | ||
export default function contains<TL, TR>(l: TL[], r: TR[], comparer: LeftRightPredicate<TL, TR>): boolean; |
"use strict"; | ||
function contains(l, r, predicate) { | ||
function contains(l, r, comparer) { | ||
var found, i, ii, j, jj; | ||
if (predicate) { | ||
if (comparer) { | ||
for (i = 0, ii = r.length; i < ii; i++) { | ||
found = false; | ||
for (j = 0, jj = l.length; j < jj; j++) { | ||
if (found = predicate(l[j], r[i])) { | ||
if (found = comparer(l[j], r[i])) { | ||
found = true; | ||
@@ -10,0 +10,0 @@ break; |
@@ -1,1 +0,2 @@ | ||
export default function distinct<TL, TR>(l: TL[], selector?: (l: TL) => TR[]): TR[]; | ||
import { Projector } from './types'; | ||
export default function distinct<TL, TKey>(items: TL[], selector?: Projector<TL, TKey>): TL[]; |
"use strict"; | ||
function distinct(l, selector) { | ||
const ii = l.length; | ||
function distinct(items, selector) { | ||
const ii = items.length; | ||
const res = new Array(ii); | ||
@@ -10,6 +10,6 @@ const tmp = new Array(); | ||
for (var i = 0; i < ii; i++) { | ||
key = selector(l[i]); | ||
key = selector(items[i], i, items); | ||
if (tmp.indexOf(key) === -1) { | ||
tmp[tmpPos++] = key; | ||
res[pos++] = l[i]; | ||
res[pos++] = items[i]; | ||
} | ||
@@ -20,4 +20,4 @@ } | ||
for (var i = 0; i < ii; i++) { | ||
if (tmp.indexOf(l[i]) === -1) { | ||
res[pos++] = tmp[tmpPos++] = l[i]; | ||
if (tmp.indexOf(items[i]) === -1) { | ||
res[pos++] = tmp[tmpPos++] = items[i]; | ||
} | ||
@@ -24,0 +24,0 @@ } |
@@ -1,1 +0,1 @@ | ||
export default function empty<TL>(l: TL[]): boolean; | ||
export default function empty<T>(items: T[]): boolean; |
"use strict"; | ||
function empty(l) { | ||
return l.length === 0; | ||
function empty(items) { | ||
return items.length === 0; | ||
} | ||
@@ -5,0 +5,0 @@ Object.defineProperty(exports, "__esModule", { value: true }); |
@@ -1,1 +0,2 @@ | ||
export default function first<TL>(l: TL[], predicate?: (l: TL) => boolean): TL; | ||
import { ItemPredicate } from './types'; | ||
export default function first<T>(items: T[], predicate?: ItemPredicate<T>): T; |
"use strict"; | ||
function first(l, predicate) { | ||
function first(items, predicate) { | ||
if (predicate) { | ||
for (var i = 0, ii = l.length; i < ii; i++) { | ||
if (predicate(l[i])) { | ||
return l[i]; | ||
for (var i = 0, ii = items.length; i < ii; i++) { | ||
if (predicate(items[i], i, items)) { | ||
return items[i]; | ||
} | ||
@@ -11,3 +11,3 @@ } | ||
else { | ||
return l[0]; | ||
return items[0]; | ||
} | ||
@@ -14,0 +14,0 @@ } |
@@ -9,3 +9,7 @@ export { default as contains } from './contains'; | ||
export { default as mapMany } from './mapMany'; | ||
export { default as mapManyNative } from './mapManyNative'; | ||
export { default as distinct } from './distinct'; | ||
export { default as select } from './select'; | ||
export { default as any } from './any'; | ||
export { default as all } from './all'; | ||
export { default as where } from './where'; |
@@ -18,6 +18,14 @@ "use strict"; | ||
exports.mapMany = mapMany_1.default; | ||
var mapManyNative_1 = require("./mapManyNative"); | ||
exports.mapManyNative = mapManyNative_1.default; | ||
var distinct_1 = require("./distinct"); | ||
exports.distinct = distinct_1.default; | ||
var select_1 = require("./select"); | ||
exports.select = select_1.default; | ||
var any_1 = require("./any"); | ||
exports.any = any_1.default; | ||
var all_1 = require("./all"); | ||
exports.all = all_1.default; | ||
var where_1 = require("./where"); | ||
exports.where = where_1.default; | ||
//# sourceMappingURL=index.js.map |
@@ -1,1 +0,2 @@ | ||
export default function intersect<TL, TR>(l: TL[], r: TR[], predicate?: (l: TL, r: TR) => boolean): TL[]; | ||
import { LeftRightPredicate } from './types'; | ||
export default function intersect<TL, TR>(l: TL[], r: TR[], comparer?: LeftRightPredicate<TL, TR>): TL[]; |
"use strict"; | ||
function intersect(l, r, predicate) { | ||
function intersect(l, r, comparer) { | ||
var i, ii, j, jj; | ||
@@ -10,3 +10,3 @@ l = l.slice(0); | ||
var x = 0; | ||
if (predicate) { | ||
if (comparer) { | ||
for (i = 0, ii = l.length; i < ii; i++) { | ||
@@ -16,3 +16,3 @@ for (j = 0, jj = r.length; j < jj; j++) { | ||
continue; | ||
if (predicate(l[i], r[j])) { | ||
if (comparer(l[i], r[j])) { | ||
res[pos++] = l[i]; | ||
@@ -19,0 +19,0 @@ r[j] = undefined; |
@@ -1,1 +0,2 @@ | ||
export default function last<TL>(l: TL[], predicate?: (l: TL) => boolean): TL; | ||
import { ItemPredicate } from './types'; | ||
export default function last<T>(items: T[], predicate?: ItemPredicate<T>): T; |
"use strict"; | ||
function last(l, predicate) { | ||
var i = l.length; | ||
function last(items, predicate) { | ||
var i = items.length; | ||
if (predicate) { | ||
while (i--) { | ||
if (predicate(l[i])) { | ||
return l[i]; | ||
if (predicate(items[i], i, items)) { | ||
return items[i]; | ||
} | ||
@@ -12,3 +12,3 @@ } | ||
else { | ||
return l[--i]; | ||
return items[--i]; | ||
} | ||
@@ -15,0 +15,0 @@ } |
import { ProjectMany } from './types'; | ||
export default function mapMany<TL, TR>(l: TL[], selector?: ProjectMany<TL, TR>): TR[]; | ||
export default function mapMany<TL, TR>(items: TL[], selector?: ProjectMany<TL, TR>): TR[]; |
"use strict"; | ||
function mapMany(l, selector) { | ||
function mapMany(items, selector) { | ||
if (selector) { | ||
const lists = l.map(selector); | ||
return Array.prototype.concat.apply([], lists); | ||
const ii = items.length; | ||
var res = Array(); | ||
var count = 0; | ||
for (let i = 0; i < ii; i++) { | ||
const deep = selector(items[i], i, items); | ||
if (deep === undefined) | ||
continue; | ||
for (let j = 0, jj = deep.length; j < jj; j++) { | ||
res[count++] = deep[j]; | ||
} | ||
} | ||
return res; | ||
} | ||
else { | ||
return Array.prototype.concat.apply([], l); | ||
const ii = items.length; | ||
var res = Array(); | ||
var count = 0; | ||
for (let i = 0; i < ii; i++) { | ||
const deep = items[i]; | ||
for (let j = 0, jj = deep.length; j < jj; j++) { | ||
res[count++] = deep[j]; | ||
} | ||
} | ||
return res; | ||
} | ||
@@ -10,0 +29,0 @@ } |
@@ -1,15 +0,18 @@ | ||
import { ItemPredicate, LeftRightPredicate, ProjectMany } from './types'; | ||
import { ItemPredicate, LeftRightPredicate, Projector, ProjectMany } from './types'; | ||
declare global { | ||
interface Array<T> { | ||
qContains<TR>(r: TR[], predicate?: LeftRightPredicate<T, TR>): boolean; | ||
qIntersect<TR>(r: TR[], predicate?: LeftRightPredicate<T, TR>): T[]; | ||
qSame<TR>(r: TR[], predicate?: LeftRightPredicate<T, TR>): boolean; | ||
qAny(predicate?: ItemPredicate<T>): boolean; | ||
qAll(predicate: ItemPredicate<T>): boolean; | ||
qContains<TR>(right: TR[], comparer?: LeftRightPredicate<T, TR>): boolean; | ||
qIntersect<TR>(right: TR[], comparer?: LeftRightPredicate<T, TR>): T[]; | ||
qSame<TR>(right: TR[], comparer?: LeftRightPredicate<T, TR>): boolean; | ||
qEmpty(): boolean; | ||
qFirst(predicate?: (l: T) => boolean): T; | ||
qLast(predicate?: (l: T) => boolean): T; | ||
qFirst(predicate?: ItemPredicate<T>): T; | ||
qLast(predicate?: ItemPredicate<T>): T; | ||
qRotate(offset: number): T[]; | ||
qMapMany<TR>(selector?: ProjectMany<T, TR>): TR[]; | ||
qDistinct(key?: (l: T) => any): T[]; | ||
qSelect<TOut>(selector: Projector<T, TOut>): TOut[]; | ||
qDistinct<TKey>(key?: Projector<T, TKey>): T[]; | ||
qWhere(predicate: ItemPredicate<T>): T[]; | ||
} | ||
} |
"use strict"; | ||
const lib = require("./index"); | ||
const ua_parser_js_1 = require("ua-parser-js"); | ||
const engine = new ua_parser_js_1.UAParser().getEngine().name; | ||
if (engine !== undefined && !/WebKit/i.test(engine)) { | ||
if (!Array.prototype.qMapMany) { | ||
Array.prototype.qMapMany = function (selector) { return lib.mapManyNative(this, selector); }; | ||
} | ||
if (!Array.prototype.qSelect) { | ||
Array.prototype.qSelect = Array.prototype.map; | ||
} | ||
} | ||
if (!Array.prototype.qContains) { | ||
Array.prototype.qContains = function (r, predicate) { | ||
return lib.contains(this, r, predicate); | ||
Array.prototype.qContains = function (right, comparer) { | ||
return lib.contains(this, right, comparer); | ||
}; | ||
} | ||
if (!Array.prototype.qIntersect) { | ||
Array.prototype.qIntersect = function (r, predicate) { | ||
return lib.intersect(this, r, predicate); | ||
Array.prototype.qIntersect = function (right, comparer) { | ||
return lib.intersect(this, right, comparer); | ||
}; | ||
} | ||
if (!Array.prototype.qSame) { | ||
Array.prototype.qSame = function (r, predicate) { | ||
return lib.same(this, r, predicate); | ||
Array.prototype.qSame = function (right, comparer) { | ||
return lib.same(this, right, comparer); | ||
}; | ||
@@ -48,2 +58,17 @@ } | ||
} | ||
if (!Array.prototype.qSelect) { | ||
Array.prototype.qSelect = function (predicate) { | ||
return lib.select(this, predicate); | ||
}; | ||
} | ||
if (!Array.prototype.qAny) { | ||
Array.prototype.qAny = function (predicate) { | ||
return lib.any(this, predicate); | ||
}; | ||
} | ||
if (!Array.prototype.qAll) { | ||
Array.prototype.qAll = function (predicate) { | ||
return lib.all(this, predicate); | ||
}; | ||
} | ||
if (!Array.prototype.qWhere) { | ||
@@ -50,0 +75,0 @@ Array.prototype.qWhere = function (predicate) { |
@@ -1,1 +0,1 @@ | ||
export default function rotate<TL>(l: TL[], offset: number): TL[]; | ||
export default function rotate<T>(items: T[], offset: number): T[]; |
"use strict"; | ||
function rotate(l, offset) { | ||
const end = l.length; | ||
function rotate(items, offset) { | ||
const end = items.length; | ||
if (offset === 0 || end === 0) | ||
return l.slice(0); | ||
return items.slice(0); | ||
var start = end - offset; | ||
@@ -12,6 +12,6 @@ while (start >= end) | ||
if (offset === 0) | ||
return l.slice(0); | ||
return items.slice(0); | ||
return [ | ||
...l.slice(start, end), | ||
...l.slice(0, start) | ||
...items.slice(start, end), | ||
...items.slice(0, start) | ||
]; | ||
@@ -18,0 +18,0 @@ } |
@@ -1,1 +0,2 @@ | ||
export default function same<TL, TR>(l: TL[], r: TR[], predicate?: (l: TL, r: TR) => boolean): boolean; | ||
import { LeftRightPredicate } from './types'; | ||
export default function same<TL, TR>(l: TL[], r: TR[], comparer?: LeftRightPredicate<TL, TR>): boolean; |
"use strict"; | ||
function same(l, r, predicate) { | ||
function same(l, r, comparer) { | ||
var i, ii, j, jj; | ||
if (l.length !== r.length) | ||
return false; | ||
if (predicate) { | ||
if (comparer) { | ||
for (i = 0, ii = l.length; i < ii; i++) { | ||
if (!predicate(l[i], r[i])) { | ||
if (!comparer(l[i], r[i])) { | ||
return false; | ||
@@ -10,0 +10,0 @@ } |
@@ -1,8 +0,10 @@ | ||
export default function contains<TL, TR>(l: TL[], r: TR[], predicate?: (l: TL, r: TR) => boolean): boolean { | ||
import { LeftRightPredicate } from './types'; | ||
export default function contains<TL, TR>(l: TL[], r: TR[], comparer: LeftRightPredicate<TL, TR>): boolean { | ||
var found, i, ii, j, jj; | ||
if (predicate) { | ||
if (comparer) { | ||
for (i = 0, ii = r.length; i < ii; i++) { | ||
found = false; | ||
for (j = 0, jj = l.length; j < jj; j++) { | ||
if (found = predicate(l[j], r[i])) { | ||
if (found = comparer(l[j], r[i])) { | ||
found = true; | ||
@@ -9,0 +11,0 @@ break; |
@@ -1,5 +0,7 @@ | ||
export default function distinct<TL, TR>(l: TL[], selector?: (l: TL) => TR[]): TR[] { | ||
const ii = l.length; | ||
const res = new Array(ii); | ||
const tmp = new Array(); | ||
import { Projector } from './types'; | ||
export default function distinct<TL, TKey>(items: TL[], selector?: Projector<TL, TKey>): TL[] { | ||
const ii = items.length; | ||
const res = new Array<TL>(ii); | ||
const tmp = new Array<TKey>(); | ||
let tmpPos = 0; | ||
@@ -9,6 +11,6 @@ let pos = 0, key; | ||
for (var i = 0; i < ii; i++) { | ||
key = selector(l[i]); | ||
key = selector(items[i], i, items); | ||
if (tmp.indexOf(key) === -1) { | ||
tmp[tmpPos++] = key; | ||
res[pos++] = l[i]; | ||
res[pos++] = items[i]; | ||
} | ||
@@ -18,4 +20,4 @@ } | ||
for (var i = 0; i < ii; i++) { | ||
if (tmp.indexOf(l[i]) === -1) { | ||
res[pos++] = tmp[tmpPos++] = l[i]; | ||
if (tmp.indexOf(items[i] as any) === -1) { | ||
res[pos++] = tmp[tmpPos++] = items[i] as any; | ||
} | ||
@@ -22,0 +24,0 @@ } |
@@ -1,3 +0,3 @@ | ||
export default function empty<TL>(l: TL[]): boolean { | ||
return l.length === 0; | ||
export default function empty<T>(items: T[]): boolean { | ||
return items.length === 0; | ||
} |
@@ -1,11 +0,13 @@ | ||
export default function first<TL>(l: TL[], predicate?: (l: TL) => boolean): TL { | ||
import { ItemPredicate } from './types'; | ||
export default function first<T>(items: T[], predicate?: ItemPredicate<T>): T { | ||
if (predicate) { | ||
for (var i = 0, ii = l.length; i < ii; i++) { | ||
if (predicate(l[i])) { | ||
return l[i]; | ||
for (var i = 0, ii = items.length; i < ii; i++) { | ||
if (predicate(items[i], i, items)) { | ||
return items[i]; | ||
} | ||
} | ||
} else { | ||
return l[0]; | ||
return items[0]; | ||
} | ||
} |
@@ -9,3 +9,7 @@ export { default as contains } from './contains'; | ||
export { default as mapMany } from './mapMany'; | ||
export { default as mapManyNative } from './mapManyNative'; | ||
export { default as distinct } from './distinct'; | ||
export { default as select } from './select'; | ||
export { default as any } from './any'; | ||
export { default as all } from './all'; | ||
export { default as where } from './where'; |
@@ -1,2 +0,4 @@ | ||
export default function intersect<TL, TR>(l: TL[], r: TR[], predicate?: (l: TL, r: TR) => boolean): TL[] { | ||
import { LeftRightPredicate } from './types'; | ||
export default function intersect<TL, TR>(l: TL[], r: TR[], comparer?: LeftRightPredicate<TL, TR>): TL[] { | ||
var i, ii, j, jj; | ||
@@ -10,7 +12,7 @@ l = l.slice(0); | ||
if (predicate) { | ||
if (comparer) { | ||
for (i = 0, ii = l.length; i < ii; i++) { | ||
for (j = 0, jj = r.length; j < jj; j++) { | ||
if (r[j] === undefined) continue; | ||
if (predicate(l[i], r[j])) { | ||
if (comparer(l[i], r[j])) { | ||
res[pos++] = l[i]; | ||
@@ -17,0 +19,0 @@ r[j] = undefined; |
@@ -1,12 +0,14 @@ | ||
export default function last<TL>(l: TL[], predicate?: (l: TL) => boolean): TL { | ||
var i = l.length; | ||
import { ItemPredicate } from './types'; | ||
export default function last<T>(items: T[], predicate?: ItemPredicate<T>): T { | ||
var i = items.length; | ||
if (predicate) { | ||
while (i--) { | ||
if (predicate(l[i])) { | ||
return l[i]; | ||
if (predicate(items[i], i, items)) { | ||
return items[i]; | ||
} | ||
} | ||
} else { | ||
return l[--i]; | ||
return items[--i]; | ||
} | ||
} |
import { ProjectMany } from './types'; | ||
export default function mapMany<TL, TR>(l: TL[], selector?: ProjectMany<TL, TR>): TR[] { | ||
if (selector) { | ||
const lists = l.map(selector); | ||
return Array.prototype.concat.apply([], lists); | ||
} else { | ||
return Array.prototype.concat.apply([], l); | ||
} | ||
export default function mapMany<TL, TR>(items: TL[], selector?: ProjectMany<TL, TR>): TR[] { | ||
if (selector) { | ||
const ii = items.length; | ||
var res = Array(); | ||
var count = 0; | ||
for (let i = 0; i < ii; i++) { | ||
const deep = selector(items[i], i, items); | ||
if (deep === undefined) continue; | ||
for (let j = 0, jj = deep.length; j < jj; j++) { | ||
res[count++] = deep[j]; | ||
} | ||
} | ||
return res; | ||
} else { | ||
const ii = items.length; | ||
var res = Array(); | ||
var count = 0; | ||
for (let i = 0; i < ii; i++) { | ||
const deep = items[i] as any as TR[]; | ||
for (let j = 0, jj = deep.length; j < jj; j++) { | ||
res[count++] = deep[j]; | ||
} | ||
} | ||
return res; | ||
} | ||
} |
@@ -7,11 +7,14 @@ import * as lib from './index'; | ||
interface Array<T> { | ||
qContains<TR>(r: TR[], predicate?: LeftRightPredicate<T, TR>): boolean; | ||
qIntersect<TR>(r: TR[], predicate?: LeftRightPredicate<T, TR>): T[]; | ||
qSame<TR>(r: TR[], predicate?: LeftRightPredicate<T, TR>): boolean; | ||
qAny(predicate?: ItemPredicate<T>): boolean; | ||
qAll(predicate: ItemPredicate<T>): boolean; | ||
qContains<TR>(right: TR[], comparer?: LeftRightPredicate<T, TR>): boolean; | ||
qIntersect<TR>(right: TR[], comparer?: LeftRightPredicate<T, TR>): T[]; | ||
qSame<TR>(right: TR[], comparer?: LeftRightPredicate<T, TR>): boolean; | ||
qEmpty(): boolean; | ||
qFirst(predicate?: (l: T) => boolean): T; | ||
qLast(predicate?: (l: T) => boolean): T; | ||
qFirst(predicate?: ItemPredicate<T>): T; | ||
qLast(predicate?: ItemPredicate<T>): T; | ||
qRotate(offset: number): T[]; | ||
qMapMany<TR>(selector?: ProjectMany<T, TR>): TR[]; | ||
qDistinct(key?: (l: T) => any): T[]; | ||
qSelect<TOut>(selector: Projector<T, TOut>): TOut[]; | ||
qDistinct<TKey>(key?: Projector<T, TKey>): T[]; | ||
qWhere(predicate: ItemPredicate<T>): T[]; | ||
@@ -21,15 +24,26 @@ } | ||
import { UAParser } from 'ua-parser-js'; | ||
const engine: string = new UAParser().getEngine().name; | ||
if (engine !== undefined && !/WebKit/i.test(engine)) { | ||
if (!Array.prototype.qMapMany) { | ||
Array.prototype.qMapMany = function<TL,TR>(selector?: ProjectMany<TL, TR>) { return lib.mapManyNative(this, selector); }; | ||
} | ||
if (!Array.prototype.qSelect) { | ||
Array.prototype.qSelect = Array.prototype.map; | ||
} | ||
} | ||
if (!Array.prototype.qContains) { | ||
Array.prototype.qContains = function<T, TR>(r: TR[], predicate?: LeftRightPredicate<T, TR>) { | ||
return lib.contains(this, r, predicate); | ||
Array.prototype.qContains = function<T, TR>(right: TR[], comparer?: LeftRightPredicate<T, TR>) { | ||
return lib.contains(this, right, comparer); | ||
}; | ||
} | ||
if (!Array.prototype.qIntersect) { | ||
Array.prototype.qIntersect = function<T, TR>(r: TR[], predicate?: LeftRightPredicate<T, TR>) { | ||
return lib.intersect(this, r, predicate); | ||
Array.prototype.qIntersect = function<T, TR>(right: TR[], comparer?: LeftRightPredicate<T, TR>) { | ||
return lib.intersect(this, right, comparer); | ||
}; | ||
} | ||
if (!Array.prototype.qSame) { | ||
Array.prototype.qSame = function<T, TR>(r: TR[], predicate?: LeftRightPredicate<T, TR>) { | ||
return lib.same(this, r, predicate); | ||
Array.prototype.qSame = function<T, TR>(right: TR[], comparer?: LeftRightPredicate<T, TR>) { | ||
return lib.same(this, right, comparer); | ||
}; | ||
@@ -43,3 +57,3 @@ } | ||
if (!Array.prototype.qFirst) { | ||
Array.prototype.qFirst = function(predicate?) { | ||
Array.prototype.qFirst = function<T>(predicate?: ItemPredicate<T>) { | ||
return lib.first(this, predicate); | ||
@@ -49,3 +63,3 @@ }; | ||
if (!Array.prototype.qLast) { | ||
Array.prototype.qLast = function(predicate?) { | ||
Array.prototype.qLast = function<T>(predicate?: ItemPredicate<T>) { | ||
return lib.last(this, predicate); | ||
@@ -55,3 +69,3 @@ }; | ||
if (!Array.prototype.qRotate) { | ||
Array.prototype.qRotate = function(offset) { | ||
Array.prototype.qRotate = function(offset: number) { | ||
return lib.rotate(this, offset); | ||
@@ -66,6 +80,21 @@ }; | ||
if (!Array.prototype.qDistinct) { | ||
Array.prototype.qDistinct = function(key?) { | ||
Array.prototype.qDistinct = function<T, TKey>(key?: Projector<T, TKey>) { | ||
return lib.distinct(this, key); | ||
}; | ||
} | ||
if (!Array.prototype.qSelect) { | ||
Array.prototype.qSelect = function<T, TOut>(predicate: Projector<T, TOut>) { | ||
return lib.select(this, predicate); | ||
}; | ||
} | ||
if (!Array.prototype.qAny) { | ||
Array.prototype.qAny = function<T>(predicate?: ItemPredicate<T>) { | ||
return lib.any(this, predicate); | ||
}; | ||
} | ||
if (!Array.prototype.qAll) { | ||
Array.prototype.qAll = function<T>(predicate: ItemPredicate<T>) { | ||
return lib.all(this, predicate); | ||
}; | ||
} | ||
if (!Array.prototype.qWhere) { | ||
@@ -72,0 +101,0 @@ Array.prototype.qWhere = function<T>(predicate: ItemPredicate<T>) { |
@@ -1,12 +0,12 @@ | ||
export default function rotate<TL>(l: TL[], offset: number): TL[] { | ||
const end = l.length; | ||
if (offset === 0 || end === 0) return l.slice(0); | ||
export default function rotate<T>(items: T[], offset: number): T[] { | ||
const end = items.length; | ||
if (offset === 0 || end === 0) return items.slice(0); | ||
var start = end - offset; | ||
while (start >= end) start -= end; | ||
while (start < 0) start += end; | ||
if (offset === 0) return l.slice(0); | ||
if (offset === 0) return items.slice(0); | ||
return [ | ||
...l.slice(start, end), | ||
...l.slice(0, start) | ||
...items.slice(start, end), | ||
...items.slice(0, start) | ||
] | ||
} |
@@ -1,8 +0,10 @@ | ||
export default function same<TL, TR>(l: TL[], r: TR[], predicate?: (l: TL, r: TR) => boolean): boolean { | ||
import { LeftRightPredicate } from './types'; | ||
export default function same<TL, TR>(l: TL[], r: TR[], comparer?: LeftRightPredicate<TL, TR>): boolean { | ||
var i, ii, j, jj; | ||
if (l.length !== r.length) return false; | ||
if (predicate) { | ||
if (comparer) { | ||
for (i = 0, ii = l.length; i < ii; i++) { | ||
if (!predicate(l[i], r[i])) { | ||
if (!comparer(l[i], r[i])) { | ||
return false; | ||
@@ -9,0 +11,0 @@ } |
{ | ||
"name": "arrayq", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"description": "Array query methods for Node.js", | ||
@@ -14,2 +14,3 @@ "main": "es6/prototype.js", | ||
"test": "mocha ./test", | ||
"bench": "node benchmark", | ||
"watch": "nodemon -i ./es6/ -w ./ --exec \"npm run compile && npm run test\"" | ||
@@ -30,5 +31,9 @@ }, | ||
"assert": "^1.4.1", | ||
"benchmark": "^2.1.3", | ||
"mocha": "^3.2.0", | ||
"typescript": "^2.1.5" | ||
}, | ||
"dependencies": { | ||
"ua-parser-js": "^0.7.12" | ||
} | ||
} |
@@ -142,2 +142,9 @@ const assert = require('assert'); | ||
describe('qSelect', function() { | ||
it('return list with values of property a', function() { | ||
// TODO | ||
assert.deepEqual([{a:1},{a:2},{a:3},{a:4}].qSelect(x => x.a), [1,2,3,4]); | ||
}); | ||
}); | ||
describe('qDistinct', function() { | ||
@@ -168,2 +175,20 @@ it('should remain empty', function() { | ||
describe('qAll', function() { | ||
it('should return true', function() { | ||
assert([1, 1, 1, 1].qAll(x => x === 1)); | ||
}); | ||
it('should return false', function() { | ||
assert(![1, 1, 1, 2].qAll(x => x === 1)); | ||
}); | ||
}); | ||
describe('qAny', function() { | ||
it('should return true', function() { | ||
assert([1, 2, 3, 4].qAny(x => x === 1)); | ||
}); | ||
it('should return false', function() { | ||
assert(![1, 2, 3, 4].qAny(x => x === 0)); | ||
}); | ||
}); | ||
describe('qWhere', function() { | ||
@@ -170,0 +195,0 @@ it('should have even numbers', function() { |
@@ -17,3 +17,4 @@ { | ||
"sourceMap": true, | ||
"outDir": "es6" | ||
"outDir": "es6", | ||
"alwaysStrict": true | ||
}, | ||
@@ -23,4 +24,7 @@ "include": [ | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
], | ||
"compileOnSave": false, | ||
"buildOnSave": false | ||
} |
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
162073
84
4581
1
4
1
+ Addedua-parser-js@^0.7.12
+ Addedua-parser-js@0.7.39(transitive)