本文整理汇总了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;
}, {});
}
};