本文整理汇总了TypeScript中util.isString函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isString函数的具体用法?TypeScript isString怎么用?TypeScript isString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isString函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: adminExecuteSql
export async function adminExecuteSql(database: string, sql: SqlBatch): Promise<ISqlDataset[]>|never {
if (!isString(database))
throwError("adminExecuteSql(): database должен быть строкой");
let req: any = {
sessionId:appState.sessionId,
windowId:appState.windowId,
authToken:appState.authToken,
database:database
};
if (isString(sql))
req.sql = [sql];
else if (isArray(sql))
req.sql = sql;
else
throwError("adminExecuteSql(): sql должен быть строкой или массивом строк");
let response: any = await axios.post("api/admin/adminExecuteSql", {xjson:XJSON_stringify(req)});
if (response.data.error)
throwError(response.data.error);
else
return postProcessSqlResult(response.data);
throw "fake";
}
示例2: generateSqlFromTemplate
export async function generateSqlFromTemplate(dialect: SqlDialect, sqlTemplate: string, paramsObj: any = {}): Promise<string> {
if (!isString(sqlTemplate))
throwError( "adminExecuteSql(): параметр 'sqlTemplate' должен быть строкой");
if (!isString(dialect))
throwError( "adminExecuteSql(): параметр 'dialect' должен быть строкой");
let req = {
sessionId:appState.sessionId,
windowId:appState.windowId,
authToken:appState.authToken,
dialect: dialect,
sqlTemplate: sqlTemplate,
// paramsObj: XJSON_stringify(paramsObj),
paramsObj: paramsObj,
};
let response: any = await axios.post("api/admin/generateSqlFromTemplate", {xjson:XJSON_stringify(req)});
if (response.data.error)
throwError( response.data.error);
else
return response.data.sql;
throw "fake";
}
示例3: assertValidRequest
private static assertValidRequest(rawRequest: any, opts: ValidatorOptions) {
if (rawRequest === undefined) {
throw new Error('No data has been provided for favorite');
}
if (opts.checkAllRequiredFields || opts.checkAllRequiredFieldsButId && !utils.isString(rawRequest.name)) {
throw new Error('Name must be specified and of type String');
}
if (opts.checkAllRequiredFields || opts.checkAllRequiredFieldsButId && !utils.isString(rawRequest.folderPath)) {
throw new Error('folderPath must be specified and of type String');
}
}
示例4: assertValidRequest
private static assertValidRequest(rawRequest: any, opts: ValidatorOptions) {
if (rawRequest === undefined) {
throw new Error('No data has been provided for user');
}
if (rawRequest.canWrite && !utils.isBoolean(rawRequest.canWrite)) {
throw new Error('canWrite must be of type Boolean');
}
if (rawRequest.isAdmin && !utils.isBoolean(rawRequest.isAdmin)) {
throw new Error('isAdmin must be of type Boolean');
}
if (rawRequest.homePath && !utils.isString(rawRequest.homePath)) {
throw new Error('homePath must be of type String');
}
if (rawRequest.allowPaths && !utils.isArray(rawRequest.allowPaths)) {
throw new Error('allowPaths must be of type String');
}
if (rawRequest.allowPaths && rawRequest.allowPaths.some(x => !utils.isString(x))) {
throw new Error('allowPaths must contain only Strings');
}
if (rawRequest.denyPaths && !utils.isArray(rawRequest.denyPaths)) {
throw new Error('allowPaths must be of type String');
}
if (rawRequest.denyPaths && rawRequest.denyPaths.some(x => !utils.isString(x))) {
throw new Error('denyPaths must contain only Strings');
}
}
示例5: formatDocument
export async function formatDocument(params: DocumentFormattingParams) {
const edits: TextEdit[] = []
const co = await clientAndObjfromUrl(params.textDocument.uri, true)
if (co) {
const newText = await co.client.prettyPrinter(co.source)
if (isString(newText) && newText) {
const diff = Math.abs(newText.length - co.source.length) / newText.length
// sanity check: if length changed more than 20% ingore
if (diff <= 0.2) {
const lines = co.source.split(/\n/)
const character = lines[lines.length - 1].length
edits.push({
range: {
start: { line: 0, character: 0 },
end: {
line: lines.length,
character
}
},
newText
})
}
}
}
return edits
}
示例6: toInt
export function toInt(raw: any): number {
if (isNaN(raw)) return 0
if (isNumber(raw)) return Math.floor(raw)
if (!raw && !isString(raw)) return 0
const n = Number.parseInt(raw, 10)
if (isNaN(n)) return 0
return n
}
示例7: assertValidRequest
private static assertValidRequest(rawRequest: any, opts: ValidatorOptions) {
if (rawRequest === undefined) {
throw new Error('No data has been provided for user');
}
if (rawRequest.isActive && !utils.isBoolean(rawRequest.isActive)) {
throw new Error('isActive must be of type Boolean');
}
if (rawRequest.username && !utils.isString(rawRequest.username)) {
throw new Error('username must be of type String');
}
if (rawRequest.fullName && !utils.isString(rawRequest.fullName)) {
throw new Error('username must be of type String');
}
if (rawRequest.email && !utils.isString(rawRequest.email)) {
throw new Error('email must be of type String');
}
if (rawRequest.password && !utils.isString(rawRequest.password)) {
throw new Error('hashedPassword must be of type String');
}
}
示例8: executeSql
export async function executeSql(sqlTemplatePath: string, paramsObj: any = {}, dbName: string = config.mainDatabaseName): Promise<ISqlDataset[]> {
if (!isString(sqlTemplatePath)) {
let msg = "executeSql(): параметр 'sqlTemplatePath' должен быть строкой";
console.error(msg, sqlTemplatePath);
throwError( msg);
}
if (!isString(dbName)) {
let msg = "executeSql(): параметр 'dbName' должен быть строкой";
console.error(msg, dbName);
throwError( msg);
}
if (typeof paramsObj !== "object") {
throwError("executeSql(): параметр 'paramsObj' должен быть объектом", paramsObj);
// let msg = "executeSql(): параметр 'paramsObj' должен быть объектом";
// console.error(msg, paramsObj);
// throw msg;
}
let req = {
sessionId:appState.sessionId,
windowId:appState.windowId,
authToken:appState.authToken,
sqlTemplatePath: sqlTemplatePath,
// paramsObj: XJSON_stringify(paramsObj),
paramsObj: paramsObj,
dbName: dbName
};
let response: any = await axios.post("api/executeSql", {xjson:XJSON_stringify(req)});
if (response.data.error)
throwError( response.data.error);
else
return postProcessSqlResult(response.data)
throw "fake";
}
示例9: isString
export const log = (...params: any) => {
let msg = ""
for (const x of params) {
try {
if (isError(x)) msg += `\nError ${x.name}\n${x.message}\n\n${x.stack}\n`
else msg += isString(x) ? x : JSON.stringify(x)
} catch (e) {
msg += x.toString()
}
msg += " "
}
connection.console.log(msg)
}
示例10: dump
function dump(out: any): void {
let outText = "";
if (isBoolean(out)) {
outText = "| Boolean: ";
}
if (isNumber(out)) {
outText = "| Number: ";
}
if (isString(out)) {
outText = "| String: ";
}
if (isArray(out)) {
outText = "| Array: ";
}
console.log(outText, out);
}