本文整理匯總了TypeScript中arrify.default方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript arrify.default方法的具體用法?TypeScript arrify.default怎麽用?TypeScript arrify.default使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類arrify
的用法示例。
在下文中一共展示了arrify.default方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
extend: function(Class, methods) {
if (Class.name !== 'Job') {
return;
}
methods = arrify(methods);
assert.deepStrictEqual(methods, ['getQueryResults']);
extended = true;
},
示例2: function
extend: function(Class, methods) {
if (Class.name !== 'BigQuery') {
return;
}
methods = arrify(methods);
assert.strictEqual(Class.name, 'BigQuery');
assert.deepStrictEqual(methods, ['getDatasets', 'getJobs']);
extended = true;
},
示例3: test
function test(val?: string | string[]) {
arrify(val);
}
示例4: test
import * as arrify from 'arrify';
/***************** arrify<T> *****************/
arrify(null);
arrify<number>(null);
arrify(undefined);
arrify<number>(undefined);
arrify(1);
arrify([2, 3]);
function test(val?: string | string[]) {
arrify(val);
}
/***************** arrify<T> *****************/
/***************** arrify<T1, T2> *****************/
arrify<number, string>(undefined); // returns []
arrify<number, string>(null); // returns []
{
const value: number | string[] = 2018;
arrify<number, string>(value); // returns [2018]
}
{
const value: number[] | string | string[] = ['a', 'b'];
arrify<number, string>(value); // returns ['a', 'b']
}
示例5: arrify
(BigQuery as any).mergeSchemaWithRows_ = BigQuery.prototype.mergeSchemaWithRows_ = function(
schema,
rows
) {
return arrify(rows)
.map(mergeSchema)
.map(flattenRows);
function mergeSchema(row) {
return row.f.map(function(field, index) {
const schemaField = schema.fields[index];
let value = field.v;
if (schemaField.mode === 'REPEATED') {
value = value.map(function(val) {
return convert(schemaField, val.v);
});
} else {
value = convert(schemaField, value);
}
const fieldObject = {};
fieldObject[schemaField.name] = value;
return fieldObject;
});
}
function convert(schemaField, value) {
if (is.nil(value)) {
return value;
}
switch (schemaField.type) {
case 'BOOLEAN':
case 'BOOL': {
value = value.toLowerCase() === 'true';
break;
}
case 'BYTES': {
value = Buffer.from(value, 'base64');
break;
}
case 'FLOAT':
case 'FLOAT64': {
value = parseFloat(value);
break;
}
case 'INTEGER':
case 'INT64': {
value = parseInt(value, 10);
break;
}
case 'NUMERIC': {
value = new Big(value);
break;
}
case 'RECORD': {
value = (BigQuery as any).mergeSchemaWithRows_(schemaField, value).pop();
break;
}
case 'DATE': {
value = (BigQuery as any).date(value);
break;
}
case 'DATETIME': {
value = (BigQuery as any).datetime(value);
break;
}
case 'TIME': {
value = (BigQuery as any).time(value);
break;
}
case 'TIMESTAMP': {
value = (BigQuery as any).timestamp(new Date(value * 1000));
break;
}
}
return value;
}
function flattenRows(rows) {
return rows.reduce(function(acc, row) {
const key = Object.keys(row)[0];
acc[key] = row[key];
return acc;
}, {});
}
};