-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
121 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,34 @@ | ||
import { Expression, StatementsExpression, SyntaxType } from '../types'; | ||
import { type Expression, type StatementsExpression, SyntaxType } from '../types'; | ||
|
||
export class CommonUtils { | ||
static toArray(val: any): any[] | undefined { | ||
if (val === undefined || val === null) { | ||
return undefined; | ||
} | ||
return Array.isArray(val) ? val : [val]; | ||
export function toArray(val: any): any[] | undefined { | ||
if (val === undefined || val === null) { | ||
return undefined; | ||
} | ||
return Array.isArray(val) ? val : [val]; | ||
} | ||
|
||
static getLastElement<T>(arr: T[]): T | undefined { | ||
if (!arr.length) { | ||
return undefined; | ||
} | ||
return arr[arr.length - 1]; | ||
export function getLastElement<T>(arr: T[]): T | undefined { | ||
if (!arr.length) { | ||
return undefined; | ||
} | ||
return arr[arr.length - 1]; | ||
} | ||
|
||
static convertToStatementsExpr(...expressions: Expression[]): StatementsExpression { | ||
return { | ||
type: SyntaxType.STATEMENTS_EXPR, | ||
statements: expressions, | ||
}; | ||
} | ||
export function convertToStatementsExpr(...expressions: Expression[]): StatementsExpression { | ||
return { | ||
type: SyntaxType.STATEMENTS_EXPR, | ||
statements: expressions, | ||
}; | ||
} | ||
|
||
static CreateAsyncFunction(...args) { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function, func-names | ||
return async function () {}.constructor(...args); | ||
} | ||
export function CreateAsyncFunction(...args) { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function, func-names | ||
return async function () {}.constructor(...args); | ||
} | ||
|
||
static escapeStr(s?: string): string { | ||
if (typeof s !== 'string') { | ||
return ''; | ||
} | ||
return `'${s.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`; | ||
export function escapeStr(s?: string): string { | ||
if (typeof s !== 'string') { | ||
return ''; | ||
} | ||
return `'${s.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.