utilitaire
Version:
Common utils for JavaScript and Typescript development
93 lines (87 loc) • 2.63 kB
TypeScript
declare module "utilitaires" {
// Generated by dts-bundle v0.5.0
const U: {
Option: typeof Option;
HasDescriptor: typeof HasDescriptor;
deepAssign: (target: {
[propName: string]: any;
}, source: {
[propName: string]: any;
}) => {
[propName: string]: any;
};
};
export default U;
/**
* The Option type encapsulates an optional value.
* A value of type Option<T> either :
* - contains a value of type T,
* - or it is empty (represented as None).
*
* Using Option is a good way to deal with null and undefined.
*/
export abstract class Option<T> {
protected _value: T;
/**
* Returns the option's value.
* @note The option must be nonEmpty and this will return
* undefined if the option is empty.
*/
value: T;
valueOrElse(value: T): T;
valueOrNull(): T;
isDefined(): boolean;
isEmpty(): boolean;
flatMap<U>(fn: (T) => Option<U>): Option<U>;
map<U>(fn: (T) => U): Option<U>;
forEach(fn: (T) => void): void;
static isDefinedValue(value: any): boolean;
static of<T>(value: T): Option<T>;
static empty<T>(): Option<T>;
}
export class Some<T> extends Option<T> {
constructor(_value: T);
}
/**
* Here we use the instance of {} as instance of None. Indeed, the '{}' can be
* viewed as an instance of Option because of the Option class definition.
* as we did not defined a '_value' attribute, every call to the isDefined() method
* will always yield false. It is then enough to have a correct working Option instance
* For example see the 'map', and 'foreach' method definition.
*
* @type {Option<typeof undefined>}
*/
export const None: Option<any>;
export class HasDescriptor<Desc extends JsObject, UDesc extends JsObject> {
protected desc: Desc;
constructor(desc: Desc);
updateInPlace(updateDescriptor: UDesc): this;
copy(updateDescriptor: UDesc): this;
}
/**
* A JsObject is a definition of Json that is not a
* primitive value nor an array.
*/
export type JsObject = {
[propName: string]: any;
};
/**
*
* @param item
* @returns {any|boolean}
*/
export function isObject(item: any): boolean;
global {
interface ObjectConstructor {
assign(target: any, ...sources: any[]): any;
}
}
/**
*
* @param target
* @param source
* @returns {({}&any)|any}
*/
export default function deepAssign(target: JsObject, source: JsObject): JsObject;
export {};
}