# Kaven-Basic

## Declaration

```typescript
export { Greeter } from "./Greeter";
import "babel-polyfill";
export declare type IndexObject = {
    [index: string]: any;
};
export declare enum DateTimeFormat {
    FullDataTime = "YYYY-MM-DD HH:mm:ss.SSS",
    ForFileName = "YYYY_MM_DD HH_mm_ss_SSS",
    YearMonth = "YYYYMM",
    YearMonthDay = "YYYY-MM-DD",
    YearMonthDayHourMinute = "YYYY-MM-DD HH:mm",
    DATETIME_LOCAL = "YYYY-MM-DDTHH:mm",
    DATETIME_LOCAL_SECONDS = "YYYY-MM-DDTHH:mm:ss",
    DATETIME_LOCAL_MS = "YYYY-MM-DDTHH:mm:ss.SSS",
    DATE = "YYYY-MM-DD",
    TIME = "HH:mm",
    TIME_SECONDS = "HH:mm:ss",
    TIME_MS = "HH:mm:ss.SSS",
    WEEK = "YYYY-[W]WW",
    MONTH = "YYYY-MM",
    CN_DATE = "YYYY\u5E74MM\u6708DD\u65E5",
}
export declare enum TimeUnit {
    milliseconds = "milliseconds",
    seconds = "seconds",
    minutes = "minutes",
    hours = "hours",
    days = "days",
    weeks = "weeks",
    months = "months",
    years = "years",
}
export declare enum TimeFactor {
    milliseconds = 1,
    seconds = 1000,
    minutes = 60000,
    hours = 3600000,
    days = 86400000,
    weeks = 604800000,
    months = 2592000000,
    years = 31536000000,
}
export declare enum LogLevel {
    Log = "Log",
    Info = "Info",
    Warn = "Warn",
    Error = "Error",
}
export declare class Strings {
    static readonly Empty: string;
    static readonly WhiteSpace: string;
    static readonly Tab: string;
    static readonly LF: string;
    static readonly CR: string;
    static readonly CR_LF: string;
    static readonly HTML_BR: string;
    static readonly HTML_NBSP: string;
    static readonly LowercaseLetters: string;
    static readonly UppercaseLetters: string;
    static readonly Numbers: string;
    static readonly PasswordSpecialCharacters: string;
    static readonly Slash: string;
    static readonly BackSlash: string;
    static readonly DoubleQuotes: string;
    static readonly RunningMode: string;
    static readonly Development: string;
    static readonly Production: string;
    static readonly Dot: string;
    static readonly Unknown: string;
    static readonly Success: string;
    static readonly Failure: string;
    static readonly true: string;
    static readonly false: string;
}
export declare class HttpStatusCode {
    static readonly Continue: number;
    static readonly SwitchingProtocols: number;
    static readonly OK: number;
    static readonly Created: number;
    static readonly Accepted: number;
    static readonly NonAuthoritativeInformation: number;
    static readonly NoContent: number;
    static readonly ResetContent: number;
    static readonly PartialContent: number;
    static readonly MultipleChoices: number;
    static readonly Ambiguous: number;
    static readonly MovedPermanently: number;
    static readonly Moved: number;
    static readonly Found: number;
    static readonly Redirect: number;
    static readonly SeeOther: number;
    static readonly RedirectMethod: number;
    static readonly NotModified: number;
    static readonly UseProxy: number;
    static readonly Unused: number;
    static readonly TemporaryRedirect: number;
    static readonly RedirectKeepVerb: number;
    static readonly BadRequest: number;
    static readonly Unauthorized: number;
    static readonly PaymentRequired: number;
    static readonly Forbidden: number;
    static readonly NotFound: number;
    static readonly MethodNotAllowed: number;
    static readonly NotAcceptable: number;
    static readonly ProxyAuthenticationRequired: number;
    static readonly RequestTimeout: number;
    static readonly Conflict: number;
    static readonly Gone: number;
    static readonly LengthRequired: number;
    static readonly PreconditionFailed: number;
    static readonly RequestEntityTooLarge: number;
    static readonly RequestUriTooLong: number;
    static readonly UnsupportedMediaType: number;
    static readonly RequestedRangeNotSatisfiable: number;
    static readonly ExpectationFailed: number;
    static readonly InternalServerError: number;
    static readonly NotImplemented: number;
    static readonly BadGateway: number;
    static readonly ServiceUnavailable: number;
    static readonly GatewayTimeout: number;
    static readonly HttpVersionNotSupported: number;
}
export declare class MailConfigBase {
    Host: string;
    Port: number;
    SSL: boolean;
    User: string;
    Password: string;
    constructor(
        host: string,
        port: number,
        ssl: boolean,
        user: string,
        password: string
    );
    static GetEmailAddressWithName(name: string, address: string): string;
    static IsEmailAddressValid(email: string): boolean;
}
export declare class MailOption {
    From: string;
    To: string;
    Subject?: string;
    Text?: string;
    HTML?: string;
    constructor(
        from: string,
        to: string,
        subject?: string,
        text?: string,
        html?: string
    );
}
export declare enum BitStringType {
    BIN = "BIN",
    HEX = "HEX",
}
export declare class BitString {
    private _binStr;
    private static readonly _padStart;
    private static readonly _radix16;
    constructor(initialValue?: string, type?: BitStringType);
    readonly Length: number;
    SetBit(offset: number, val: boolean): BitString;
    GetBit(offset: number, defaultVal?: boolean): boolean;
    toString(type?: BitStringType): string;
}
declare global {
    interface Date {
        Format(format?: string): string;
        AddMilliseconds(ms: number): Date;
        AddSeconds(seconds: number): Date;
        AddMinutes(minutes: number): Date;
        AddHours(hours: number): Date;
        AddDays(days: number): Date;
        AddWeeks(weeks: number): Date;
        AddMonths(months: number): Date;
        AddQuarters(quarters: number): Date;
        AddYears(years: number): Date;
        SubtractMilliseconds(ms: number): Date;
        SubtractSeconds(seconds: number): Date;
        SubtractMinutes(minutes: number): Date;
        SubtractHours(hours: number): Date;
        SubtractDays(days: number): Date;
        SubtractWeeks(weeks: number): Date;
        SubtractMonths(months: number): Date;
        SubtractQuarters(quarters: number): Date;
        SubtractYears(years: number): Date;
        DiffMilliseconds(anotherDate: Date): number;
        DiffMonths(anotherDate: Date): number;
        DiffYears(anotherDate: Date): number;
    }
    interface DateConstructor {
        Create(): Date;
    }
    interface Console {
        logOrigin(message?: any, ...optionalParams: any[]): void;
        infoOrigin(message?: any, ...optionalParams: any[]): void;
        warnOrigin(message?: any, ...optionalParams: any[]): void;
        errorOrigin(message?: any, ...optionalParams: any[]): void;
    }
    interface String {
        ReplaceAll(old: string, rep: string): string;
        ReplaceAt(index: number, rep: string): string;
        TrimStart(trim: string): string;
        TrimEnd(trim: string): string;
        IsNotEmpty(): boolean;
        IsEmpty(): boolean;
        padStart(targetLength: number, padString?: string): string;
        endsWith(searchString: string, length?: number): boolean;
        GetIndent(): string;
        OnlyContains(...characters: string[]): boolean;
        ToArray(): string[];
        Distinct(): string;
    }
    interface Array<T> {
        includes(searchElement: T, fromIndex?: number): boolean;
        IsNotEmpty(): boolean;
        Remove(index: number): Array<T>;
        Distinct(): Array<T>;
        First(): T;
        Last(): T;
    }
    interface Number {
        ToMilliseconds(currentUnit: TimeUnit): number;
        ToSeconds(currentUnit: TimeUnit): number;
        ToMinutes(currentUnit: TimeUnit): number;
        ToHours(currentUnit: TimeUnit): number;
        ToDays(currentUnit: TimeUnit): number;
        ToWeeks(currentUnit: TimeUnit): number;
        ToMonths(currentUnit: TimeUnit): number;
        ToYears(currentUnit: TimeUnit): number;
    }
}
export declare class KavenBasic {
    private static readonly _memoryCacheCollection;
    private static readonly _memoryCollection;
    static SetCacheWithDate(
        name: string,
        value: any,
        absoluteExpiration: Date
    ): void;
    static SetCacheWithMilliseconds(
        name: string,
        value: any,
        millisecond: number
    ): void;
    static SetCacheWithMinute(name: string, value: any, minute: number): void;
    static SetCacheWithHour(name: string, value: any, hour: number): void;
    static GetCache<T>(name: string): T | undefined;
    static RemoveCache(name?: string, removeExpired?: boolean): void;
    static FormatDate(dt?: Date, format?: string): string;
    static GetFileNameByDateTime(): string;
    static GetStackInfo(depth?: number): any;
    static GetRandomArbitrary(min: number, max: number): number;
    static GetRandomInt(min: number, max: number): number;
    static GenerateNumberString(length: number): string;
    static GenerateYearMonthId(
        randomLength?: number,
        validFunc?: (id: string) => boolean,
        ignoreIDs?: string[],
        candidatesGUID?: string
    ): string;
    static GenerateYearMonthIdAsync(
        randomLength?: number,
        validFunc?: (id: string) => Promise<boolean>,
        ignoreIDs?: string[],
        candidatesGUID?: string
    ): Promise<string>;
    static GenerateGuid(): string;
    static GenerateRandomString(
        length: number,
        validCharacters?: string
    ): string;
    static GeneratePassword(
        length: number,
        numbers?: boolean,
        lowercaseLetters?: boolean,
        uppercaseLetters?: boolean,
        specialCharacters?: boolean
    ): string;
    static RunTest(func: () => void, times: number): void;
    static RandomBoolean(): boolean;
    static GetBaseDir(pathStr: string): string;
    static GetFileExtension(fileName: string): string;
    static GetFileName(fileName: string): string;
    static ChangeFileExtension(fileName: string, extension: string): string;
    static SetValue(name: string, value: any): void;
    static GetValue(name: string, defaultValueIfNotExist?: any): any;
    static RemoveValue(name: string): void;
    static RemoveEmpty(obj: {}): {};
    static SortByKey(obj: {}): {};
    static CreateArray(length: number, start: number, step?: number): number[];
    static GetStringBetween(
        str: string,
        strStart: string,
        strEnd: string,
        max?: number
    ): string[];
    static SplitStringByNewline(str: string): string[] | undefined;
    static RemoveInvalidCharactersForPath(pathStr: string): string;
    static GetNextVersion(version: string): string | number | undefined;
    static SplitCamelCaseString(camelCaseStr: string): string;
    static DoUntilSuccess(
        action: () => boolean,
        timeout?: number,
        retryCount?: number,
        startImmediately?: boolean
    ): void;
    static Countdown(
        action: (left?: number) => void,
        count: number,
        interval: number | undefined,
        runWhenStart: boolean | undefined,
        completeAction: () => void
    ): void;
    static EncodeByRFC3986(str: string): string;
    static UpdateQueryString(param: string, value: string, url: string): string;
}
export declare class APIRequestBase {
    URL: string;
    Action: string;
    Parameters: {
        [name: string]: string;
    };
    static readonly Timestamp: string;
    static readonly SignatureNonce: string;
    static readonly Signature: string;
    constructor(url: string, action?: string);
    AddParameter(name: string, val: string): this;
    AddTimestamp(): this;
    AddSignatureNonce(): this;
    Make(
        accessSecret: string,
        signatureMethod: (strToSign: string, accessSecret: string) => string,
        encodeURIMethod?: (uri: string) => string
    ): string;
}
```

## FAQ

-   Clipboard operation not working on Ubuntu?

```
Couldn't find the required `xsel` binary.

On Debian/Ubuntu you can install it with:

sudo apt install xsel
```
