Skip to content

Commit

Permalink
refactor: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
behzadam committed Dec 20, 2022
1 parent d84df72 commit bd517a0
Show file tree
Hide file tree
Showing 43 changed files with 205 additions and 205 deletions.
18 changes: 9 additions & 9 deletions rollup.config.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import type { OutputOptions, RollupOptions } from "rollup";
import { defineRollupSwcOption, swc } from "rollup-plugin-swc3";
import { readFileSync } from "node:fs";
import type { OutputOptions, RollupOptions } from 'rollup';
import { defineRollupSwcOption, swc } from 'rollup-plugin-swc3';
import { readFileSync } from 'node:fs';

const pkg = JSON.parse(
readFileSync(new URL("./package.json", import.meta.url)).toString()
readFileSync(new URL('./package.json', import.meta.url)).toString(),
);

const outputs: OutputOptions[] = [
{ file: pkg.main, format: "cjs", exports: "auto" },
{ file: pkg.module, format: "es" },
{ file: pkg.browser, format: "umd", name: pkg.name },
{ file: pkg.main, format: 'cjs', exports: 'auto' },
{ file: pkg.module, format: 'es' },
{ file: pkg.browser, format: 'umd', name: pkg.name },
];

const config: RollupOptions = {
input: "./src/index.ts",
input: './src/index.ts',
output: outputs,
plugins: [
swc(
defineRollupSwcOption({
minify: true,
sourceMaps: true,
})
}),
),
],
};
Expand Down
14 changes: 7 additions & 7 deletions src/are-same.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { areSame } from "./";
import { areSame } from './';

describe("areSame valid cases", () => {
describe('areSame valid cases', () => {
test.each`
input | expected
${[1, 1, 1]} | ${true}
${["one", "one", "one"]} | ${true}
${['one', 'one', 'one']} | ${true}
${[1.5, 1.5, 1.5]} | ${true}
${[true, true, true]} | ${true}
`("should return $expected when input is: $input", ({ input, expected }) => {
`('should return $expected when input is: $input', ({ input, expected }) => {
expect(areSame(input)).toBe(expected);
});
});

describe("areEqual invalid cases", () => {
describe('areEqual invalid cases', () => {
test.each`
input | expected
${[1, 2, 3]} | ${false}
${["one", "two", "three"]} | ${false}
${['one', 'two', 'three']} | ${false}
${[1.5, 2.5, 3.5]} | ${false}
${[true, false, true]} | ${false}
`("should return $expected when input is: $input", ({ input, expected }) => {
`('should return $expected when input is: $input', ({ input, expected }) => {
expect(areSame(input)).toBe(expected);
});
});
2 changes: 1 addition & 1 deletion src/are-same.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @public
*/
export function areSame<T extends string | number | boolean>(
arr: Required<T[]>
arr: Required<T[]>,
): boolean {
return arr.every((item) => item === arr[0]);
}
10 changes: 5 additions & 5 deletions src/count-items.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { countItems } from "./";
import { countItems } from './';

describe("countItems cases", () => {
describe('countItems cases', () => {
test.each`
input | expected
${[1, 1, 1, 2]} | ${{ "1": 3, "2": 1 }}
${["in", "love", "love", "love"]} | ${{ in: 1, love: 3 }}
`("should return $expected when input is: $input", ({ input, expected }) => {
${[1, 1, 1, 2]} | ${{ '1': 3, '2': 1 }}
${['in', 'love', 'love', 'love']} | ${{ in: 1, love: 3 }}
`('should return $expected when input is: $input', ({ input, expected }) => {
expect(countItems(input)).toStrictEqual(expected);
});
});
2 changes: 1 addition & 1 deletion src/count-items.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Primitive } from "./types";
import { Primitive } from './types';
/**
* Counts of repeated items in flattened arrays.
* @param array - array of items.
Expand Down
6 changes: 3 additions & 3 deletions src/get-length.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getLength } from "./";
import { getLength } from './';

describe("getLength cases", () => {
describe('getLength cases', () => {
test.each`
input | expected
${[]} | ${0}
Expand All @@ -9,7 +9,7 @@ describe("getLength cases", () => {
${{ id: 1 }} | ${1}
${true} | ${0}
${1} | ${0}
`("should return $expected when input is: $input", ({ input, expected }) => {
`('should return $expected when input is: $input', ({ input, expected }) => {
expect(getLength(input)).toBe(expected);
});
});
6 changes: 3 additions & 3 deletions src/get-length.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isArray } from "./is-array";
import { isObject } from "./is-object";
import { isString } from "./is-string";
import { isArray } from './is-array';
import { isObject } from './is-object';
import { isString } from './is-string';

/**
* Gets length of string | array | object
Expand Down
10 changes: 5 additions & 5 deletions src/has-duplicates.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { hasDuplicates } from "./";
import { hasDuplicates } from './';

describe("hasDuplicates cases", () => {
describe('hasDuplicates cases', () => {
test.each`
array | expected
${[1, 1, 2]} | ${true}
${["one", "one", "two"]} | ${true}
${['one', 'one', 'two']} | ${true}
${[1, 2, 3]} | ${false}
${["one", "two", "three"]} | ${false}
`("should return $expected when array is: $array", ({ array, expected }) => {
${['one', 'two', 'three']} | ${false}
`('should return $expected when array is: $array', ({ array, expected }) => {
expect(hasDuplicates(array)).toBe(expected);
});
});
2 changes: 1 addition & 1 deletion src/has-duplicates.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Primitive } from "./types";
import { Primitive } from './types';

/**
* Determines whether an array has duplicates.
Expand Down
30 changes: 15 additions & 15 deletions src/index-by.test.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import { indexBy } from ".";
import { indexBy } from '.';

describe("indexBy cases", () => {
describe('indexBy cases', () => {
const withUniqueKey = [
{ id: 1, name: "A" },
{ id: 2, name: "B" },
{ id: 3, name: "C" },
{ id: 1, name: 'A' },
{ id: 2, name: 'B' },
{ id: 3, name: 'C' },
];

const withUniqueKeyExpected = {
"1": { id: 1, name: "A" },
"2": { id: 2, name: "B" },
"3": { id: 3, name: "C" },
'1': { id: 1, name: 'A' },
'2': { id: 2, name: 'B' },
'3': { id: 3, name: 'C' },
};

const withDuplicatedKey = [
{ id: 1, name: "A" },
{ id: 1, name: "B" },
{ id: 3, name: "C" },
{ id: 1, name: 'A' },
{ id: 1, name: 'B' },
{ id: 3, name: 'C' },
];

// On duplicate keys should be replaced the repeated key with the last one.
const withDuplicatedKeyExpected = {
"1": { id: 1, name: "B" },
"3": { id: 3, name: "C" },
'1': { id: 1, name: 'B' },
'3': { id: 3, name: 'C' },
};

test.each`
input | expected
${withUniqueKey} | ${withUniqueKeyExpected}
${withDuplicatedKey} | ${withDuplicatedKeyExpected}
`("should return $expected when input is: $input", ({ input, expected }) => {
expect(indexBy([...input], "id")).toStrictEqual(expected);
`('should return $expected when input is: $input', ({ input, expected }) => {
expect(indexBy([...input], 'id')).toStrictEqual(expected);
});
});
4 changes: 2 additions & 2 deletions src/index-by.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
*/
export function indexBy<
T extends { [K in keyof T]: string | number | symbol },
K extends keyof T
K extends keyof T,
>(array: T[], key: K): Record<T[K], T> {
return array.reduce(
(acc, item) => ({ ...acc, [item[key]]: item }),
{} as Record<T[K], T>
{} as Record<T[K], T>,
);
}
46 changes: 23 additions & 23 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
export { areSame } from "./are-same";
export { countItems } from "./count-items";
export { hasDuplicates } from "./has-duplicates";
export { isArray } from "./is-array";
export { isArrayOfString } from "./is-array-of-string";
export { isDate } from "./is-date";
export { isDateString as isDateValid } from "./is-date-string";
export { isDefined } from "./is-defined";
export { isEmpty } from "./is-empty";
export { isEqual } from "./is-equal";
export { isEqualDate } from "./is-equal-date";
export { isMap } from "./is-map";
export { isNumber } from "./is-number";
export { isObject } from "./is-object";
export { isObjectLike } from "./is-object-like";
export { isSet } from "./is-set";
export { isString } from "./is-string";
export { isNull } from "./is-null";
export { omitBy } from "./omit-by";
export { toChunks } from "./to-chunks";
export { indexBy } from "./index-by";
export { wrapInArray } from "./wrap-in-array";
export { getLength } from "./get-length";
export { areSame } from './are-same';
export { countItems } from './count-items';
export { hasDuplicates } from './has-duplicates';
export { isArray } from './is-array';
export { isArrayOfString } from './is-array-of-string';
export { isDate } from './is-date';
export { isDateString as isDateValid } from './is-date-string';
export { isDefined } from './is-defined';
export { isEmpty } from './is-empty';
export { isEqual } from './is-equal';
export { isEqualDate } from './is-equal-date';
export { isMap } from './is-map';
export { isNumber } from './is-number';
export { isObject } from './is-object';
export { isObjectLike } from './is-object-like';
export { isSet } from './is-set';
export { isString } from './is-string';
export { isNull } from './is-null';
export { omitBy } from './omit-by';
export { toChunks } from './to-chunks';
export { indexBy } from './index-by';
export { wrapInArray } from './wrap-in-array';
export { getLength } from './get-length';
24 changes: 12 additions & 12 deletions src/internal/get-tag.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { getTag } from "./index";
import { getTag } from './index';

describe("getTag cases", () => {
describe('getTag cases', () => {
test.each`
input | expected
${new Set()} | ${"[object Set]"}
${new Map()} | ${"[object Map]"}
${{}} | ${"[object Object]"}
${""} | ${"[object String]"}
${1} | ${"[object Number]"}
${null} | ${"[object Null]"}
${undefined} | ${"[object Undefined]"}
${new Date()} | ${"[object Date]"}
${Symbol()} | ${"[object Symbol]"}
`("should return $expected when input is: $input", ({ input, expected }) => {
${new Set()} | ${'[object Set]'}
${new Map()} | ${'[object Map]'}
${{}} | ${'[object Object]'}
${''} | ${'[object String]'}
${1} | ${'[object Number]'}
${null} | ${'[object Null]'}
${undefined} | ${'[object Undefined]'}
${new Date()} | ${'[object Date]'}
${Symbol()} | ${'[object Symbol]'}
`('should return $expected when input is: $input', ({ input, expected }) => {
expect(getTag(input)).toBe(expected);
});
});
2 changes: 1 addition & 1 deletion src/internal/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { getTag } from "./_get-tag";
export { getTag } from './_get-tag';
10 changes: 5 additions & 5 deletions src/is-array-of-string.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { isArrayOfString } from "./";
import { isArrayOfString } from './';

describe("isArrayOfString cases", () => {
describe('isArrayOfString cases', () => {
test.each`
input | expected
${["a", "b", "c"]} | ${true}
${["a", "b", 1]} | ${false}
`("should return $expected when input is: $input", ({ input, expected }) => {
${['a', 'b', 'c']} | ${true}
${['a', 'b', 1]} | ${false}
`('should return $expected when input is: $input', ({ input, expected }) => {
expect(isArrayOfString(input)).toBe(expected);
});
});
2 changes: 1 addition & 1 deletion src/is-array-of-string.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isString } from "./is-string";
import { isString } from './is-string';

/**
* Determines whether the input is array of string or not.
Expand Down
10 changes: 5 additions & 5 deletions src/is-array.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { isArray } from "./";
import { isArray } from './';

describe("isArray cases", () => {
describe('isArray cases', () => {
test.each`
input | expected
${[1, 1, 1]} | ${true}
${["one", "one"]} | ${true}
${['one', 'one']} | ${true}
${[{ id: 1 }, { id: 2 }]} | ${true}
${"string"} | ${false}
${'string'} | ${false}
${null} | ${false}
`("should return $expected when input is: $input", ({ input, expected }) => {
`('should return $expected when input is: $input', ({ input, expected }) => {
expect(isArray(input)).toBe(expected);
});
});
32 changes: 16 additions & 16 deletions src/is-date-string.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { isDateValid } from "./";
import { isDateValid } from './';

describe("isDateValid valid cases", () => {
describe('isDateValid valid cases', () => {
test.each`
input | expected
${"01/01/2000"} | ${true}
${"31/01/2000"} | ${true}
${"32/01/2000"} | ${false}
${"01/1/2000"} | ${true}
${"01/1/01"} | ${true}
${"29/02/2000"} | ${true}
${"28/02/2001"} | ${true}
${"29/02/2001"} | ${false}
${"29 Feb 2001"} | ${false}
${"29 Feb 2020"} | ${true}
${"26 OCT 2024"} | ${true}
${"01/Mar/2020"} | ${true}
${"1.1.1"} | ${false}
`("should return $expected when input is: $input", ({ input, expected }) => {
${'01/01/2000'} | ${true}
${'31/01/2000'} | ${true}
${'32/01/2000'} | ${false}
${'01/1/2000'} | ${true}
${'01/1/01'} | ${true}
${'29/02/2000'} | ${true}
${'28/02/2001'} | ${true}
${'29/02/2001'} | ${false}
${'29 Feb 2001'} | ${false}
${'29 Feb 2020'} | ${true}
${'26 OCT 2024'} | ${true}
${'01/Mar/2020'} | ${true}
${'1.1.1'} | ${false}
`('should return $expected when input is: $input', ({ input, expected }) => {
expect(isDateValid(input)).toBe(expected);
});
});
8 changes: 4 additions & 4 deletions src/is-date.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { isDate } from "./";
import { isDate } from './';

describe("isDate cases", () => {
describe('isDate cases', () => {
test.each`
input | expected
${new Date()} | ${true}
${"29 Feb 2020"} | ${false}
`("should return $expected when input is: $input", ({ input, expected }) => {
${'29 Feb 2020'} | ${false}
`('should return $expected when input is: $input', ({ input, expected }) => {
expect(isDate(input)).toBe(expected);
});
});
Loading

0 comments on commit bd517a0

Please sign in to comment.