Skip to content

Commit 926c9f8

Browse files
fix: remove is package as dependency (#1500)
* fix: remove dep on is package * fix: remove other is usages * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 02db74e commit 926c9f8

File tree

4 files changed

+80
-27
lines changed

4 files changed

+80
-27
lines changed

‎package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
"big.js": "^6.2.2",
5858
"duplexify": "^4.1.3",
5959
"extend": "^3.0.2",
60-
"is": "^3.3.0",
6160
"stream-events": "^1.0.5"
6261
},
6362
"overrides": {

‎src/bigquery.ts‎

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,17 @@ import * as common from '@google-cloud/common';
2525
import {paginator, ResourceStream} from '@google-cloud/paginator';
2626
import {promisifyAll} from '@google-cloud/promisify';
2727
import {PreciseDate} from '@google-cloud/precise-date';
28-
import {toArray} from './util';
28+
import {
29+
toArray,
30+
isArray,
31+
isString,
32+
isObject,
33+
isDate,
34+
isBoolean,
35+
isNumber,
36+
} from './util';
2937
import * as Big from 'big.js';
3038
import * as extend from 'extend';
31-
import * as is from 'is';
3239
import {randomUUID} from 'crypto';
3340

3441
import {Dataset, DatasetOptions} from './dataset';
@@ -1071,13 +1078,13 @@ export class BigQuery extends Service {
10711078
'RANGE',
10721079
];
10731080

1074-
if (is.array(providedType)) {
1081+
if (isArray(providedType)) {
10751082
providedType = providedType as Array<ProvidedTypeStruct | string | []>;
10761083
return {
10771084
type: 'ARRAY',
10781085
arrayType: BigQuery.getTypeDescriptorFromProvidedType_(providedType[0]),
10791086
};
1080-
} else if (is.object(providedType)) {
1087+
} else if (isObject(providedType)) {
10811088
return {
10821089
type: 'STRUCT',
10831090
structTypes: Object.keys(providedType).map(prop => {
@@ -1147,7 +1154,7 @@ export class BigQuery extends Service {
11471154
type: value.elementType,
11481155
},
11491156
};
1150-
} else if (Array.isArray(value)) {
1157+
} else if (isArray(value)) {
11511158
if (value.length === 0) {
11521159
throw new Error(
11531160
"Parameter types must be provided for empty arrays via the 'types' field in query options.",
@@ -1157,11 +1164,11 @@ export class BigQuery extends Service {
11571164
type: 'ARRAY',
11581165
arrayType: BigQuery.getTypeDescriptorFromValue_(value[0]),
11591166
};
1160-
} else if (is.boolean(value)) {
1167+
} else if (isBoolean(value)) {
11611168
typeName = 'BOOL';
1162-
} else if (is.number(value)) {
1169+
} else if (isNumber(value)) {
11631170
typeName = (value as number) % 1 === 0 ? 'INT64' : 'FLOAT64';
1164-
} else if (is.object(value)) {
1171+
} else if (isObject(value)) {
11651172
return {
11661173
type: 'STRUCT',
11671174
structTypes: Object.keys(value as object).map(prop => {
@@ -1172,7 +1179,7 @@ export class BigQuery extends Service {
11721179
};
11731180
}),
11741181
};
1175-
} else if (is.string(value)) {
1182+
} else if (isString(value)) {
11761183
typeName = 'STRING';
11771184
}
11781185

@@ -1207,7 +1214,7 @@ export class BigQuery extends Service {
12071214
value: any,
12081215
providedType?: string | ProvidedTypeStruct | ProvidedTypeArray,
12091216
) {
1210-
if (is.date(value)) {
1217+
if (isDate(value)) {
12111218
value = BigQuery.timestamp(value as Date);
12121219
}
12131220
let parameterType: bigquery.IQueryParameterType;
@@ -1223,8 +1230,8 @@ export class BigQuery extends Service {
12231230
queryParameter.parameterValue!.arrayValues = (value as Array<{}>).map(
12241231
itemValue => {
12251232
const value = BigQuery._getValue(itemValue, parameterType.arrayType!);
1226-
if (is.object(value) || is.array(value)) {
1227-
if (is.array(providedType)) {
1233+
if (isObject(value) || isArray(value)) {
1234+
if (isArray(providedType)) {
12281235
providedType = providedType as [];
12291236
return BigQuery.valueToQueryParameter_(value, providedType[0])
12301237
.parameterValue!;
@@ -1271,7 +1278,7 @@ export class BigQuery extends Service {
12711278
value: rangeValue.value.end,
12721279
},
12731280
};
1274-
} else if (typeName === 'JSON' && is.object(value)) {
1281+
} else if (typeName === 'JSON' && isObject(value)) {
12751282
queryParameter.parameterValue!.value = JSON.stringify(value);
12761283
} else {
12771284
queryParameter.parameterValue!.value = BigQuery._getValue(
@@ -1586,7 +1593,7 @@ export class BigQuery extends Service {
15861593
params: undefined,
15871594
};
15881595
}
1589-
const parameterMode = is.array(params) ? 'positional' : 'named';
1596+
const parameterMode = isArray(params) ? 'positional' : 'named';
15901597
const queryParameters: bigquery.IQueryParameter[] = [];
15911598
if (parameterMode === 'named') {
15921599
const namedParams = params as {[param: string]: any};
@@ -1595,7 +1602,7 @@ export class BigQuery extends Service {
15951602
let queryParameter;
15961603

15971604
if (types) {
1598-
if (!is.object(types)) {
1605+
if (!isObject(types)) {
15991606
throw new Error(
16001607
'Provided types must match the value type passed to `params`',
16011608
);
@@ -1620,7 +1627,7 @@ export class BigQuery extends Service {
16201627
}
16211628
} else {
16221629
if (types) {
1623-
if (!is.array(types)) {
1630+
if (!isArray(types)) {
16241631
throw new Error(
16251632
'Provided types must match the value type passed to `params`',
16261633
);
@@ -2466,7 +2473,7 @@ function convertSchemaFieldValue(
24662473
parseJSON?: boolean;
24672474
},
24682475
) {
2469-
if (is.null(value)) {
2476+
if (value === null) {
24702477
return value;
24712478
}
24722479

@@ -2783,7 +2790,7 @@ export class BigQueryTime {
27832790
const h = value.hours;
27842791
const m = value.minutes || 0;
27852792
const s = value.seconds || 0;
2786-
const f = is.defined(value.fractional) ? '.' + value.fractional : '';
2793+
const f = value.fractional !== undefined ? '.' + value.fractional : '';
27872794
value = `${h}:${m}:${s}${f}`;
27882795
}
27892796
this.value = value as string;

‎src/table.ts‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ import {
2525
} from '@google-cloud/common';
2626
import {paginator, ResourceStream} from '@google-cloud/paginator';
2727
import {promisifyAll} from '@google-cloud/promisify';
28-
import {toArray} from './util';
28+
import {isArray, isString, isDate, toArray} from './util';
2929
import * as Big from 'big.js';
3030
import * as extend from 'extend';
3131
import {once} from 'events';
3232
import * as fs from 'fs';
33-
import * as is from 'is';
3433
import * as path from 'path';
3534
import * as streamEvents from 'stream-events';
3635
import {randomUUID} from 'crypto';
@@ -592,11 +591,11 @@ class Table extends ServiceObject {
592591
return (value as {value: {}}).value;
593592
}
594593

595-
if (is.date(value)) {
594+
if (isDate(value)) {
596595
return (value as Date).toJSON();
597596
}
598597

599-
if (is.array(value)) {
598+
if (isArray(value)) {
600599
return (value as []).map(Table.encodeValue_);
601600
}
602601

@@ -625,11 +624,11 @@ class Table extends ServiceObject {
625624
delete (body as TableMetadata).name;
626625
}
627626

628-
if (is.string(options.schema)) {
627+
if (isString(options.schema)) {
629628
body.schema = Table.createSchemaFromString_(options.schema as string);
630629
}
631630

632-
if (is.array(options.schema)) {
631+
if (isArray(options.schema)) {
633632
body.schema = {
634633
fields: options.schema as [],
635634
};
@@ -644,14 +643,14 @@ class Table extends ServiceObject {
644643
});
645644
}
646645

647-
if (is.string(options.partitioning)) {
646+
if (isString(options.partitioning)) {
648647
body.timePartitioning = {
649648
type: options.partitioning!.toUpperCase(),
650649
};
651650
delete (body as TableMetadata).partitioning;
652651
}
653652

654-
if (is.string(options.view)) {
653+
if (isString(options.view)) {
655654
body.view = {
656655
query: options.view! as string,
657656
useLegacySql: false,

‎src/util.ts‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,51 @@ export function toArray(value: any) {
3535

3636
return [value];
3737
}
38+
39+
/**
40+
* Check if value is an object.
41+
* @internal
42+
*/
43+
export function isObject(value: any) {
44+
return value && [undefined, Object].includes(value.constructor);
45+
}
46+
47+
/**
48+
* Check if value is an object.
49+
* @internal
50+
*/
51+
export function isString(value: any) {
52+
return Object.prototype.toString.call(value) === '[object String]';
53+
}
54+
55+
/**
56+
* Check if value is an array.
57+
* @internal
58+
*/
59+
export function isArray(value: any) {
60+
return Array.isArray(value);
61+
}
62+
63+
/**
64+
* Check if value is an instance of Date.
65+
* @internal
66+
*/
67+
export function isDate(value: any) {
68+
return value instanceof Date;
69+
}
70+
71+
/**
72+
* Check if value is a boolean.
73+
* @internal
74+
*/
75+
export function isBoolean(value: any) {
76+
return Object.prototype.toString.call(value) === '[object Boolean]';
77+
}
78+
79+
/**
80+
* Check if value is a number.
81+
* @internal
82+
*/
83+
export function isNumber(value: any) {
84+
return Object.prototype.toString.call(value) === '[object Number]';
85+
}

0 commit comments

Comments
 (0)