# Variable utils

utils: {
allReturnDirectives: string[];
apply: (f: any, ...x: any[]) => any;
applyAsync: (f: any, ...x: any[]) => Promise<any>;
asyncMap: (xs: any[], asyncF: Function) => Promise<any[]>;
cloneName: (name: string, allNames: string[]) => string;
comparing: (
f: string | ((o: any) => any),
) => (a: any, b: any) => -1 | 0 | 1;
comparingCaseInsensitive: (k: string) => (a: any, b: any) => -1 | 0 | 1;
comparingCaseInsensitiveValue: (a: any, b: any) => -1 | 0 | 1;
dataModulePath: string;
dollarizeObject: (state: object) => { [k: string]: any };
ensure_final_slash: (s: string) => string;
escapeHtml: (str: string) => string;
extractPagings: (state: any) => any;
filesWithEnding: (directory: string, ending: string) => string[];
flatEqual: (a: any, b: any) => boolean;
getFetchProxyOptions: () => | { agent: HttpsProxyAgent<string> }
| { agent?: undefined };
getLines: (filename: string, lineCount: number) => Promise<string>;
getSafeBaseUrl: () => any;
getSafeSaltcornCmd: () => string;
getSessionId: (req: Req) => string;
hashState: (state: any, viewname: string) => string;
hashString: (s: string) => string;
imageAvailable: (
imageName: string,
preferedVersion: string,
) => Promise<
| { installed: boolean; version: any }
| { installed: boolean; version?: undefined },
>;
interpolate: (
s: string,
row: any,
user?: any,
errorLocation?: string,
) => string;
InvalidAdminAction: typeof InvalidAdminAction;
InvalidConfiguration: typeof InvalidConfiguration;
isEmpty: (o: GenObj) => boolean;
isNode: () => boolean;
isOfflineMode: () => boolean;
isPushEnabled: (user?: User) => user is User;
isRoot: () => boolean;
isStale: (date: string | Date, hours?: number) => boolean;
isTest: () => boolean;
isWeb: (req: Req) => boolean;
jsIdentifierValidator: (
s: string,
_: any,
field?: { required: boolean },
) => string | undefined;
mergeActionResults: (result: ResultType, stepres: StepResType) => void;
mergeConnectedObjects: (
lhs: ConnectedObjects,
rhs: ConnectedObjects,
) => ConnectedObjects;
mergeIntoWhere: (where: Where, newWhere: GenObj) => Where;
NotAuthorized: typeof NotAuthorized;
nubBy: (prop: string, xs: any[]) => any[];
numberToBool: (b: boolean) => number | boolean;
objectToQueryString: (o: Object) => string;
pluginsFolderRoot: string;
ppVal: (x: any) => any;
prefixFieldsInWhere: (inputWhere: any, tablePrefix: string) => Where;
prepMobileRows: (rows: Row[], fields: Field[]) => Row[];
removeAllWhiteSpace: (s: string) => string;
removeDefaultColor: (obj: GenObj) => GenObj;
removeEmptyStrings: (obj: GenObj) => GenObj;
removeEmptyStringsKeepNull: (obj: GenObj) => GenObj;
removeNonWordChars: (str: string) => string;
renderServerSide: (viewname: string, state: any) => Promise<any>;
returnDirectivesOnly: (
o: GenObj | null | undefined,
) => GenObj | null | undefined;
safeEnding: (file: string, ending: string) => string;
satisfies: (where: Where) => (obj: any) => boolean;
secondaryReturnDirectives: Record<string, string[]>;
sleep: (ms: number) => Promise<unknown>;
stringToJSON: (v: any) => any;
structuredClone: (obj: any) => any;
urlStringToObject: (url: string) => any;
validSqlId: (s: string) => string;
}

#### Type Declaration

- ##### allReturnDirectives: string[]

- ##### apply: (f: any, ...x: any[]) => any

- ##### applyAsync: (f: any, ...x: any[]) => Promise<any>

- ##### asyncMap: (xs: any[], asyncF: Function) => Promise<any[]>

- ##### cloneName: (name: string, allNames: string[]) => string

- ##### comparing: (f: string | ((o: any) => any)) => (a: any, b: any) => -1 | 0 | 1

  Compare objects (for Array.sort) by property name or function

- ##### comparingCaseInsensitive: (k: string) => (a: any, b: any) => -1 | 0 | 1

- ##### comparingCaseInsensitiveValue: (a: any, b: any) => -1 | 0 | 1

- ##### dataModulePath: string

- ##### dollarizeObject: (state: object) => { [k: string]: any }

- ##### ensure_final_slash: (s: string) => string

  Ensure that string is finished with /

- ##### escapeHtml: (str: string) => string

- ##### extractPagings: (state: any) => any

- ##### filesWithEnding: (directory: string, ending: string) => string[]

  find all files with specific ending

- ##### flatEqual: (a: any, b: any) => boolean

  flat comparison of two objects (fast for comparing objects with primitive values, only first level)

- ##### getFetchProxyOptions: () => { agent: HttpsProxyAgent<string> } | { agent?: undefined }

- ##### getLines: (filename: string, lineCount: number) => Promise<string>

- ##### getSafeBaseUrl: () => any

  get base_url config without ending slash

- ##### getSafeSaltcornCmd: () => string

  check if 'saltcorn' is in the PATH env or build a full path

- ##### getSessionId: (req: Req) => string

  returns the session id

- ##### hashState: (state: any, viewname: string) => string

  create a hash from a state object so that views with identical type can be uniquely identified "_page", "_pagesize", "_sortby", "_sortdesc" are ecxluded

- ##### hashString: (s: string) => string

  create a sha1 hash from a string

- ##### imageAvailable: (
  imageName: string,
  preferedVersion: string,
  ) => Promise<
  | { installed: boolean; version: any }
  | { installed: boolean; version?: undefined },
  >

- ##### interpolate: (s: string, row: any, user?: any, errorLocation?: string) => string

- ##### InvalidAdminAction: typeof InvalidAdminAction

- ##### InvalidConfiguration: typeof InvalidConfiguration

- ##### isEmpty: (o: GenObj) => boolean

- ##### isNode: () => boolean

  returns true if it's a node enviroment, false if it's webpack bundled code

- ##### isOfflineMode: () => boolean

- ##### isPushEnabled: (user?: User) => user is User

- ##### isRoot: () => boolean

- ##### `Function` isStale: (date: string | Date, hours?: number) => boolean

- ##### isTest: () => boolean

- ##### isWeb: (req: Req) => boolean

  returns true if it's node and not a 'saltcorn mobile requeset' a saltcorn mobile request is identified by the smr header

- ##### jsIdentifierValidator: (s: string, _: any, field?: { required: boolean }) => string | undefined

- ##### mergeActionResults: (result: ResultType, stepres: StepResType) => void

- ##### mergeConnectedObjects: (lhs: ConnectedObjects, rhs: ConnectedObjects) => ConnectedObjects

  merges the arrays from 'lhs' and 'rhs'

- ##### mergeIntoWhere: (where: Where, newWhere: GenObj) => Where

- ##### NotAuthorized: typeof NotAuthorized

- ##### nubBy: (prop: string, xs: any[]) => any[]

- ##### numberToBool: (b: boolean) => number | boolean

- ##### objectToQueryString: (o: Object) => string

- ##### pluginsFolderRoot: string

- ##### ppVal: (x: any) => any

- ##### prefixFieldsInWhere: (inputWhere: any, tablePrefix: string) => Where

- ##### prepMobileRows: (rows: Row[], fields: Field[]) => Row[]

- ##### removeAllWhiteSpace: (s: string) => string

- ##### removeDefaultColor: (obj: GenObj) => GenObj

- ##### removeEmptyStrings: (obj: GenObj) => GenObj

- ##### removeEmptyStringsKeepNull: (obj: GenObj) => GenObj

- ##### removeNonWordChars: (str: string) => string

- ##### renderServerSide: (viewname: string, state: any) => Promise<any>

  Mobile helper to render views with the 'mobile_render_server_side' flag server-side

- ##### returnDirectivesOnly: (o: GenObj | null | undefined) => GenObj | null | undefined

- ##### safeEnding: (file: string, ending: string) => string

- ##### satisfies: (where: Where) => (obj: any) => boolean

- ##### secondaryReturnDirectives: Record<string, string[]>

- ##### sleep: (ms: number) => Promise<unknown>

- ##### stringToJSON: (v: any) => any

- ##### structuredClone: (obj: any) => any

- ##### urlStringToObject: (url: string) => any

- ##### validSqlId: (s: string) => string

- Defined in packages/saltcorn-data/utils.ts:683