Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

Commit 2753dd1

Browse files
authored
chore: remove is dependency (#2358)
1 parent 380e770 commit 2753dd1

11 files changed

Lines changed: 237 additions & 58 deletions

File tree

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
"google-auth-library": "^10.0.0-rc.1",
7979
"google-gax": "^5.0.1-rc.0",
8080
"grpc-gcp": "^1.0.1",
81-
"is": "^3.3.0",
8281
"lodash.snakecase": "^4.1.1",
8382
"merge-stream": "^2.0.0",
8483
"p-queue": "^6.0.2",

src/batch-transaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import {PreciseDate} from '@google-cloud/precise-date';
1818
import {promisifyAll} from '@google-cloud/promisify';
1919
import * as extend from 'extend';
20-
import * as is from 'is';
2120
import {
2221
ExecuteSqlRequest,
2322
ReadCallback,
@@ -36,6 +35,7 @@ import {
3635
} from '../src/common';
3736
import {startTrace, setSpanError, traceConfig} from './instrument';
3837
import {injectRequestIDIntoHeaders} from './request_id_header';
38+
import {isString} from './helper';
3939

4040
export interface TransactionIdentifier {
4141
session: string | Session;
@@ -450,7 +450,7 @@ class BatchTransaction extends Snapshot {
450450
*/
451451
executeStream(partition) {
452452
// TODO: Instrument the streams with Otel.
453-
if (is.string(partition.table)) {
453+
if (isString(partition.table)) {
454454
return this.createReadStream(partition.table, partition);
455455
}
456456
return this.runStream(partition);

src/codec.ts

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,21 @@
1515
*/
1616
import {GrpcService} from './common-grpc/service';
1717
import {PreciseDate} from '@google-cloud/precise-date';
18-
import {toArray} from './helper';
18+
import {
19+
isArray,
20+
isBoolean,
21+
isDate,
22+
isDecimal,
23+
isInfinite,
24+
isInteger,
25+
isNull,
26+
isNumber,
27+
isObject,
28+
isString,
29+
isUndefined,
30+
toArray,
31+
} from './helper';
1932
import {Big} from 'big.js';
20-
import * as is from 'is';
2133
import {common as p} from 'protobufjs';
2234
import {google as spannerClient} from '../protos/protos';
2335
import {GoogleError} from 'google-gax';
@@ -440,19 +452,19 @@ export class Interval {
440452
* @param nanoseconds nanoseconds part of the `Interval`
441453
*/
442454
constructor(months: number, days: number, nanoseconds: bigint) {
443-
if (!is.integer(months)) {
455+
if (!isInteger(months)) {
444456
throw new GoogleError(
445457
`Invalid months: ${months}, months should be an integral value`,
446458
);
447459
}
448460

449-
if (!is.integer(days)) {
461+
if (!isInteger(days)) {
450462
throw new GoogleError(
451463
`Invalid days: ${days}, days should be an integral value`,
452464
);
453465
}
454466

455-
if (is.null(nanoseconds) || is.undefined(nanoseconds)) {
467+
if (isNull(nanoseconds) || isUndefined(nanoseconds)) {
456468
throw new GoogleError(
457469
`Invalid nanoseconds: ${nanoseconds}, nanoseconds should be a valid bigint value`,
458470
);
@@ -502,7 +514,7 @@ export class Interval {
502514
* Constructs an `Interval` with specified seconds.
503515
*/
504516
static fromSeconds(seconds: number): Interval {
505-
if (!is.integer(seconds)) {
517+
if (!isInteger(seconds)) {
506518
throw new GoogleError(
507519
`Invalid seconds: ${seconds}, seconds should be an integral value`,
508520
);
@@ -518,7 +530,7 @@ export class Interval {
518530
* Constructs an `Interval` with specified milliseconds.
519531
*/
520532
static fromMilliseconds(milliseconds: number): Interval {
521-
if (!is.integer(milliseconds)) {
533+
if (!isInteger(milliseconds)) {
522534
throw new GoogleError(
523535
`Invalid milliseconds: ${milliseconds}, milliseconds should be an integral value`,
524536
);
@@ -534,7 +546,7 @@ export class Interval {
534546
* Constructs an `Interval` with specified microseconds.
535547
*/
536548
static fromMicroseconds(microseconds: number): Interval {
537-
if (!is.integer(microseconds)) {
549+
if (!isInteger(microseconds)) {
538550
throw new GoogleError(
539551
`Invalid microseconds: ${microseconds}, microseconds should be an integral value`,
540552
);
@@ -817,7 +829,7 @@ function decode(
817829
type: spannerClient.spanner.v1.Type,
818830
columnMetadata?: object,
819831
): Value {
820-
if (is.null(value)) {
832+
if (isNull(value)) {
821833
return null;
822834
}
823835

@@ -954,11 +966,11 @@ function encode(value: Value): p.IValue {
954966
* @returns {*}
955967
*/
956968
function encodeValue(value: Value): Value {
957-
if (is.number(value) && !is.decimal(value)) {
969+
if (isNumber(value) && !isDecimal(value)) {
958970
return value.toString();
959971
}
960972

961-
if (is.date(value)) {
973+
if (isDate(value)) {
962974
return value.toJSON();
963975
}
964976

@@ -990,7 +1002,7 @@ function encodeValue(value: Value): Value {
9901002
return Array.from(value).map(field => encodeValue(field.value));
9911003
}
9921004

993-
if (is.array(value)) {
1005+
if (isArray(value)) {
9941006
return value.map(encodeValue);
9951007
}
9961008

@@ -1002,7 +1014,7 @@ function encodeValue(value: Value): Value {
10021014
return value.toISO8601();
10031015
}
10041016

1005-
if (is.object(value)) {
1017+
if (isObject(value)) {
10061018
return JSON.stringify(value);
10071019
}
10081020

@@ -1099,17 +1111,17 @@ interface FieldType extends Type {
10991111
*/
11001112
function getType(value: Value): Type {
11011113
const isSpecialNumber =
1102-
is.infinite(value) || (is.number(value) && isNaN(value));
1114+
isInfinite(value) || (isNumber(value) && isNaN(value));
11031115

11041116
if (value instanceof Float32) {
11051117
return {type: 'float32'};
11061118
}
11071119

1108-
if (is.decimal(value) || isSpecialNumber || value instanceof Float) {
1120+
if (isDecimal(value) || isSpecialNumber || value instanceof Float) {
11091121
return {type: 'float64'};
11101122
}
11111123

1112-
if (is.number(value) || value instanceof Int) {
1124+
if (isNumber(value) || value instanceof Int) {
11131125
return {type: 'int64'};
11141126
}
11151127

@@ -1141,11 +1153,11 @@ function getType(value: Value): Type {
11411153
return {type: 'enum', fullName: value.fullName};
11421154
}
11431155

1144-
if (is.boolean(value)) {
1156+
if (isBoolean(value)) {
11451157
return {type: 'bool'};
11461158
}
11471159

1148-
if (is.string(value)) {
1160+
if (isString(value)) {
11491161
return {type: 'string'};
11501162
}
11511163

@@ -1157,7 +1169,7 @@ function getType(value: Value): Type {
11571169
return {type: 'date'};
11581170
}
11591171

1160-
if (is.date(value)) {
1172+
if (isDate(value)) {
11611173
return {type: 'timestamp'};
11621174
}
11631175

@@ -1170,13 +1182,13 @@ function getType(value: Value): Type {
11701182
};
11711183
}
11721184

1173-
if (is.array(value)) {
1185+
if (isArray(value)) {
11741186
let child;
11751187

11761188
for (let i = 0; i < value.length; i++) {
11771189
child = value[i];
11781190

1179-
if (!is.null(child)) {
1191+
if (!isNull(child)) {
11801192
break;
11811193
}
11821194
}
@@ -1187,7 +1199,7 @@ function getType(value: Value): Type {
11871199
};
11881200
}
11891201

1190-
if (is.object(value)) {
1202+
if (isObject(value)) {
11911203
return {type: 'json'};
11921204
}
11931205

src/common-grpc/service.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,19 @@ import * as duplexify from 'duplexify';
3737
import {EventEmitter} from 'events';
3838
import * as extend from 'extend';
3939
import {grpc, GrpcClient} from 'google-gax';
40-
import * as is from 'is';
4140
import {Request, Response} from 'teeny-request';
4241
import * as retryRequest from 'retry-request';
4342
import {Duplex, PassThrough} from 'stream';
43+
import {
44+
isArray,
45+
isBoolean,
46+
isError,
47+
isNull,
48+
isNumber,
49+
isObject,
50+
isString,
51+
isUndefined,
52+
} from '../helper';
4453

4554
const gaxProtoPath = path.join(
4655
path.dirname(require.resolve('google-gax')),
@@ -265,7 +274,7 @@ export class ObjectToStructConverter {
265274
for (const prop in obj) {
266275
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
267276
const value = obj[prop];
268-
if (is.undefined(value)) {
277+
if (isUndefined(value)) {
269278
continue;
270279
}
271280
convertedObject.fields[prop] = this.encodeValue_(value);
@@ -292,27 +301,27 @@ export class ObjectToStructConverter {
292301
encodeValue_(value: {}) {
293302
let convertedValue;
294303

295-
if (is.null(value)) {
304+
if (isNull(value)) {
296305
convertedValue = {
297306
nullValue: 0,
298307
};
299-
} else if (is.number(value)) {
308+
} else if (isNumber(value)) {
300309
convertedValue = {
301310
numberValue: value,
302311
};
303-
} else if (is.string(value)) {
312+
} else if (isString(value)) {
304313
convertedValue = {
305314
stringValue: value,
306315
};
307-
} else if (is.boolean(value)) {
316+
} else if (isBoolean(value)) {
308317
convertedValue = {
309318
boolValue: value,
310319
};
311320
} else if (Buffer.isBuffer(value)) {
312321
convertedValue = {
313322
blobValue: value,
314323
};
315-
} else if (is.object(value)) {
324+
} else if (isObject(value)) {
316325
if (this.seenObjects.has(value)) {
317326
// Circular reference.
318327
if (!this.removeCircular) {
@@ -331,7 +340,7 @@ export class ObjectToStructConverter {
331340
structValue: this.convert(value),
332341
};
333342
}
334-
} else if (is.array(value)) {
343+
} else if (isArray(value)) {
335344
convertedValue = {
336345
listValue: {
337346
values: (value as Array<{}>).map(this.encodeValue_.bind(this)),
@@ -723,7 +732,7 @@ export class GrpcService extends Service {
723732
const grpcMetadata = this.grpcMetadata;
724733
const grpcOpts: GrpcOptions = {};
725734

726-
if (is.number(protoOpts.timeout)) {
735+
if (isNumber(protoOpts.timeout)) {
727736
grpcOpts.deadline = GrpcService.createDeadline_(protoOpts.timeout);
728737
}
729738

@@ -821,7 +830,7 @@ export class GrpcService extends Service {
821830
* @return {error|null}
822831
*/
823832
static decorateError_(err: Error): Error | null {
824-
const errorObj = is.error(err) ? err : {};
833+
const errorObj = isError(err) ? err : {};
825834
return GrpcService.decorateGrpcResponse_(errorObj, err);
826835
}
827836

0 commit comments

Comments
 (0)