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

space-lift

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

space-lift - npm Package Compare versions

Comparing version 1.0.0-beta.3 to 1.0.0-beta.4

commonjs/wrapper.d.ts

65

commonjs/array.d.ts
import { Draft } from './immupdate';
import { pipe, Wrapper, Lifted } from './lift';
import { Lifted, Pipe } from './lift';
import { Wrapper } from './wrapper';
import { MapWrapper } from './map';
import { SetWrapper } from './set';
/** An Array wrapper providing extra functionalities and more chaining opportunities */
export declare class ArrayWrapper<T> {
export declare class ArrayWrapper<T extends ReadonlyArray<unknown>> {
private _value;
constructor(_value: ReadonlyArray<T>);
constructor(_value: T);
private _isLiftWrapper;
value(): readonly T[];
clone(): ArrayWrapper<T>;
value(): T;
clone(): ArrayWrapper<unknown[]>;
private _clone;

@@ -16,7 +17,7 @@ /**

*/
append(item: T): ArrayWrapper<T>;
append(item: T[number]): ArrayWrapper<T[number][]>;
/**
* Appends an Array of items at the end of the Array.
*/
appendAll(items: T[]): ArrayWrapper<T>;
appendAll(items: ReadonlyArray<T[number]>): ArrayWrapper<unknown[]>;
/**

@@ -26,11 +27,11 @@ * Filters all the falsy elements out of this Array.

*/
compact(): ArrayWrapper<Compacted<T>>;
compact(): ArrayWrapper<ArrayOf<T, Compacted<T[number]>>>;
/**
* Counts the items satisfying a predicate.
*/
count(predicate: (item: T, index: number) => boolean): number;
count(predicate: (item: T[number], index: number) => boolean): number;
/**
* Maps this Array's items, unless void or undefined is returned, in which case the item is filtered.
*/
collect<B>(iterator: (item: T, index: number) => B | undefined | void): ArrayWrapper<B>;
collect<B>(iterator: (item: T[number], index: number) => B | undefined | void): ArrayWrapper<ArrayOf<T, B>>;
/**

@@ -41,3 +42,3 @@ * Creates an array without any duplicate item.

*/
distinct(getKey?: (item: T, index: number) => string | number): ArrayWrapper<T>;
distinct(getKey?: (item: T[number], index: number) => string | number): ArrayWrapper<T>;
/**

@@ -54,32 +55,32 @@ * Drops the first 'count' items from this Array.

*/
filter<A extends T>(predicate: (item: T, index: number) => item is A): ArrayWrapper<A>;
filter<A extends T[number]>(predicate: (item: T[number], index: number) => item is A): ArrayWrapper<ArrayOf<T, A>>;
/**
* Filters this array by aplying a predicate.
*/
filter(predicate: (item: T, index: number) => boolean): ArrayWrapper<T>;
filter(predicate: (item: T[number], index: number) => boolean): ArrayWrapper<T>;
/**
* Returns the first element in this Array or undefined.
*/
first(): T | undefined;
first(): T[number] | undefined;
/**
* Maps this Array to an Array of Array | ArrayWrapper using a mapper function then flattens it.
*/
flatMap<B>(fun: (item: T, index: number) => B[]): ArrayWrapper<B>;
flatMap<B extends ReadonlyArray<any>>(fun: (item: T[number], index: number) => B): ArrayWrapper<B>;
/**
* Maps this Array to an Array of Array | ArrayWrapper using a mapper function then flattens it.
*/
flatMap<B>(fun: (item: T, index: number) => ArrayWrapper<B>): ArrayWrapper<B>;
flatMap<B extends ReadonlyArray<any>>(fun: (item: T[number], index: number) => ArrayWrapper<B>): ArrayWrapper<B>;
/**
* Flattens this Array of Arrays.
*/
flatten<A>(this: ArrayWrapper<ReadonlyArray<A>>): ArrayWrapper<A>;
flatten<A>(this: ArrayWrapper<A[]>): ArrayWrapper<A>;
flatten<A>(this: ArrayWrapper<ReadonlyArray<A>>): ArrayWrapper<ArrayOf<T, A>>;
flatten<A>(this: ArrayWrapper<A[]>): ArrayWrapper<ArrayOf<T, A>>;
/**
* Folds this Array into a single value, using a starting value.
*/
fold<V>(startValue: V, func: (acc: V, value: T, index: number) => V): Lifted<V>;
fold<V>(startValue: V, func: (acc: V, value: T[number], index: number) => V): Lifted<V>;
/**
* Returns the item found at the provided index or undefined.
*/
get(index: number): T | undefined;
get(index: number): T[number] | undefined;
/**

@@ -89,15 +90,15 @@ * Creates a Map where keys are the results of running each element through a discriminator function.

*/
groupBy<K extends string | number>(discriminator: (item: T, index: number) => K): MapWrapper<K, ReadonlyArray<T>>;
groupBy<K extends string | number>(discriminator: (item: T[number], index: number) => K): MapWrapper<K, T>;
/**
* Inserts an item at a specified index.
*/
insert(index: number, item: T): ArrayWrapper<T>;
insert(index: number, item: T[number]): ArrayWrapper<T>;
/**
* Returns the item found at the last index or undefined.
*/
last(): T | undefined;
last(): T[number] | undefined;
/**
* Maps this Array using a mapper function.
*/
map<B>(fun: (item: T, index: number) => B): ArrayWrapper<B>;
map<B>(fun: (item: T[number], index: number) => B): ArrayWrapper<ArrayOf<T, B>>;
/**

@@ -116,3 +117,3 @@ * Removes the item found at the specified index.

*/
sort(...fields: Array<SortOnField<T>>): ArrayWrapper<T>;
sort(...fields: Array<SortOnField<T[number]>>): ArrayWrapper<T>;
/**

@@ -129,3 +130,3 @@ * Takes the first 'count' items from this Array.

*/
toSet(): SetWrapper<T>;
toSet(): SetWrapper<T[number]>;
/**

@@ -135,19 +136,21 @@ * Make mutable modifications to a draft then return a new Array.

*/
update(updateFunction: (draft: Draft<ReadonlyArray<T>>) => void): ArrayWrapper<T>;
update(updateFunction: (draft: Draft<ReadonlyArray<T[number]>>) => void): Lifted<T>;
/**
* Updates an item at the specified index.
*/
updateAt(index: number, updater: (item: T) => Wrapper<T>): ArrayWrapper<T>;
updateAt(index: number, updater: (item: T[number]) => Wrapper<T[number]>): ArrayWrapper<T>;
/**
* Updates an item at the specified index.
*/
updateAt(index: number, updater: (item: T) => T): ArrayWrapper<T>;
updateAt(index: number, updater: (item: T[number]) => T[number]): ArrayWrapper<T>;
/**
* Pipes this Array with an arbitrary transformation function.
*/
pipe: typeof pipe;
pipe: typeof import("./lift").pipe;
}
export declare function range(start: number, stop?: number, step?: number): ArrayWrapper<number>;
export declare function setArrayPipe(_pipe: Pipe): void;
export declare function range(start: number, stop?: number, step?: number): ArrayWrapper<ReadonlyArray<number>>;
declare type SortOnField<T> = ((field: T) => string | null | undefined) | ((field: T) => number | null | undefined);
declare type Compacted<T> = T extends null | undefined | 0 | false ? never : T;
declare type ArrayOf<T extends ReadonlyArray<unknown>, ITEM> = T extends Array<any> ? Array<ITEM> : ReadonlyArray<ITEM>;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.range = exports.ArrayWrapper = void 0;
exports.range = exports.setArrayPipe = exports.ArrayWrapper = void 0;
const function_1 = require("./function");
const immupdate_1 = require("./immupdate");
const lift_1 = require("./lift");
const wrapper_1 = require("./wrapper");
const map_1 = require("./map");

@@ -16,3 +16,3 @@ /** An Array wrapper providing extra functionalities and more chaining opportunities */

*/
this.pipe = lift_1.pipe;
this.pipe = pipe;
}

@@ -107,3 +107,3 @@ value() {

for (let i = 0; i < arr.length; i++) {
result.push.apply(result, lift_1.getValue(fun(arr[i], i)));
result.push.apply(result, wrapper_1.getValue(fun(arr[i], i)));
}

@@ -124,3 +124,3 @@ return new ArrayWrapper(result);

fold(startValue, func) {
return lift_1.lift(this._value.reduce(func, startValue));
return this.pipe(arr => arr.reduce(func, startValue));
}

@@ -247,3 +247,3 @@ /**

if (result.length > index && index > -1)
result[index] = lift_1.getValue(updater(result[index]));
result[index] = wrapper_1.getValue(updater(result[index]));
return new ArrayWrapper(result);

@@ -253,2 +253,7 @@ }

exports.ArrayWrapper = ArrayWrapper;
let pipe;
function setArrayPipe(_pipe) {
pipe = _pipe;
}
exports.setArrayPipe = setArrayPipe;
/*

@@ -255,0 +260,0 @@ * Returns a number[] wrapper with all numbers from start to stop (inclusive),

@@ -73,5 +73,10 @@ "use strict";

let low = 0, high = arr.length;
const itemValue = by(item);
while (low < high) {
let mid = (low + high) >>> 1;
if (by(arr[mid]) < by(item))
const mid = (low + high) >>> 1;
const midValue = by(arr[mid]);
const itemValueIsBigger = typeof itemValue === 'string'
? itemValue.localeCompare(midValue) > 0
: itemValue > midValue;
if (itemValueIsBigger)
low = mid + 1;

@@ -78,0 +83,0 @@ else

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.is = exports.noop = exports.identity = exports.createEnum = exports.createUnion = exports.range = exports.update = exports.lift = void 0;
var lift_1 = require("./lift");
Object.defineProperty(exports, "lift", { enumerable: true, get: function () { return lift_1.lift; } });
const lift_1 = require("./lift");
var lift_2 = require("./lift");
Object.defineProperty(exports, "lift", { enumerable: true, get: function () { return lift_2.lift; } });
var immupdate_1 = require("./immupdate");

@@ -19,1 +20,9 @@ Object.defineProperty(exports, "update", { enumerable: true, get: function () { return immupdate_1.update; } });

exports.is = isType;
const array_2 = require("./array");
const object_1 = require("./object");
const map_1 = require("./map");
const set_1 = require("./set");
array_2.setArrayPipe(lift_1.pipe);
object_1.setObjectPipe(lift_1.pipe);
map_1.setMapPipe(lift_1.pipe);
set_1.setSetPipe(lift_1.pipe);

@@ -5,7 +5,8 @@ import { ArrayWrapper } from './array';

import { SetWrapper } from './set';
import { Wrapper } from './wrapper';
export declare type Lifted<T> = undefined extends T ? never : null extends T ? never : T extends Wrapper<infer W> ? LiftedValue<W> : LiftedValue<T>;
declare type AtomicObject = Function | Promise<any> | Date | RegExp | Boolean | Number | String;
declare type LiftedValue<T> = null extends T ? never : undefined extends T ? never : T extends AtomicObject ? T : T extends ReadonlyArray<infer E> ? ArrayWrapper<E> : T extends ReadonlyMap<infer K, infer V> ? MapWrapper<K, V> : T extends ReadonlySet<infer E> ? SetWrapper<E> : T extends object ? ObjectWrapper<T> : never;
declare type LiftedValue<T> = null extends T ? never : undefined extends T ? never : T extends AtomicObject ? T : T extends ReadonlyArray<any> ? ArrayWrapper<T> : T extends ReadonlyMap<infer K, infer V> ? MapWrapper<K, V> : T extends ReadonlySet<infer E> ? SetWrapper<E> : T extends object ? ObjectWrapper<T> : never;
interface Lift {
<T>(obj: ArrayWrapper<T>): ArrayWrapper<T>;
<T>(obj: ArrayWrapper<ReadonlyArray<T>>): ArrayWrapper<ReadonlyArray<T>>;
<T extends object>(obj: ObjectWrapper<T>): ObjectWrapper<T>;

@@ -17,3 +18,4 @@ <K, V>(obj: MapWrapper<K, V>): MapWrapper<K, V>;

/** Wraps an Array to provide a richer API. Unwrap with .value() **/
<T>(obj: ReadonlyArray<T>): ArrayWrapper<T>;
<T>(obj: T[]): ArrayWrapper<T[]>;
<T>(obj: ReadonlyArray<T>): ArrayWrapper<ReadonlyArray<T>>;
/** Wraps a Set to provide a richer API. Unwrap with .value() **/

@@ -27,7 +29,4 @@ <T>(obj: ReadonlySet<T>): SetWrapper<T>;

export declare const lift: Lift;
export declare function getValue<A>(input: A | Wrapper<A>): A;
export interface Wrapper<T> {
value(): T;
}
export declare type Pipe = typeof pipe;
export declare function pipe<T, R>(this: Wrapper<T>, func: (object: T) => R): Lifted<R>;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.pipe = exports.getValue = exports.lift = void 0;
exports.pipe = exports.lift = void 0;
const array_1 = require("./array");

@@ -8,5 +8,6 @@ const map_1 = require("./map");

const set_1 = require("./set");
const wrapper_1 = require("./wrapper");
const is = require("./is");
exports.lift = function (obj) {
if (isWrapper(obj))
if (wrapper_1.isWrapper(obj))
return obj;

@@ -23,9 +24,2 @@ if (is.object(obj))

};
function getValue(input) {
return isWrapper(input) ? input.value() : input;
}
exports.getValue = getValue;
function isWrapper(obj) {
return obj && obj['_isLiftWrapper'];
}
function pipe(func) {

@@ -32,0 +26,0 @@ return exports.lift(func(this.value()));

import { Draft } from './immupdate';
import { pipe } from './lift';
import type { Pipe } from './lift';
/** A Map wrapper providing extra functionalities and more chaining opportunities */

@@ -43,4 +43,5 @@ export declare class MapWrapper<K, V> {

update(updateFunction: (draft: Draft<ReadonlyMap<K, V>>) => void): MapWrapper<K, V>;
pipe: typeof pipe;
toArray(): import("./array").ArrayWrapper<[K, V]>;
pipe: typeof import("./lift").pipe;
toArray(): import("./array").ArrayWrapper<[K, V][]>;
}
export declare function setMapPipe(_pipe: Pipe): void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MapWrapper = void 0;
exports.setMapPipe = exports.MapWrapper = void 0;
const immupdate_1 = require("./immupdate");
const lift_1 = require("./lift");
/** A Map wrapper providing extra functionalities and more chaining opportunities */

@@ -11,3 +10,3 @@ class MapWrapper {

this._isLiftWrapper = true;
this.pipe = lift_1.pipe;
this.pipe = pipe;
}

@@ -77,1 +76,6 @@ value() {

exports.MapWrapper = MapWrapper;
let pipe;
function setMapPipe(_pipe) {
pipe = _pipe;
}
exports.setMapPipe = setMapPipe;
import { ArrayWrapper } from './array';
import { Draft } from './immupdate';
import { pipe } from './lift';
import type { Pipe } from './lift';
export declare class ObjectWrapper<T extends object> {

@@ -25,4 +25,4 @@ private _value;

*/
keys(): ArrayWrapper<keyof T>;
pipe: typeof pipe;
keys(): ArrayWrapper<Array<keyof T>>;
pipe: typeof import("./lift").pipe;
/**

@@ -36,3 +36,3 @@ * Removes a key/value from this object and return a new object (and type)

*/
values(): ArrayWrapper<T[keyof T]>;
values(): ArrayWrapper<Array<keyof T>>;
/**

@@ -44,1 +44,2 @@ * Make mutable modifications to a draft then return a new Object.

}
export declare function setObjectPipe(_pipe: Pipe): void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObjectWrapper = void 0;
exports.setObjectPipe = exports.ObjectWrapper = void 0;
const immupdate_1 = require("./immupdate");
const lift_1 = require("./lift");
class ObjectWrapper {

@@ -10,3 +9,3 @@ constructor(_value) {

this._isLiftWrapper = true;
this.pipe = lift_1.pipe;
this.pipe = pipe;
}

@@ -67,1 +66,6 @@ value() {

exports.ObjectWrapper = ObjectWrapper;
let pipe;
function setObjectPipe(_pipe) {
pipe = _pipe;
}
exports.setObjectPipe = setObjectPipe;

@@ -1,2 +0,2 @@

import { pipe } from './lift';
import type { Pipe } from './lift';
/** A Set wrapper providing extra functionalities and more chaining opportunities */

@@ -22,4 +22,5 @@ export declare class SetWrapper<T> {

filter(predicate: (item: T) => boolean): SetWrapper<T>;
toArray(): import("./array").ArrayWrapper<T>;
pipe: typeof pipe;
toArray(): import("./array").ArrayWrapper<T[]>;
pipe: typeof import("./lift").pipe;
}
export declare function setSetPipe(_pipe: Pipe): void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SetWrapper = void 0;
const lift_1 = require("./lift");
exports.setSetPipe = exports.SetWrapper = void 0;
/** A Set wrapper providing extra functionalities and more chaining opportunities */

@@ -10,3 +9,3 @@ class SetWrapper {

this._isLiftWrapper = true;
this.pipe = lift_1.pipe;
this.pipe = pipe;
}

@@ -52,1 +51,6 @@ value() {

exports.SetWrapper = SetWrapper;
let pipe;
function setSetPipe(_pipe) {
pipe = _pipe;
}
exports.setSetPipe = setSetPipe;
import { Draft } from './immupdate';
import { pipe, Wrapper, Lifted } from './lift';
import { Lifted, Pipe } from './lift';
import { Wrapper } from './wrapper';
import { MapWrapper } from './map';
import { SetWrapper } from './set';
/** An Array wrapper providing extra functionalities and more chaining opportunities */
export declare class ArrayWrapper<T> {
export declare class ArrayWrapper<T extends ReadonlyArray<unknown>> {
private _value;
constructor(_value: ReadonlyArray<T>);
constructor(_value: T);
private _isLiftWrapper;
value(): readonly T[];
clone(): ArrayWrapper<T>;
value(): T;
clone(): ArrayWrapper<unknown[]>;
private _clone;

@@ -16,7 +17,7 @@ /**

*/
append(item: T): ArrayWrapper<T>;
append(item: T[number]): ArrayWrapper<T[number][]>;
/**
* Appends an Array of items at the end of the Array.
*/
appendAll(items: T[]): ArrayWrapper<T>;
appendAll(items: ReadonlyArray<T[number]>): ArrayWrapper<unknown[]>;
/**

@@ -26,11 +27,11 @@ * Filters all the falsy elements out of this Array.

*/
compact(): ArrayWrapper<Compacted<T>>;
compact(): ArrayWrapper<ArrayOf<T, Compacted<T[number]>>>;
/**
* Counts the items satisfying a predicate.
*/
count(predicate: (item: T, index: number) => boolean): number;
count(predicate: (item: T[number], index: number) => boolean): number;
/**
* Maps this Array's items, unless void or undefined is returned, in which case the item is filtered.
*/
collect<B>(iterator: (item: T, index: number) => B | undefined | void): ArrayWrapper<B>;
collect<B>(iterator: (item: T[number], index: number) => B | undefined | void): ArrayWrapper<ArrayOf<T, B>>;
/**

@@ -41,3 +42,3 @@ * Creates an array without any duplicate item.

*/
distinct(getKey?: (item: T, index: number) => string | number): ArrayWrapper<T>;
distinct(getKey?: (item: T[number], index: number) => string | number): ArrayWrapper<T>;
/**

@@ -54,32 +55,32 @@ * Drops the first 'count' items from this Array.

*/
filter<A extends T>(predicate: (item: T, index: number) => item is A): ArrayWrapper<A>;
filter<A extends T[number]>(predicate: (item: T[number], index: number) => item is A): ArrayWrapper<ArrayOf<T, A>>;
/**
* Filters this array by aplying a predicate.
*/
filter(predicate: (item: T, index: number) => boolean): ArrayWrapper<T>;
filter(predicate: (item: T[number], index: number) => boolean): ArrayWrapper<T>;
/**
* Returns the first element in this Array or undefined.
*/
first(): T | undefined;
first(): T[number] | undefined;
/**
* Maps this Array to an Array of Array | ArrayWrapper using a mapper function then flattens it.
*/
flatMap<B>(fun: (item: T, index: number) => B[]): ArrayWrapper<B>;
flatMap<B extends ReadonlyArray<any>>(fun: (item: T[number], index: number) => B): ArrayWrapper<B>;
/**
* Maps this Array to an Array of Array | ArrayWrapper using a mapper function then flattens it.
*/
flatMap<B>(fun: (item: T, index: number) => ArrayWrapper<B>): ArrayWrapper<B>;
flatMap<B extends ReadonlyArray<any>>(fun: (item: T[number], index: number) => ArrayWrapper<B>): ArrayWrapper<B>;
/**
* Flattens this Array of Arrays.
*/
flatten<A>(this: ArrayWrapper<ReadonlyArray<A>>): ArrayWrapper<A>;
flatten<A>(this: ArrayWrapper<A[]>): ArrayWrapper<A>;
flatten<A>(this: ArrayWrapper<ReadonlyArray<A>>): ArrayWrapper<ArrayOf<T, A>>;
flatten<A>(this: ArrayWrapper<A[]>): ArrayWrapper<ArrayOf<T, A>>;
/**
* Folds this Array into a single value, using a starting value.
*/
fold<V>(startValue: V, func: (acc: V, value: T, index: number) => V): Lifted<V>;
fold<V>(startValue: V, func: (acc: V, value: T[number], index: number) => V): Lifted<V>;
/**
* Returns the item found at the provided index or undefined.
*/
get(index: number): T | undefined;
get(index: number): T[number] | undefined;
/**

@@ -89,15 +90,15 @@ * Creates a Map where keys are the results of running each element through a discriminator function.

*/
groupBy<K extends string | number>(discriminator: (item: T, index: number) => K): MapWrapper<K, ReadonlyArray<T>>;
groupBy<K extends string | number>(discriminator: (item: T[number], index: number) => K): MapWrapper<K, T>;
/**
* Inserts an item at a specified index.
*/
insert(index: number, item: T): ArrayWrapper<T>;
insert(index: number, item: T[number]): ArrayWrapper<T>;
/**
* Returns the item found at the last index or undefined.
*/
last(): T | undefined;
last(): T[number] | undefined;
/**
* Maps this Array using a mapper function.
*/
map<B>(fun: (item: T, index: number) => B): ArrayWrapper<B>;
map<B>(fun: (item: T[number], index: number) => B): ArrayWrapper<ArrayOf<T, B>>;
/**

@@ -116,3 +117,3 @@ * Removes the item found at the specified index.

*/
sort(...fields: Array<SortOnField<T>>): ArrayWrapper<T>;
sort(...fields: Array<SortOnField<T[number]>>): ArrayWrapper<T>;
/**

@@ -129,3 +130,3 @@ * Takes the first 'count' items from this Array.

*/
toSet(): SetWrapper<T>;
toSet(): SetWrapper<T[number]>;
/**

@@ -135,19 +136,21 @@ * Make mutable modifications to a draft then return a new Array.

*/
update(updateFunction: (draft: Draft<ReadonlyArray<T>>) => void): ArrayWrapper<T>;
update(updateFunction: (draft: Draft<ReadonlyArray<T[number]>>) => void): Lifted<T>;
/**
* Updates an item at the specified index.
*/
updateAt(index: number, updater: (item: T) => Wrapper<T>): ArrayWrapper<T>;
updateAt(index: number, updater: (item: T[number]) => Wrapper<T[number]>): ArrayWrapper<T>;
/**
* Updates an item at the specified index.
*/
updateAt(index: number, updater: (item: T) => T): ArrayWrapper<T>;
updateAt(index: number, updater: (item: T[number]) => T[number]): ArrayWrapper<T>;
/**
* Pipes this Array with an arbitrary transformation function.
*/
pipe: typeof pipe;
pipe: typeof import("./lift").pipe;
}
export declare function range(start: number, stop?: number, step?: number): ArrayWrapper<number>;
export declare function setArrayPipe(_pipe: Pipe): void;
export declare function range(start: number, stop?: number, step?: number): ArrayWrapper<ReadonlyArray<number>>;
declare type SortOnField<T> = ((field: T) => string | null | undefined) | ((field: T) => number | null | undefined);
declare type Compacted<T> = T extends null | undefined | 0 | false ? never : T;
declare type ArrayOf<T extends ReadonlyArray<unknown>, ITEM> = T extends Array<any> ? Array<ITEM> : ReadonlyArray<ITEM>;
export {};
import { identity } from './function';
import { update } from './immupdate';
import { lift, getValue, pipe } from './lift';
import { getValue } from './wrapper';
import { MapWrapper } from './map';

@@ -119,3 +119,3 @@ /** An Array wrapper providing extra functionalities and more chaining opportunities */

fold(startValue, func) {
return lift(this._value.reduce(func, startValue));
return this.pipe(arr => arr.reduce(func, startValue));
}

@@ -246,2 +246,6 @@ /**

}
let pipe;
export function setArrayPipe(_pipe) {
pipe = _pipe;
}
/*

@@ -248,0 +252,0 @@ * Returns a number[] wrapper with all numbers from start to stop (inclusive),

@@ -69,5 +69,10 @@ export function update(obj, updater) {

let low = 0, high = arr.length;
const itemValue = by(item);
while (low < high) {
let mid = (low + high) >>> 1;
if (by(arr[mid]) < by(item))
const mid = (low + high) >>> 1;
const midValue = by(arr[mid]);
const itemValueIsBigger = typeof itemValue === 'string'
? itemValue.localeCompare(midValue) > 0
: itemValue > midValue;
if (itemValueIsBigger)
low = mid + 1;

@@ -74,0 +79,0 @@ else

@@ -0,1 +1,2 @@

import { pipe } from './lift';
export { lift } from './lift';

@@ -9,1 +10,9 @@ export { update } from './immupdate';

export const is = isType;
import { setArrayPipe } from './array';
import { setObjectPipe } from './object';
import { setMapPipe } from './map';
import { setSetPipe } from './set';
setArrayPipe(pipe);
setObjectPipe(pipe);
setMapPipe(pipe);
setSetPipe(pipe);

@@ -5,7 +5,8 @@ import { ArrayWrapper } from './array';

import { SetWrapper } from './set';
import { Wrapper } from './wrapper';
export declare type Lifted<T> = undefined extends T ? never : null extends T ? never : T extends Wrapper<infer W> ? LiftedValue<W> : LiftedValue<T>;
declare type AtomicObject = Function | Promise<any> | Date | RegExp | Boolean | Number | String;
declare type LiftedValue<T> = null extends T ? never : undefined extends T ? never : T extends AtomicObject ? T : T extends ReadonlyArray<infer E> ? ArrayWrapper<E> : T extends ReadonlyMap<infer K, infer V> ? MapWrapper<K, V> : T extends ReadonlySet<infer E> ? SetWrapper<E> : T extends object ? ObjectWrapper<T> : never;
declare type LiftedValue<T> = null extends T ? never : undefined extends T ? never : T extends AtomicObject ? T : T extends ReadonlyArray<any> ? ArrayWrapper<T> : T extends ReadonlyMap<infer K, infer V> ? MapWrapper<K, V> : T extends ReadonlySet<infer E> ? SetWrapper<E> : T extends object ? ObjectWrapper<T> : never;
interface Lift {
<T>(obj: ArrayWrapper<T>): ArrayWrapper<T>;
<T>(obj: ArrayWrapper<ReadonlyArray<T>>): ArrayWrapper<ReadonlyArray<T>>;
<T extends object>(obj: ObjectWrapper<T>): ObjectWrapper<T>;

@@ -17,3 +18,4 @@ <K, V>(obj: MapWrapper<K, V>): MapWrapper<K, V>;

/** Wraps an Array to provide a richer API. Unwrap with .value() **/
<T>(obj: ReadonlyArray<T>): ArrayWrapper<T>;
<T>(obj: T[]): ArrayWrapper<T[]>;
<T>(obj: ReadonlyArray<T>): ArrayWrapper<ReadonlyArray<T>>;
/** Wraps a Set to provide a richer API. Unwrap with .value() **/

@@ -27,7 +29,4 @@ <T>(obj: ReadonlySet<T>): SetWrapper<T>;

export declare const lift: Lift;
export declare function getValue<A>(input: A | Wrapper<A>): A;
export interface Wrapper<T> {
value(): T;
}
export declare type Pipe = typeof pipe;
export declare function pipe<T, R>(this: Wrapper<T>, func: (object: T) => R): Lifted<R>;
export {};

@@ -5,2 +5,3 @@ import { ArrayWrapper } from './array';

import { SetWrapper } from './set';
import { isWrapper } from './wrapper';
import * as is from './is';

@@ -20,10 +21,4 @@ export const lift = function (obj) {

};
export function getValue(input) {
return isWrapper(input) ? input.value() : input;
}
function isWrapper(obj) {
return obj && obj['_isLiftWrapper'];
}
export function pipe(func) {
return lift(func(this.value()));
}
import { Draft } from './immupdate';
import { pipe } from './lift';
import type { Pipe } from './lift';
/** A Map wrapper providing extra functionalities and more chaining opportunities */

@@ -43,4 +43,5 @@ export declare class MapWrapper<K, V> {

update(updateFunction: (draft: Draft<ReadonlyMap<K, V>>) => void): MapWrapper<K, V>;
pipe: typeof pipe;
toArray(): import("./array").ArrayWrapper<[K, V]>;
pipe: typeof import("./lift").pipe;
toArray(): import("./array").ArrayWrapper<[K, V][]>;
}
export declare function setMapPipe(_pipe: Pipe): void;
import { update } from './immupdate';
import { pipe } from './lift';
/** A Map wrapper providing extra functionalities and more chaining opportunities */

@@ -72,1 +71,5 @@ export class MapWrapper {

}
let pipe;
export function setMapPipe(_pipe) {
pipe = _pipe;
}
import { ArrayWrapper } from './array';
import { Draft } from './immupdate';
import { pipe } from './lift';
import type { Pipe } from './lift';
export declare class ObjectWrapper<T extends object> {

@@ -25,4 +25,4 @@ private _value;

*/
keys(): ArrayWrapper<keyof T>;
pipe: typeof pipe;
keys(): ArrayWrapper<Array<keyof T>>;
pipe: typeof import("./lift").pipe;
/**

@@ -36,3 +36,3 @@ * Removes a key/value from this object and return a new object (and type)

*/
values(): ArrayWrapper<T[keyof T]>;
values(): ArrayWrapper<Array<keyof T>>;
/**

@@ -44,1 +44,2 @@ * Make mutable modifications to a draft then return a new Object.

}
export declare function setObjectPipe(_pipe: Pipe): void;
import { clone, update } from './immupdate';
import { pipe } from './lift';
export class ObjectWrapper {

@@ -62,1 +61,5 @@ constructor(_value) {

}
let pipe;
export function setObjectPipe(_pipe) {
pipe = _pipe;
}

@@ -1,2 +0,2 @@

import { pipe } from './lift';
import type { Pipe } from './lift';
/** A Set wrapper providing extra functionalities and more chaining opportunities */

@@ -22,4 +22,5 @@ export declare class SetWrapper<T> {

filter(predicate: (item: T) => boolean): SetWrapper<T>;
toArray(): import("./array").ArrayWrapper<T>;
pipe: typeof pipe;
toArray(): import("./array").ArrayWrapper<T[]>;
pipe: typeof import("./lift").pipe;
}
export declare function setSetPipe(_pipe: Pipe): void;

@@ -1,2 +0,1 @@

import { pipe } from './lift';
/** A Set wrapper providing extra functionalities and more chaining opportunities */

@@ -47,1 +46,5 @@ export class SetWrapper {

}
let pipe;
export function setSetPipe(_pipe) {
pipe = _pipe;
}
{
"name": "space-lift",
"version": "1.0.0-beta.3",
"version": "1.0.0-beta.4",
"description": "Idiomatic Typescript Array, Object, Map, Set, Union, Enum utils",

@@ -5,0 +5,0 @@ "sideEffects": false,

@@ -7,3 +7,3 @@ **space-lift**

# Rich Array/Object wrapper, Option, Result monads
# Rich Array, Object, Map, Set wrapper

@@ -13,7 +13,6 @@ Design goals

- Fun to use
- Correctness and proper typescript typings
- Correctness and first-class typescript typings
- Tiny and performant
- Small set of functions, configurable with lambdas
- Cover 95% of frontend data transformation needs without becoming a bloated lib just to cover the remaining 5%
- Use an OO style as it's the most convenient one without an `|>` operator directly in the language (fingers crossed)

@@ -27,5 +26,2 @@

* [Object](#api.object)
* [Function](#api.function)
* [Option](#api.option)
* [Result](#api.result)
* [enum](#api.enum)

@@ -41,6 +37,7 @@ * [union](#api.union)

```ts
import lift, { Option, Some, None, Result, Ok, Err, update, deepUpdate, DELETE, range, Set, memoize, is, fromArrayLike, tuple } from 'space-lift'
import { lift, update, range, is, createUnion, createEnum, identity, noop } from 'space-lift'
```
`lift` is a generic function that can wrap an Array or Object and give it extra functionalities
`lift` is the main attraction and is used to wrap an Array, Object, Map or Set to give it extra functionalities
`update`, `deepUpdate`, `DELETE` come from [immupdate](https://github.com/AlexGalays/immupdate)

@@ -47,0 +44,0 @@ `Option`, `Some`, `None` are used to work with optional values

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