diff --git a/config/default-options.ts b/config/default-options.ts index 7882924..8d02a62 100644 --- a/config/default-options.ts +++ b/config/default-options.ts @@ -1,4 +1,4 @@ -import { alphabetical } from 'radash/dist/array'; +import { alphabetical } from 'radash'; import type { CalculationOptions } from 'stores/calculation/options/types'; export const selectSeasonType = [ diff --git a/mocks/handlers.js b/mocks/handlers.js index c55e705..ef17014 100644 --- a/mocks/handlers.js +++ b/mocks/handlers.js @@ -1,5 +1,5 @@ import { rest } from 'msw'; -import { random } from 'radash'; +const _ = require('radash'); const users = { akalinina: { @@ -29,8 +29,8 @@ export const handlers = [ rest.post('/api/core/fingap', (req, res, ctx) => { return res( ctx.json({ - sum: random(100000, 200000), - premium: random(1000, 10000), + sum: _.random(100000, 200000), + premium: _.random(1000, 10000), }) ); }), diff --git a/package.json b/package.json index 39ed6a6..f9b0174 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "next-plugin-graphql": "^0.0.2", "next-with-less": "^2.0.5", "normalize.css": "^8.0.1", - "radash": "^7.1.0", + "radash": "^8.0.0", "react": "^18.2.0", "react-dom": "^18.2.0", "rebass": "^4.0.7", diff --git a/process/payments/reactions.ts b/process/payments/reactions.ts index 4b9d5ac..4bf4937 100644 --- a/process/payments/reactions.ts +++ b/process/payments/reactions.ts @@ -4,10 +4,11 @@ import type { ApolloClient } from '@apollo/client'; import type { QueryClient } from '@tanstack/react-query'; import { selectHighSeasonStart, selectSeasonType } from 'config/default-options'; import { comparer, reaction, toJS } from 'mobx'; +import { shift } from 'radash'; import type { CalculationOptions } from 'stores/calculation/options/types'; import type RootStore from 'stores/root'; import type { Row } from 'stores/tables/payments/types'; -import { difference, shift } from 'tools/array'; +import { difference } from 'tools/array'; import * as seasonsConstants from './lib/seasons-constants'; import * as seasonsTools from './lib/seasons-tools'; import validatePaymentsTable from './validation'; diff --git a/process/payments/validation.ts b/process/payments/validation.ts index 5ae0b88..eb75d22 100644 --- a/process/payments/validation.ts +++ b/process/payments/validation.ts @@ -1,8 +1,9 @@ /* eslint-disable max-len */ /* eslint-disable no-case-declarations */ -import { counting, max, min, sort } from 'radash/dist/array'; + +import { counting, max, min, shift, sort } from 'radash'; import type RootStore from 'stores/root'; -import { areEqual, isSorted, shift } from 'tools/array'; +import { areEqual, isSorted } from 'tools/array'; import { SEASONS_PERIODS, SEASONS_PERIOD_NUMBER } from './lib/seasons-constants'; export default function validatePaymentsTable({ $calculation, $tables }: RootStore) { diff --git a/tools/__tests__/array.test.js b/tools/__tests__/array.test.js deleted file mode 100644 index 964b9ec..0000000 --- a/tools/__tests__/array.test.js +++ /dev/null @@ -1,39 +0,0 @@ -import { shift } from 'tools/array'; - -describe('tools/array', () => { - describe('[function] shift', () => { - const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]; - test('should shift array right 3 positions', () => { - const result = shift(arr, 3); - expect(result).toEqual([7, 8, 9, 1, 2, 3, 4, 5, 6]); - }); - test('should shift array left 3 positions', () => { - const result = shift(arr, -3); - expect(result).toEqual([4, 5, 6, 7, 8, 9, 1, 2, 3]); - }); - test('should shift array right 6 positions', () => { - const result = shift(arr, 15); - expect(result).toEqual([4, 5, 6, 7, 8, 9, 1, 2, 3]); - }); - test('should shift array left 6 positions', () => { - const result = shift(arr, -15); - expect(result).toEqual([7, 8, 9, 1, 2, 3, 4, 5, 6]); - }); - test('should keep array as is', () => { - const result = shift(arr, 0); - expect(result).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]); - }); - test('should keep array as is', () => { - const result = shift(arr, 9); - expect(result).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]); - }); - test('should return empty array', () => { - const result = shift([], 0); - expect(result).toEqual([]); - }); - test('should return empty array', () => { - const result = shift([], 0); - expect(result).toEqual([]); - }); - }); -}); diff --git a/tools/array.ts b/tools/array.ts index 3460805..5c3b734 100644 --- a/tools/array.ts +++ b/tools/array.ts @@ -16,16 +16,6 @@ export function difference(arr1: ReadonlyArray, arr2: ReadonlyArray) { return changes; } -export function shift(arr: Array, n: number) { - if (arr.length === 0) return arr; - - const shiftNumber = n % arr.length; - - if (shiftNumber === 0) return arr; - - return [...arr.slice(-shiftNumber, arr.length), ...arr.slice(0, -shiftNumber)]; -} - export function isSorted(arr: Array) { return arr.every((value, index, array) => !index || array[index - 1] <= value); } diff --git a/tools/entity.ts b/tools/entity.ts index 12d2e86..90192f0 100644 --- a/tools/entity.ts +++ b/tools/entity.ts @@ -1,6 +1,6 @@ /* eslint-disable import/prefer-default-export */ import type { BaseOption } from 'Elements/types'; -import { isEmpty } from 'radash/dist/typed'; +import { isEmpty } from 'radash'; export function normalizeOptions(options: any[] | null | undefined) { return (isEmpty(options) ? [] : options) as BaseOption[]; diff --git a/yarn.lock b/yarn.lock index ed514fc..1ab1ff0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7858,10 +7858,10 @@ queue-microtask@^1.2.2: resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243" integrity sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A== -radash@^7.1.0: - version "7.1.0" - resolved "https://registry.yarnpkg.com/radash/-/radash-7.1.0.tgz#b6da541c678368ab3a1f3702057342e944599e92" - integrity sha512-NOWTaF5YMY3mCgrNq9Fw9fK8yvJv92uqRb2StcVq5W8kcJ6949EbV2vk6nLJKAocYs29rzJafZZP1lFkEkoVGw== +radash@^8.0.0: + version "8.0.0" + resolved "https://registry.yarnpkg.com/radash/-/radash-8.0.0.tgz#c3486c0062f2388e6502a85cd51b56264bde7d88" + integrity sha512-OaK3HZDH1I2Yh0+v3nZRcy/OLNviADAk12QepxmLZH2dsQ4SZWEd+YwbZEG/veignExeAJBKfQDiNCZUiXR6iA== rc-align@^4.0.0: version "4.0.11"