Skip to content

Commit

Permalink
refactor(stark-all): update lodash usage
Browse files Browse the repository at this point in the history
This commit will refactor all used instances of `const (.*) = require("lodash/(.*)")` to `import (.*) from "lodash/(.*)"`

ISSUES CLOSED: #150
  • Loading branch information
carlo-nomes committed Feb 26, 2019
1 parent 458e93f commit 44b2475
Show file tree
Hide file tree
Showing 31 changed files with 6,016 additions and 6,649 deletions.
1,882 changes: 813 additions & 1,069 deletions package-lock.json

Large diffs are not rendered by default.

5,782 changes: 2,734 additions & 3,048 deletions packages/stark-build/package-lock.json

Large diffs are not rendered by default.

59 changes: 14 additions & 45 deletions packages/stark-core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { TranslateService } from "@ngx-translate/core";
import { StarkLocale } from "./locale.intf";
import { commonCoreTranslations } from "./common-translations";

/**
* @ignore
*/
const _cloneDeep: Function = require("lodash/cloneDeep");
import cloneDeep from "lodash-es/cloneDeep";

/**
* This function can be used by Stark modules to merge their translations into existing translations,
Expand Down Expand Up @@ -36,7 +32,7 @@ const _cloneDeep: Function = require("lodash/cloneDeep");
* mergeTranslations(this.translateService, english, french, dutch);
*/
export function mergeTranslations(translateService: TranslateService, ...localesToMerge: StarkLocale[]): void {
const currentTranslations: object = _cloneDeep(translateService.translations);
const currentTranslations: object = cloneDeep(translateService.translations);

for (const locale of localesToMerge) {
translateService.setTranslation(locale.languageCode, commonCoreTranslations[locale.languageCode], false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ import { StarkFlushLogMessages, StarkLogMessageAction } from "../actions";
import { selectStarkLogging } from "../reducers";
import { StarkError, StarkErrorImpl } from "../../../common/error";
import { StarkConfigurationUtil } from "../../../util/configuration.util";

/**
* @ignore
*/
const _noop: Function = require("lodash/noop");
import noop from "lodash-es/noop";

const xsrfServiceNotFound: "not provided" = "not provided";

Expand Down Expand Up @@ -246,7 +242,7 @@ export class StarkLoggingServiceImpl implements StarkLoggingService {
*/
protected getConsole(type: string): Function {
const console: any = window && window.console ? window.console : {};
const logFn: Function = console[type] || console.log || _noop;
const logFn: Function = console[type] || console.log || noop;

return (...args: any[]): any => {
const consoleArgs: any[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ import { StarkStateConfigWithParams } from "./state-config-with-params.intf";
import { StarkCoreApplicationState } from "../../../common/store";
import { StarkConfigurationUtil } from "../../../util/configuration.util";
import { starkAppExitStateName, starkAppInitStateName } from "../../session/constants";

/**
* @ignore
*/
const _isEmpty: Function = require("lodash/isEmpty");
import isEmpty from "lodash-es/isEmpty";

/**
* @ignore
Expand Down Expand Up @@ -515,7 +511,7 @@ export class StarkRoutingServiceImpl implements StarkRoutingService {
(pathNode.state === this.getCurrentState() || this.isParentState(pathNode.state))
) {
const resolvablesData: { [key: string]: any } = this.extractResolvablesData(pathNode.resolvables);
const stateResolves: any = _isEmpty(resolvablesData) ? undefined : resolvablesData;
const stateResolves: any = isEmpty(resolvablesData) ? undefined : resolvablesData;
stateTreeResolves.set(pathNode.state.name, stateResolves);
}
}
Expand Down Expand Up @@ -548,7 +544,7 @@ export class StarkRoutingServiceImpl implements StarkRoutingService {
pathNode.state !== pathNode.state.root() &&
(pathNode.state === this.getCurrentState() || this.isParentState(pathNode.state))
) {
const stateData: any = _isEmpty(pathNode.state.data) ? undefined : pathNode.state.data;
const stateData: any = isEmpty(pathNode.state.data) ? undefined : pathNode.state.data;
stateTreeData.set(pathNode.state.name, stateData);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/**
* @ignore
*/
const _floor: Function = require("lodash/floor");
import floor from "lodash-es/floor";

import { isValidBBAN } from "ibantools";

Expand Down Expand Up @@ -42,7 +39,7 @@ export function starkIsBBAN(bban: string, countryCode: string = ""): boolean {
*/
function calculateCheckDigit(bbanNumber: string): number {
const firstPart: number = parseInt(bbanNumber.substring(0, bbanNumber.length - 2), 10);
let checkDigit: number = _floor(firstPart % 97);
let checkDigit: number = floor(firstPart % 97);
if (checkDigit === 0) {
checkDigit = 97;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/**
* @ignore
*/
const _floor: Function = require("lodash/floor");
import floor from "lodash-es/floor";

/**
* @ignore
Expand Down Expand Up @@ -36,7 +33,7 @@ export function starkIsEstablishmentUnitNumber(establishmentNumber: string): boo
const numberToCheck: number = parseInt(enterpriseNumber.substring(0, controlNumberBeginIndex), 10);

// We validate 8 first digits with a mod-97 checksum algorithm
isValid = 97 - _floor(numberToCheck % 97) === controlNumber;
isValid = 97 - floor(numberToCheck % 97) === controlNumber;
}

return isValid;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/**
* @ignore
*/
const _floor: Function = require("lodash/floor");
import floor from "lodash-es/floor";

/**
* @ignore
Expand Down Expand Up @@ -45,12 +42,12 @@ export function starkIsISIN(isin: string): boolean {
digit *= 2;
}

sum += _floor(digit / modulo);
sum += floor(digit / modulo);
sum += digit % modulo;
}

const currentCheckDigit: number = parseInt(isin[lengthWithoutCheckDigit], base);
const expectedCheckDigit: number = sum % modulo === 0 ? 0 : (_floor(sum / modulo) + 1) * modulo - sum;
const expectedCheckDigit: number = sum % modulo === 0 ? 0 : (floor(sum / modulo) + 1) * modulo - sum;
isValid = currentCheckDigit === expectedCheckDigit;
}
return isValid;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/**
* @ignore
*/
const _floor: Function = require("lodash/floor");
import floor from "lodash-es/floor";

/**
* @ignore
Expand Down Expand Up @@ -79,7 +76,7 @@ function isValidBelgianNin(nin: string): boolean {
const numberToCheck19thCentury: number = parseInt(getBirthDate(nin) + getOrder(nin), 10);
const numberToCheck20thCentury: number = parseInt("2" + getBirthDate(nin) + getOrder(nin), 10);

return 97 - _floor(numberToCheck19thCentury % 97) === checkDigits || 97 - _floor(numberToCheck20thCentury % 97) === checkDigits;
return 97 - floor(numberToCheck19thCentury % 97) === checkDigits || 97 - floor(numberToCheck20thCentury % 97) === checkDigits;
}
}

Expand Down
79 changes: 24 additions & 55 deletions packages/stark-testing/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 44b2475

Please sign in to comment.