delphirtl
Version:
RTL functions from Delphi
254 lines (253 loc) • 7.65 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: number;
Attr: number;
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_";
/**
* 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;
};
export { CreateDir, DirectoryExists, GetDirectories, GetCurrentDir, SetCurrentDir, RemoveDir, ExtractFileDir, ExtractFileExt, ExtractFileName, FileExists, FormatDateTime, IncludeTrailingPathDelimiter, LowerCase, UpperCase, LowerCase as lowerCase, UpperCase as upperCase, DeleteEnvironmentVariable, ExistsEnvironmentVariable, GetEnvironmentVariable, SetEnvironmentVariable, hasMessageField, hasFieldOfType, isArbitraryObject, IsLeapYear, ENV_NEXT_PREFIX, ENV_REACT_PREFIX };