diff --git a/.eslintrc.js b/.eslintrc.cjs similarity index 100% rename from .eslintrc.js rename to .eslintrc.cjs diff --git a/.npmignore b/.npmignore index f455f6b..b0d87cd 100644 --- a/.npmignore +++ b/.npmignore @@ -16,3 +16,5 @@ node_modules/ .releaserc yarn.lock package-lock.json +tsconfig.esm.json +tsconfig.json diff --git a/.release/release-notes.txt b/.release/release-notes.txt index 60e1815..962cb0b 100644 --- a/.release/release-notes.txt +++ b/.release/release-notes.txt @@ -1 +1,2 @@ ## This release for testing subpath modules and their declerations +- Folder structure changed \ No newline at end of file diff --git a/package.json b/package.json index 1295217..c99f868 100644 --- a/package.json +++ b/package.json @@ -7,47 +7,132 @@ "url": "https://github.com/laxmanpokhrel/xmanscript-utils.git" }, "type": "module", + "types": "./@types", "exports": { - "./abbreviateCurrencyValue": "./lib/abbreviateCurrencyValue", - "./areObjectsEqual": "./lib/areObjectsEqual", - "./calculateAndInjectPercentageByMaxValue": "./lib/calculateAndInjectPercentageByMaxValue", - "./calculateAndInjectPercentageBySum": "./lib/calculateAndInjectPercentageBySum", - "./calculateSumOfKey": "./lib/calculateSumOfKey", - "./containsBinaryData": "./lib/containsBinaryData", - "./convertNestedKeysToObject": "./lib/convertNestedKeysToObject", - "./countKeyOccurrences": "./lib/countKeyOccurrences", - "./distributePercentageEqually": "./lib/distributePercentageEqually", - "./distributePercentageEquallyWithRemainder": "./lib/distributePercentageEquallyWithRemainder", - "./formatNumberToCommaString": "./lib/formatNumberToCommaString", + "./abbreviateCurrencyValue": { + "types": "./lib/abbreviateCurrencyValue/index.d.ts", + "default": "./lib/abbreviateCurrencyValue/index.js" + }, + "./areObjectsEqual": { + "types": "./lib/areObjectsEqual/index.d.ts", + "default": "./lib/areObjectsEqual/index.js" + }, + "./calculateAndInjectPercentageByMaxValue": { + "types": "./lib/calculateAndInjectPercentageByMaxValue/index.d.ts", + "default": "./lib/calculateAndInjectPercentageByMaxValue/index.js" + }, + "./calculateAndInjectPercentageBySum": { + "types": "./lib/calculateAndInjectPercentageBySum/index.d.ts", + "default": "./lib/calculateAndInjectPercentageBySum/index.js" + }, + "./calculateSumOfKey": { + "types": "./lib/calculateSumOfKey/index.d.ts", + "default": "./lib/calculateSumOfKey/index.js" + }, + "./containsBinaryData": { + "types": "./lib/containsBinaryData/index.d.ts", + "default": "./lib/containsBinaryData/index.js" + }, + "./convertNestedKeysToObject": { + "types": "./lib/convertNestedKeysToObject/index.d.ts", + "default": "./lib/convertNestedKeysToObject/index.js" + }, + "./countKeyOccurrences": { + "types": "./lib/countKeyOccurrences/index.d.ts", + "default": "./lib/countKeyOccurrences/index.js" + }, + "./distributePercentageEqually": { + "types": "./lib/distributePercentageEqually/index.d.ts", + "default": "./lib/distributePercentageEqually/index.js" + }, + "./distributePercentageEquallyWithRemainder": { + "types": "./lib/distributePercentageEquallyWithRemainder/index.d.ts", + "default": "./lib/distributePercentageEquallyWithRemainder/index.js" + }, + "./formatNumberToCommaString": { + "types": "./lib/formatNumberToCommaString/index.d.ts", + "default": "./lib/formatNumberToCommaString/index.js" + }, "./getDifferenceObject": { "types": "./lib/getDifferenceObject/index.d.ts", "default": "./lib/getDifferenceObject/index.js" }, - "./getFileExtension": "./lib/getFileExtension", - "./getMinMax": "./lib/getMinMax", - "./groupArrayOfObjectsByValueOfAKey": "./lib/groupArrayOfObjectsByValueOfAKey", - "./intersectObjects": "./lib/intersectObjects", - "./isJSONObject": "./lib/isJSONObject", - "./markCheckedByStringMatch": "./lib/markCheckedByStringMatch", - "./objectToFormDataWithFiles": "./lib/objectToFormDataWithFiles", - "./omitKey": "./lib/omitKey", - "./parseToBoolean": "./lib/parseToBoolean", - "./partitionObjectsByKey": "./lib/partitionObjectsByKey", - "./removeObjectFromArray": "./lib/removeObjectFromArray", + "./getFileExtension": { + "types": "./lib/getFileExtension/index.d.ts", + "default": "./lib/getFileExtension/index.js" + }, + "./getMinMax": { + "types": "./lib/getMinMax/index.d.ts", + "default": "./lib/getMinMax/index.js" + }, + "./groupArrayOfObjectsByValueOfAKey": { + "types": "./lib/groupArrayOfObjectsByValueOfAKey/index.d.ts", + "default": "./lib/groupArrayOfObjectsByValueOfAKey/index.js" + }, + "./intersectObjects": { + "types": "./lib/intersectObjects/index.d.ts", + "default": "./lib/intersectObjects/index.js" + }, + "./isJSONObject": { + "types": "./lib/isJSONObject/index.d.ts", + "default": "./lib/isJSONObject/index.js" + }, + "./markCheckedByStringMatch": { + "types": "./lib/markCheckedByStringMatch/index.d.ts", + "default": "./lib/markCheckedByStringMatch/index.js" + }, + "./objectToFormDataWithFiles": { + "types": "./lib/objectToFormDataWithFiles/index.d.ts", + "default": "./lib/objectToFormDataWithFiles/index.js" + }, + "./omitKey": { + "types": "./lib/omitKey/index.d.ts", + "default": "./lib/omitKey/index.js" + }, + "./parseToBoolean": { + "types": "./lib/parseToBoolean/index.d.ts", + "default": "./lib/parseToBoolean/index.js" + }, + "./partitionObjectsByKey": { + "types": "./lib/partitionObjectsByKey/index.d.ts", + "default": "./lib/partitionObjectsByKey/index.js" + }, + "./removeObjectFromArray": { + "types": "./lib/removeObjectFromArray/index.d.ts", + "default": "./lib/removeObjectFromArray/index.js" + }, "./scrollToComponent": { - "types":"./lib/scrollToComponent/index.d.ts", + "types": "./lib/scrollToComponent/index.d.ts", "default": "./lib/scrollToComponent/index.js" }, - "./setKeysToValueInObjects": "./lib/setKeysToValueInObjects", - "./setValueOfKeyForMatchingValuesOfAKey": "./lib/setValueOfKeyForMatchingValuesOfAKey", - "./splitArrayIntoChunks": "./lib/splitArrayIntoChunks", + "./setKeysToValueInObjects": { + "types": "./lib/setKeysToValueInObjects/index.d.ts", + "default": "./lib/setKeysToValueInObjects/index.js" + }, + "./setValueOfKeyForMatchingValuesOfAKey": { + "types": "./lib/setValueOfKeyForMatchingValuesOfAKey/index.d.ts", + "default": "./lib/setValueOfKeyForMatchingValuesOfAKey/index.js" + }, + "./splitArrayIntoChunks": { + "types": "./lib/splitArrayIntoChunks/index.d.ts", + "default": "./lib/splitArrayIntoChunks/index.js" + }, "./strictIntersectObjects": { "types": "./lib/strictIntersectObjects/index.d.ts", "default": "./lib/strictIntersectObjects/index.js" }, - "./toggleObjectInArray": "./lib/toggleObjectInArray", - "./uniqueValuesOfKey": "./lib/uniqueValuesOfKey", - "./validateObjectsForKey": "./lib/validateObjectsForKey" + "./toggleObjectInArray": { + "types": "./lib/toggleObjectInArray/index.d.ts", + "default": "./lib/toggleObjectInArray/index.js" + }, + "./uniqueValuesOfKey": { + "types": "./lib/uniqueValuesOfKey/index.d.ts", + "default": "./lib/uniqueValuesOfKey/index.js" + }, + "./validateObjectsForKey": { + "types": "./lib/validateObjectsForKey/index.d.ts", + "default": "./lib/validateObjectsForKey/index.js" + } }, "keywords": [ "utils", @@ -62,7 +147,7 @@ "homepage": "https://github.com/laxmanpokhrel/xmanscript-utils#readme", "main": "./lib/index.js", "scripts": { - "build": "rm -rf lib && tsc", + "build": "rm -rf lib && tsc && tsc -p tsconfig.esm.json", "prepare": "husky install", "lint": "eslint .", "lint:fix": "eslint --fix .", diff --git a/src/abbreviateCurrencyValue.ts b/src/abbreviateCurrencyValue/index.ts similarity index 100% rename from src/abbreviateCurrencyValue.ts rename to src/abbreviateCurrencyValue/index.ts diff --git a/src/areObjectsEqual.ts b/src/areObjectsEqual/index.ts similarity index 100% rename from src/areObjectsEqual.ts rename to src/areObjectsEqual/index.ts diff --git a/src/calculateAndInjectPercentageByMaxValue.ts b/src/calculateAndInjectPercentageByMaxValue/index.ts similarity index 94% rename from src/calculateAndInjectPercentageByMaxValue.ts rename to src/calculateAndInjectPercentageByMaxValue/index.ts index 901ffb1..0f7e109 100644 --- a/src/calculateAndInjectPercentageByMaxValue.ts +++ b/src/calculateAndInjectPercentageByMaxValue/index.ts @@ -1,5 +1,6 @@ /* eslint-disable no-restricted-syntax */ -import validateObjectsForKey from './validateObjectsForKey'; + +import validateObjectsForKey from '../validateObjectsForKey'; /** * The function calculates and injects the percentage value based on the maximum value of a specified diff --git a/src/calculateAndInjectPercentageBySum.ts b/src/calculateAndInjectPercentageBySum/index.ts similarity index 94% rename from src/calculateAndInjectPercentageBySum.ts rename to src/calculateAndInjectPercentageBySum/index.ts index a013561..a55ea74 100644 --- a/src/calculateAndInjectPercentageBySum.ts +++ b/src/calculateAndInjectPercentageBySum/index.ts @@ -1,5 +1,6 @@ /* eslint-disable no-restricted-syntax */ -import validateObjectsForKey from './validateObjectsForKey'; + +import validateObjectsForKey from '../validateObjectsForKey'; /** * The function calculates the percentage of a specific key's value based on sum of values in that key in each object of an array and diff --git a/src/calculateSumOfKey.ts b/src/calculateSumOfKey/index.ts similarity index 100% rename from src/calculateSumOfKey.ts rename to src/calculateSumOfKey/index.ts diff --git a/src/containsBinaryData.ts b/src/containsBinaryData/index.ts similarity index 100% rename from src/containsBinaryData.ts rename to src/containsBinaryData/index.ts diff --git a/src/convertNestedKeysToObject.ts b/src/convertNestedKeysToObject/index.ts similarity index 100% rename from src/convertNestedKeysToObject.ts rename to src/convertNestedKeysToObject/index.ts diff --git a/src/countKeyOccurrences.ts b/src/countKeyOccurrences/index.ts similarity index 100% rename from src/countKeyOccurrences.ts rename to src/countKeyOccurrences/index.ts diff --git a/src/distributePercentageEqually.ts b/src/distributePercentageEqually/index.ts similarity index 97% rename from src/distributePercentageEqually.ts rename to src/distributePercentageEqually/index.ts index e3b64f9..c007927 100644 --- a/src/distributePercentageEqually.ts +++ b/src/distributePercentageEqually/index.ts @@ -1,5 +1,6 @@ /* eslint-disable no-param-reassign */ -import countKeyOccurrences from './countKeyOccurrences'; + +import countKeyOccurrences from '../countKeyOccurrences'; /** * The `distributePercentageEqually` function takes a JSON object and a key, and updates the values of that key in diff --git a/src/distributePercentageEquallyWithRemainder.ts b/src/distributePercentageEquallyWithRemainder/index.ts similarity index 100% rename from src/distributePercentageEquallyWithRemainder.ts rename to src/distributePercentageEquallyWithRemainder/index.ts diff --git a/src/formatNumberToCommaString.ts b/src/formatNumberToCommaString/index.ts similarity index 100% rename from src/formatNumberToCommaString.ts rename to src/formatNumberToCommaString/index.ts diff --git a/src/getDifferenceObject/package.json b/src/getDifferenceObject/package.json deleted file mode 100644 index 2fdef03..0000000 --- a/src/getDifferenceObject/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "@xmanscript/utils/getDifferenceObject", - "type": "module", - "main": "../../lib/getDifferenceObject/index.js", - "module": "../../lib/getDifferenceObject/index.js", - "types": "../../lib/getDifferenceObject/index.d.ts", - "sideEffects": false - } \ No newline at end of file diff --git a/src/getFileExtension.ts b/src/getFileExtension/index.ts similarity index 100% rename from src/getFileExtension.ts rename to src/getFileExtension/index.ts diff --git a/src/getMinMax.ts b/src/getMinMax/index.ts similarity index 100% rename from src/getMinMax.ts rename to src/getMinMax/index.ts diff --git a/src/groupArrayOfObjectsByValueOfAKey.ts b/src/groupArrayOfObjectsByValueOfAKey/index.ts similarity index 100% rename from src/groupArrayOfObjectsByValueOfAKey.ts rename to src/groupArrayOfObjectsByValueOfAKey/index.ts diff --git a/src/intersectObjects/package.json b/src/intersectObjects/package.json deleted file mode 100644 index b5d4467..0000000 --- a/src/intersectObjects/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "@xmanscript/utils/intersectObjects", - "type": "module", - "main": "../../lib/intersectObjects/index.js", - "module": "../../lib/intersectObjects/index.js", - "types": "../../lib/intersectObjects/index.d.ts", - "sideEffects": false - } \ No newline at end of file diff --git a/src/isJSONObject.ts b/src/isJSONObject/index.ts similarity index 100% rename from src/isJSONObject.ts rename to src/isJSONObject/index.ts diff --git a/src/markCheckedByStringMatch.ts b/src/markCheckedByStringMatch/index.ts similarity index 100% rename from src/markCheckedByStringMatch.ts rename to src/markCheckedByStringMatch/index.ts diff --git a/src/objectToFormDataWithFiles.ts b/src/objectToFormDataWithFiles/index.ts similarity index 95% rename from src/objectToFormDataWithFiles.ts rename to src/objectToFormDataWithFiles/index.ts index 4727c4a..8dcc5e4 100644 --- a/src/objectToFormDataWithFiles.ts +++ b/src/objectToFormDataWithFiles/index.ts @@ -1,4 +1,4 @@ -import isJSONObject from './isJSONObject'; +import isJSONObject from '../isJSONObject'; /** * The function `objectToFormDataWithFiles` converts a JSON object into a FormData object, handling file uploads diff --git a/src/omitKey.ts b/src/omitKey/index.ts similarity index 100% rename from src/omitKey.ts rename to src/omitKey/index.ts diff --git a/src/parseToBoolean.ts b/src/parseToBoolean/index.ts similarity index 100% rename from src/parseToBoolean.ts rename to src/parseToBoolean/index.ts diff --git a/src/partitionObjectsByKey.ts b/src/partitionObjectsByKey/index.ts similarity index 100% rename from src/partitionObjectsByKey.ts rename to src/partitionObjectsByKey/index.ts diff --git a/src/removeObjectFromArray.ts b/src/removeObjectFromArray/index.ts similarity index 100% rename from src/removeObjectFromArray.ts rename to src/removeObjectFromArray/index.ts diff --git a/src/scrollToComponent.ts b/src/scrollToComponent.ts deleted file mode 100644 index 5d4390a..0000000 --- a/src/scrollToComponent.ts +++ /dev/null @@ -1,56 +0,0 @@ -type ScrollLogicalPosition = 'center' | 'end' | 'nearest' | 'start'; - -type scrollToComponentProps = { - componentId: string; - focusAfterScroll?: boolean; - scrollDelay?: number; - focusDelay?: number; - align?: ScrollLogicalPosition; -}; - -/** - * The scrollToComponent function scrolls to a specified component on the page and optionally focuses - * on it after scrolling. - * @param {scrollToComponentProps} - - `componentId`: The id of the component to scroll to. - * 'align': The alignment of the component after scrolling. It can be one of the following values: - * 'start', 'center', or 'end'. The default value is 'center'. - * 'delay': The delay in milliseconds before scrolling to the component. - */ - -export default function scrollToComponent({ - componentId, - focusAfterScroll = false, - scrollDelay, - focusDelay, - align = 'center', -}: scrollToComponentProps) { - // eslint-disable-next-line no-undef - const element = document.getElementById(componentId); - - if (element) { - // scroll after delay - if (scrollDelay) { - setTimeout(() => { - element.scrollIntoView({ - behavior: 'smooth', - block: align, - }); - }, scrollDelay); - } - // scroll without delay - element.scrollIntoView({ - behavior: 'smooth', - block: 'center', - }); - // focus to element - if (focusAfterScroll) { - // focus after delay - if (focusDelay) - setTimeout(() => { - element.focus(); - }, focusDelay || 300); - // focus without delay - else element.focus(); - } - } -} diff --git a/src/scrollToComponent/package.json b/src/scrollToComponent/package.json deleted file mode 100644 index 90dd1f3..0000000 --- a/src/scrollToComponent/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "@xmanscript/utils/scrollToComponent", - "type": "module", - "main": "../../lib/scrollToComponent/index.js", - "module": "../../lib/scrollToComponent/index.js", - "types": "../../lib/scrollToComponent/index.d.ts", - "sideEffects": false - } \ No newline at end of file diff --git a/src/setKeysToValueInObjects.ts b/src/setKeysToValueInObjects/index.ts similarity index 100% rename from src/setKeysToValueInObjects.ts rename to src/setKeysToValueInObjects/index.ts diff --git a/src/setValueOfKeyForMatchingValuesOfAKey.ts b/src/setValueOfKeyForMatchingValuesOfAKey/index.ts similarity index 100% rename from src/setValueOfKeyForMatchingValuesOfAKey.ts rename to src/setValueOfKeyForMatchingValuesOfAKey/index.ts diff --git a/src/splitArrayIntoChunks.ts b/src/splitArrayIntoChunks/index.ts similarity index 100% rename from src/splitArrayIntoChunks.ts rename to src/splitArrayIntoChunks/index.ts diff --git a/src/strictIntersectObjects.ts b/src/strictIntersectObjects/index.ts similarity index 100% rename from src/strictIntersectObjects.ts rename to src/strictIntersectObjects/index.ts diff --git a/src/toggleObjectInArray.ts b/src/toggleObjectInArray/index.ts similarity index 93% rename from src/toggleObjectInArray.ts rename to src/toggleObjectInArray/index.ts index 39f028f..54f3b2a 100644 --- a/src/toggleObjectInArray.ts +++ b/src/toggleObjectInArray/index.ts @@ -1,4 +1,4 @@ -import areObjectsEqual from './areObjectsEqual'; +import areObjectsEqual from '../areObjectsEqual'; /** * The function removes the target object from the array if it exists, otherwise it adds it to the diff --git a/src/toggleStringInArray.ts b/src/toggleStringInArray/index.ts similarity index 100% rename from src/toggleStringInArray.ts rename to src/toggleStringInArray/index.ts diff --git a/src/uniqueValuesOfKey.ts b/src/uniqueValuesOfKey/index.ts similarity index 100% rename from src/uniqueValuesOfKey.ts rename to src/uniqueValuesOfKey/index.ts diff --git a/src/validateObjectsForKey.ts b/src/validateObjectsForKey/index.ts similarity index 100% rename from src/validateObjectsForKey.ts rename to src/validateObjectsForKey/index.ts diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 0000000..b3c7bb2 --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,7 @@ +{ +"extends": "./tsconfig.json", +"compilerOptions": { + "module": "esnext", + "outDir": "./lib/esm" + } +} diff --git a/tsconfig.json b/tsconfig.json index b3b5499..c3ef8b7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,10 +1,13 @@ + + + { "compilerOptions": { "target": "ES6", - "module": "ES2015", + // "module": "ES2015", "declaration": true, "sourceMap": true, - "outDir": "./lib", + // "outDir": "./lib", // "baseUrl": "src/", "strict": true, "lib": ["ES2020", "DOM"], @@ -19,9 +22,10 @@ "noFallthroughCasesInSwitch": true, "esModuleInterop": true, "allowSyntheticDefaultImports": false, - // "declarationDir": "./@types" - + "module": "commonjs", + "outDir": "./lib/commonjs", + "moduleResolution": "node", }, - "exclude": ["node_modules"], - "include": [".eslintrc.js", "src", "src/**/*.ts"] -} + "exclude": ["node_modules",], + "include": [".eslintrc.cjs", "src", "src/**/*.ts"] +} \ No newline at end of file