delphirtl
Version:
RTL functions from Delphi
321 lines (320 loc) • 10.2 kB
TypeScript
import { FormatDateTime } from "./dateutils";
/**
* Returs true if the given year is a leap year
*
* @param {number} Year
* @returns {boolean}
* @category SysUtils
*/
declare function IsLeapYear(Year: number): boolean;
/**
* Creates the given directory, Dir
*
* @param {string} Dir
* @returns {boolean}
* @category SysUtils
*/
declare function CreateDir(Dir: string): boolean;
/**
* Checks if the given Dir exists or not.
*
* @param {string} Dir
* @returns {boolean}
* @category SysUtils
*/
declare function DirectoryExists(Dir: string): boolean;
export declare const faInvalid = -1;
export declare const faReadOnly = 1;
export declare const faHidden = 2;
export declare const faSysFile = 4;
export declare const faVolumeID = 8;
/**
* The referenced item is a directory
*/
export declare const faDirectory = 16;
export declare const faArchive = 32;
/**
* * The referenced item is a file
*
* @type {128}
*/
export declare const faNormal = 128;
export declare const faTemporary = 256;
export declare const faSymLink = 1024;
export declare const faCompressed = 2048;
export declare const faEncrypted = 16384;
export declare const faVirtual = 65536;
export declare const faAnyFile = 511;
export type TSearchRec = {
Time: number;
/**
* Size of the file
*/
Size: number;
Attr: number;
/**
* File Name
*/
Name: string;
ExcludeAttr: number;
/**
* Last time it was accessed or modified, whichever's later
*
* @type {Date}
*/
LastAccessTime: Date;
/**
* Last modified time
*
* @type {Date}
*/
TimeStamp: Date;
CreationTime: number;
};
export type TFilterPredicate = (path: string, sr: TSearchRec) => boolean;
/**
* Get subdirectories from the given path, using the given predicate to filter out items
*
* @param {string} path
* @param {TFilterPredicate} predicate
* @returns {string[]}
* @category SysUtils
*/
declare function GetDirectories(path: string, predicate: TFilterPredicate): string[];
/**
* Removes the given directory, Dir
*
* @param {string} Dir
* @param {?boolean} [Recursive]
* @returns {boolean}
* @throws ENOENT
* @throws ENOTDIR
* @category SysUtils
*/
declare function RemoveDir(Dir: string, Recursive?: boolean): boolean;
/**
* Gets the current working directory
* @returns The current working directory
* @category SysUtils
*/
declare function GetCurrentDir(): string;
/**
* Changes the current working directory to the specified directory
* @param newDir New working directory
* @category SysUtils
*/
declare function SetCurrentDir(newDir: string): void;
/**
* Extracts the drive and directory parts from AFileName.
* Regardless of whether AFileName is a path or filename,
* this routine returns the path up to the last path.sep
* eg, AFileName contains K:\\Development\\TypeScript\\delphirtl\\tests
* the result is K:\\Development\\TypeScript\\delphirtl
*
* @param {string} AFileNameOrPath
* @returns {string}
* @category SysUtils
*/
declare function ExtractFileDir(AFileNameOrPath: string): string;
/**
* Extracts the file extension, given the filename, AFileName
* For example, if given "Nothing.pas", returns ".pas"
* If given "Nothing", returns ""
*
* @param {string} AFilename
* @returns {string}
* @category SysUtils
*/
declare function ExtractFileExt(AFilename: string): string;
/**
* Extracts the name and extension parts of a file name.
*
* The resulting string is the rightmost characters of FileName, starting with the first character after
* the colon or backslash that separates the path information from the name and extension. The resulting
* string is equal to FileName, if FileName contains no drive and directory parts.
* @param AFileName
* @returns
* @category SysUtils
*/
declare function ExtractFileName(AFileName: string): string;
/**
* Checks if the given filename exists
*
* @param {string} AFileName Filename to check existence for.
* @returns {boolean} true if the given filename exists, false otherwise.
* @category SysUtils
*/
declare function FileExists(AFileName: string): boolean;
/**
* Adds a path delimiter to the given string. If the path delimiter is already at the end of the string, does nothing.
*
* @param {string} APath Given path to check for delimiter to add to
* @returns {string} The path with added delimiter
* @category SysUtils
*/
declare function IncludeTrailingPathDelimiter(APath: string): string;
/**
* Description placeholder
*
* @param {string} str
* @returns {string}
* @category SysUtils
*/
declare function LowerCase(str: string): string;
/**
* Description placeholder
*
* @param {string} str
* @returns {string}
* @category SysUtils
*/
declare function UpperCase(str: string): string;
/**
* Deletes the given name from the environment variable
*
* @param {string} Name
* @category SysUtils
*/
declare function DeleteEnvironmentVariable(Name: string): void;
/**
* Only environment variables starting with ENV_REACT_PREFIX are returned in React
*
* @type {"REACT_APP_"}
* @category Constants
*/
declare const ENV_REACT_PREFIX = "REACT_APP_";
/**
* Only environment variables starting with ENV_NEXT_PREFIX are returned in Nextjs
*
* @type {"NEXT_PUBLIC_"}
* @category Constants
*/
declare const ENV_NEXT_PREFIX = "NEXT_PUBLIC_";
/**
* Only environment variables starting with VITE_PREFIX are returned in Vite
*
* @type {"VITE_"}
* @category Constants
*/
declare const ENV_VITE_PREFIX = "VITE_";
/**
* Retrieves the contents of the specified variable from the environment block
*
* @param Name The name of the environment variable to retrieve
* @returns The value of the given environment variable
* @category SysUtils
*/
declare function GetEnvironmentVariable(Name: string): string;
/**
* Checks if an environment variable exists
*
* @param {string} Name
* @returns {boolean}
* @category SysUtils
*/
declare function ExistsEnvironmentVariable(Name: string): boolean;
/**
* Sets the specified variable in the environment with the given value
*
* @param {string} Name
* @param {string} Value
* @category SysUtils
*/
declare function SetEnvironmentVariable(Name: string, Value: string): void;
/**
* An object
*
* @typedef {ArbitraryObject}
* @category SysUtils
*/
export type ArbitraryObject = {
[key: string]: unknown;
};
/**
* Checks if the given parameter is an object
* @param potentialObj item to check as an object
* @returns boolean
* @category SysUtils
*/
declare function isArbitraryObject(potentialObj: unknown): potentialObj is ArbitraryObject;
/**
* Checks that obj is an object, and it has a field named fieldName and that its type is fieldType
* Assuming e is an object with the field code of type string.
* * If you use this, then the expression following it is valid, for example:
* - hasFieldOfType<string>(e, "code", "string") && e.code === "INSUFFICIENT_FUNDS")
* * If you do not use it, then
* - e.code is invalid when checked by code analyzer
* @param obj
* @param fieldName
* @param fieldType
* @returns
* @category SysUtils
*/
declare function hasFieldOfType<T>(obj: unknown, fieldName: string, fieldType: string): obj is {
[fieldName: string]: T;
};
/**
* Checks if the given object has a message field of string type
*
* @param obj
* @returns
* @category SysUtils
*/
declare function hasMessageField(obj: unknown): obj is {
message: string;
};
type FormatArg = string | number | boolean | bigint | null | undefined;
/**
* Delphi-style Format
* Example: Format('Hello %0:s, you have %1:d item(s), total=%2:.2f', ['World', 3, 12.345])
*/
/**
* Delphi-style Format
* Spec: "%" [index ":"] ["-"] [width] ["." prec] type
* Note that: Index, width, and precision specifiers can be specified directly, using a decimal digit string (for example "%10d"), or indirectly, using an asterisk character (for example "%*.*f")
*
* @param (string) fmt Format specifier
* @param (FormatArg[]) args Arguments to format
* @returns (string) Formatted string
*/
declare function Format(fmt: string, args: FormatArg[]): string;
type TEraInfo = {
EraName: string;
EraOffset: number;
EraStart: Date;
EraEnd: Date;
};
type Char = 'A' | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" | "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "|" | "," | '-' | "/" | "." | "\\" | ":" | " " | "年" | "月" | "日" | '\u07dd' | '\u07da';
declare class FormatSettings {
static CurrencyString: string;
static CurrencyFormat: number;
static CurrencyDecimals: number;
static DateSeparator: Char;
static TimeSeparator: Char;
static ListSeparator: Char;
static ShortDateFormat: string;
static LongDateFormat: string;
static TimeAMString: string;
static TimePMString: string;
static ShortTimeFormat: string;
static LongTimeFormat: string;
static ShortMonthNames: string[];
static LongMonthNames: string[];
static ShortDayNames: string[];
static LongDayNames: string[];
static EraInfo: TEraInfo[];
static ThousandSeparator: Char;
static DecimalSeparator: Char;
static TwoDigitYearCenturyWindow: number;
static NegCurrFormat: number;
static NormalizedLocaleName: string;
}
/**
* This separates the end of a path from a filename
*/
declare const PathDelim: "\\" | "/";
/**
* This separates a path from another path
*/
declare const PathSep: ":" | ";";
export { CreateDir, DirectoryExists, GetDirectories, GetCurrentDir, SetCurrentDir, RemoveDir, ExtractFileDir, ExtractFileExt, ExtractFileName, FileExists, FormatDateTime, Format, FormatSettings, IncludeTrailingPathDelimiter, LowerCase, UpperCase, LowerCase as lowerCase, UpperCase as upperCase, DeleteEnvironmentVariable, ExistsEnvironmentVariable, GetEnvironmentVariable, SetEnvironmentVariable, hasMessageField, hasFieldOfType, isArbitraryObject, IsLeapYear, PathDelim, PathSep, ENV_NEXT_PREFIX, ENV_REACT_PREFIX, ENV_VITE_PREFIX, };