Skip to content

Commit bb4620d

Browse files
Merge pull request #1264 from opencomponents/remove-lodash-typeof-checks
[INTERNAL] Replace lodash type checkers with typeof
2 parents 975fc16 + 5020f7d commit bb4620d

File tree

6 files changed

+23
-26
lines changed

6 files changed

+23
-26
lines changed

src/cli/facade/dev.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ const dev =
3838
const port = opts.port || 3000;
3939
const baseUrl = opts.baseUrl || `http://localhost:${port}/`;
4040
const fallbackRegistryUrl = opts.fallbackRegistryUrl;
41-
const hotReloading = _.isUndefined(opts.hotReloading)
42-
? true
43-
: opts.hotReloading;
44-
const optWatch = _.isUndefined(opts.watch) ? true : opts.watch;
41+
const hotReloading =
42+
typeof opts.hotReloading === 'undefined' ? true : opts.hotReloading;
43+
const optWatch = typeof opts.watch === 'undefined' ? true : opts.watch;
4544
let packaging = false;
4645

4746
const watchForChanges = function (
@@ -71,7 +70,7 @@ const dev =
7170
componentsDirs: string[],
7271
optCb?: () => void
7372
) => {
74-
const cb = _.isFunction(optCb) ? optCb : _.noop;
73+
const cb = typeof optCb === 'function' ? optCb : _.noop;
7574

7675
let i = 0;
7776

src/registry/domain/options-sanitiser.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,28 @@ export default function optionsSanitiser(input: Input): Config {
3737
options.tempDir = settings.registry.defaultTempPath;
3838
}
3939

40-
if (!_.isBoolean(options.hotReloading)) {
40+
if (typeof options.hotReloading !== 'boolean') {
4141
options.hotReloading = !!options.local;
4242
}
4343

44-
if (_.isUndefined(options.verbosity)) {
44+
if (!options.verbosity) {
4545
options.verbosity = 0;
4646
}
4747

48-
if (_.isUndefined(options.discovery)) {
48+
if (typeof options.discovery === 'undefined') {
4949
options.discovery = true;
5050
}
5151

52-
if (_.isUndefined(options.pollingInterval)) {
52+
if (typeof options.pollingInterval === 'undefined') {
5353
options.pollingInterval = 5;
5454
}
5555

56-
if (_.isUndefined(options.templates)) {
56+
if (!options.templates) {
5757
options.templates = [];
5858
}
5959

6060
if (
61-
!_.isUndefined(options.fallbackRegistryUrl) &&
61+
typeof options.fallbackRegistryUrl !== 'undefined' &&
6262
_.last(options.fallbackRegistryUrl) !== '/'
6363
) {
6464
options.fallbackRegistryUrl += '/';

src/registry/domain/plugins-initialiser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ function validatePlugins(plugins: unknown[]): asserts plugins is Plugin[] {
1212
c++;
1313
if (
1414
!_.isObject((plugin as Plugin).register) ||
15-
!_.isFunction((plugin as Plugin).register.register) ||
16-
!_.isFunction((plugin as Plugin).register.execute) ||
17-
!_.isString((plugin as Plugin).name)
15+
typeof (plugin as Plugin).register.register !== 'function' ||
16+
typeof (plugin as Plugin).register.execute !== 'function' ||
17+
typeof (plugin as Plugin).name !== 'string'
1818
) {
1919
throw new Error(
2020
strings.errors.registry.PLUGIN_NOT_VALID(

src/registry/domain/repository.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,14 @@ export default function repository(conf: Config): Repository {
132132
componentVersionOrCallback: string | Callback<Component, string>,
133133
callbackMaybe?: Callback<Component, string>
134134
) {
135-
const componentVersion: string | undefined = _.isFunction(
136-
componentVersionOrCallback
137-
)
138-
? undefined
139-
: (componentVersionOrCallback as any);
140-
const callback: Callback<Component, string> = _.isFunction(
141-
componentVersionOrCallback
142-
)
143-
? (componentVersionOrCallback as any)
144-
: callbackMaybe!;
135+
const componentVersion: string | undefined =
136+
typeof componentVersionOrCallback === 'function'
137+
? undefined
138+
: (componentVersionOrCallback as any);
139+
const callback: Callback<Component, string> =
140+
typeof componentVersionOrCallback === 'function'
141+
? (componentVersionOrCallback as any)
142+
: callbackMaybe!;
145143

146144
repository.getComponentVersions(componentName, (err, allVersions) => {
147145
if (err) {

src/registry/routes/components.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default function components(
4444
return returnError(
4545
registryErrors.BATCH_ROUTE_COMPONENTS_PROPERTY_MISSING
4646
);
47-
} else if (!_.isArray(components)) {
47+
} else if (!Array.isArray(components)) {
4848
return returnError(registryErrors.BATCH_ROUTE_COMPONENTS_NOT_ARRAY);
4949
}
5050

test/unit/registry-domain-nested-renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('registry : routes : helpers : nested-renderer', () => {
1212
let renderer;
1313

1414
const initialise = function (rendererMocks, conf) {
15-
if (_.isArray(rendererMocks)) {
15+
if (Array.isArray(rendererMocks)) {
1616
renderer = sinon.stub();
1717

1818
_.each(rendererMocks, (rendererMock, i) => {

0 commit comments

Comments
 (0)