chore: format number

This commit is contained in:
Ibrahima G. Coulibaly
2024-07-11 21:35:00 +01:00
parent 5cc4f4032f
commit 350061d79e
3 changed files with 73 additions and 62 deletions

121
.idea/workspace.xml generated
View File

@@ -4,12 +4,10 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="feat: reverse list ui"> <list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="feat: self host">
<change afterPath="$PROJECT_DIR$/.dockerignore" afterDir="false" /> <change afterPath="$PROJECT_DIR$/src/utils/number.ts" afterDir="false" />
<change afterPath="$PROJECT_DIR$/Dockerfile" afterDir="false" />
<change afterPath="$PROJECT_DIR$/img.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/pages/list/group/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/group/index.tsx" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -31,9 +29,9 @@
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
<option name="RESET_MODE" value="HARD" /> <option name="RESET_MODE" value="HARD" />
</component> </component>
<component name="KubernetesApiProvider"><![CDATA[{ <component name="KubernetesApiProvider">{
"isMigrated": true &quot;isMigrated&quot;: true
}]]></component> }</component>
<component name="MarkdownSettingsMigration"> <component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" /> <option name="stateVersion" value="1" />
</component> </component>
@@ -49,46 +47,46 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"ASKED_ADD_EXTERNAL_FILES": "true", &quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;,
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true", &quot;ASKED_SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
"Docker.Dockerfile build.executor": "Run", &quot;Docker.Dockerfile build.executor&quot;: &quot;Run&quot;,
"Docker.Dockerfile.executor": "Run", &quot;Docker.Dockerfile.executor&quot;: &quot;Run&quot;,
"Playwright.JoinText Component.executor": "Run", &quot;Playwright.JoinText Component.executor&quot;: &quot;Run&quot;,
"Playwright.JoinText Component.should merge text pieces with specified join character.executor": "Run", &quot;Playwright.JoinText Component.should merge text pieces with specified join character.executor&quot;: &quot;Run&quot;,
"RunOnceActivity.OpenProjectViewOnStart": "true", &quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"Vitest.compute function (1).executor": "Run", &quot;Vitest.compute function (1).executor&quot;: &quot;Run&quot;,
"Vitest.compute function.executor": "Run", &quot;Vitest.compute function.executor&quot;: &quot;Run&quot;,
"Vitest.mergeText.executor": "Run", &quot;Vitest.mergeText.executor&quot;: &quot;Run&quot;,
"Vitest.mergeText.should merge lines and preserve blank lines when deleteBlankLines is false.executor": "Run", &quot;Vitest.mergeText.should merge lines and preserve blank lines when deleteBlankLines is false.executor&quot;: &quot;Run&quot;,
"Vitest.mergeText.should merge lines, preserve blank lines and trailing spaces when both deleteBlankLines and deleteTrailingSpaces are false.executor": "Run", &quot;Vitest.mergeText.should merge lines, preserve blank lines and trailing spaces when both deleteBlankLines and deleteTrailingSpaces are false.executor&quot;: &quot;Run&quot;,
"git-widget-placeholder": "main", &quot;git-widget-placeholder&quot;: &quot;main&quot;,
"ignore.virus.scanning.warn.message": "true", &quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
"kotlin-language-version-configured": "true", &quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
"last_opened_file_path": "C:/Users/HP/IdeaProjects/omni-tools/src/components/options", &quot;last_opened_file_path&quot;: &quot;C:/Users/HP/IdeaProjects/omni-tools/src/components/options&quot;,
"node.js.detected.package.eslint": "true", &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
"node.js.detected.package.tslint": "true", &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
"node.js.selected.package.eslint": "(autodetect)", &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
"node.js.selected.package.tslint": "(autodetect)", &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
"nodejs_package_manager_path": "npm", &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
"npm.dev.executor": "Run", &quot;npm.dev.executor&quot;: &quot;Run&quot;,
"npm.lint.executor": "Run", &quot;npm.lint.executor&quot;: &quot;Run&quot;,
"npm.prebuild.executor": "Run", &quot;npm.prebuild.executor&quot;: &quot;Run&quot;,
"npm.script:create:tool.executor": "Run", &quot;npm.script:create:tool.executor&quot;: &quot;Run&quot;,
"npm.test.executor": "Run", &quot;npm.test.executor&quot;: &quot;Run&quot;,
"npm.test:e2e.executor": "Run", &quot;npm.test:e2e.executor&quot;: &quot;Run&quot;,
"npm.test:e2e:run.executor": "Run", &quot;npm.test:e2e:run.executor&quot;: &quot;Run&quot;,
"prettierjs.PrettierConfiguration.Package": "C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\prettier", &quot;prettierjs.PrettierConfiguration.Package&quot;: &quot;C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\prettier&quot;,
"project.structure.last.edited": "Problems", &quot;project.structure.last.edited&quot;: &quot;Problems&quot;,
"project.structure.proportion": "0.0", &quot;project.structure.proportion&quot;: &quot;0.0&quot;,
"project.structure.side.proportion": "0.2", &quot;project.structure.side.proportion&quot;: &quot;0.2&quot;,
"settings.editor.selected.configurable": "settings.typescriptcompiler", &quot;settings.editor.selected.configurable&quot;: &quot;settings.typescriptcompiler&quot;,
"ts.external.directory.path": "C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\typescript\\lib", &quot;ts.external.directory.path&quot;: &quot;C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\typescript\\lib&quot;,
"vue.rearranger.settings.migration": "true" &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
} }
}]]></component> }</component>
<component name="ReactDesignerToolWindowState"> <component name="ReactDesignerToolWindowState">
<option name="myId2Visible"> <option name="myId2Visible">
<map> <map>
@@ -113,7 +111,7 @@
<recent name="C:\Users\HP\IdeaProjects\omni-tools\src\tools" /> <recent name="C:\Users\HP\IdeaProjects\omni-tools\src\tools" />
</key> </key>
</component> </component>
<component name="RunManager" selected="Docker.Dockerfile"> <component name="RunManager" selected="npm.dev">
<configuration name="Dockerfile build" type="docker-deploy" factoryName="dockerfile" temporary="true" server-name="Docker"> <configuration name="Dockerfile build" type="docker-deploy" factoryName="dockerfile" temporary="true" server-name="Docker">
<deployment type="dockerfile"> <deployment type="dockerfile">
<settings> <settings>
@@ -180,9 +178,9 @@
</list> </list>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="npm.dev" />
<item itemvalue="Docker.Dockerfile build" /> <item itemvalue="Docker.Dockerfile build" />
<item itemvalue="Docker.Dockerfile" /> <item itemvalue="Docker.Dockerfile" />
<item itemvalue="npm.dev" />
<item itemvalue="npm.lint" /> <item itemvalue="npm.lint" />
<item itemvalue="npm.test:e2e" /> <item itemvalue="npm.test:e2e" />
</list> </list>
@@ -225,15 +223,8 @@
<workItem from="1720564427492" duration="1523000" /> <workItem from="1720564427492" duration="1523000" />
<workItem from="1720613598176" duration="8000" /> <workItem from="1720613598176" duration="8000" />
<workItem from="1720655252208" duration="3975000" /> <workItem from="1720655252208" duration="3975000" />
<workItem from="1720661825389" duration="3107000" /> <workItem from="1720661825389" duration="4305000" />
</task> <workItem from="1720729165596" duration="730000" />
<task id="LOCAL-00046" summary="feat: change colors in png init">
<option name="closed" value="true" />
<created>1719193884293</created>
<option name="number" value="00046" />
<option name="presentableId" value="LOCAL-00046" />
<option name="project" value="LOCAL" />
<updated>1719193884293</updated>
</task> </task>
<task id="LOCAL-00047" summary="feat: change colors in png"> <task id="LOCAL-00047" summary="feat: change colors in png">
<option name="closed" value="true" /> <option name="closed" value="true" />
@@ -619,7 +610,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1720658257129</updated> <updated>1720658257129</updated>
</task> </task>
<option name="localTasksCounter" value="95" /> <task id="LOCAL-00095" summary="feat: self host">
<option name="closed" value="true" />
<created>1720665220407</created>
<option name="number" value="00095" />
<option name="presentableId" value="LOCAL-00095" />
<option name="project" value="LOCAL" />
<updated>1720665220408</updated>
</task>
<option name="localTasksCounter" value="96" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@@ -663,7 +662,6 @@
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" /> <option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
<option name="CHECK_NEW_TODO" value="false" /> <option name="CHECK_NEW_TODO" value="false" />
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" /> <option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
<MESSAGE value="feat: make tool responsive" />
<MESSAGE value="chore: make tool examples responsive" /> <MESSAGE value="chore: make tool examples responsive" />
<MESSAGE value="chore: loading screen" /> <MESSAGE value="chore: loading screen" />
<MESSAGE value="chore: shuffle tools search" /> <MESSAGE value="chore: shuffle tools search" />
@@ -688,7 +686,8 @@
<MESSAGE value="feat: find unique ui" /> <MESSAGE value="feat: find unique ui" />
<MESSAGE value="feat: group list ui" /> <MESSAGE value="feat: group list ui" />
<MESSAGE value="feat: reverse list ui" /> <MESSAGE value="feat: reverse list ui" />
<option name="LAST_COMMIT_MESSAGE" value="feat: reverse list ui" /> <MESSAGE value="feat: self host" />
<option name="LAST_COMMIT_MESSAGE" value="feat: self host" />
</component> </component>
<component name="XSLT-Support.FileAssociations.UIState"> <component name="XSLT-Support.FileAssociations.UIState">
<expand /> <expand />

View File

@@ -9,6 +9,7 @@ import ToolInputAndResult from '../../../components/ToolInputAndResult';
import SimpleRadio from '../../../components/options/SimpleRadio'; import SimpleRadio from '../../../components/options/SimpleRadio';
import TextFieldWithDesc from '../../../components/options/TextFieldWithDesc'; import TextFieldWithDesc from '../../../components/options/TextFieldWithDesc';
import CheckboxWithDesc from '../../../components/options/CheckboxWithDesc'; import CheckboxWithDesc from '../../../components/options/CheckboxWithDesc';
import { formatNumber } from '../../../utils/number';
const initialValues = { const initialValues = {
splitOperatorType: 'symbol' as SplitOperatorType, splitOperatorType: 'symbol' as SplitOperatorType,
@@ -121,7 +122,7 @@ export default function FindUnique() {
description={'Number of items in a group'} description={'Number of items in a group'}
type={'number'} type={'number'}
onOwnChange={(value) => onOwnChange={(value) =>
updateField('groupNumber', Number(value)) updateField('groupNumber', formatNumber(value, 1))
} }
/> />
<TextFieldWithDesc <TextFieldWithDesc

11
src/utils/number.ts Normal file
View File

@@ -0,0 +1,11 @@
export function formatNumber(
num: number | string,
fallback: number = 0
): number {
if (!num) return fallback;
const result: number = Number(num);
if (!result) {
return fallback;
}
return result >= 0 ? result : fallback;
}