diff --git a/packages/input-number/package.json b/packages/input-number/package.json index 22a9863c..78a75286 100644 --- a/packages/input-number/package.json +++ b/packages/input-number/package.json @@ -41,7 +41,8 @@ "@svelement-ui/input": "workspace:^", "@svelement-ui/theme-chalk": "workspace:^", "@svelement-ui/util-array-2-class-string": "workspace:^", - "@svelement-ui/util-array-2-style-string": "workspace:^" + "@svelement-ui/util-array-2-style-string": "workspace:^", + "@svelement-ui/utils": "workspace:^" }, "repository": { "type": "git", diff --git a/packages/input-number/src/lib/input-number.svelte b/packages/input-number/src/lib/input-number.svelte index f8dab73f..61cb74c9 100644 --- a/packages/input-number/src/lib/input-number.svelte +++ b/packages/input-number/src/lib/input-number.svelte @@ -2,6 +2,7 @@ import a2s from '@svelement-ui/util-array-2-class-string'; import a2st from '@svelement-ui/util-array-2-style-string'; import { createEventDispatcher, onMount, tick } from 'svelte'; + import { isNull, isNumber, isUndefined } from '@svelement-ui/utils'; import { SvelIcon, ArrowDown, Minus, ArrowUp, Plus } from '@svelement-ui/icon'; import SvelInput from '@svelement-ui/input'; @@ -30,12 +31,14 @@ return dataUserInput; } let currentValue = dataCurrentValue; - if (currentValue === undefined || currentValue === null) { + if (isNull(currentValue)) { return ''; } - // todo: - if (Object.prototype.toString.call(currentValue).toLowerCase() === '') { - currentValue = currentValue.toFixed(precision); + if (isNumber(currentValue)) { + if (Number.isNaN(currentValue)) return ''; + if (!isUndefined(precision)) { + currentValue = currentValue.toFixed(precision); + } } return currentValue; } diff --git a/packages/utils/.gitignore b/packages/utils/.gitignore new file mode 100644 index 00000000..a547bf36 --- /dev/null +++ b/packages/utils/.gitignore @@ -0,0 +1,24 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/packages/utils/CHANGELOG.md b/packages/utils/CHANGELOG.md new file mode 100644 index 00000000..b0f3e7dc --- /dev/null +++ b/packages/utils/CHANGELOG.md @@ -0,0 +1,132 @@ +# Change Log + +All notable changes to this project will be documented in this file. +See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +# [0.18.0](https://github.com/koory1st/svelement-ui/compare/v0.17.10...v0.18.0) (2023-11-20) + +**Note:** Version bump only for package @svelement-ui/util-errors + +## [0.17.10](https://github.com/koory1st/svelement-ui/compare/v0.17.9...v0.17.10) (2023-11-15) + +### Bug Fixes + +* **input:** textarea style ([c9e4ebc](https://github.com/koory1st/svelement-ui/commit/c9e4ebc35fd4e589010091d3e409609bb9a4d5d7)) + +# [0.17.0](https://github.com/koory1st/svelement-ui/compare/v0.16.1...v0.17.0) (2023-11-05) + +**Note:** Version bump only for package @svelement-ui/util-errors + +# [0.16.0](https://github.com/koory1st/svelement-ui/compare/v0.15.8...v0.16.0) (2023-10-28) + +**Note:** Version bump only for package @svelement-ui/util-errors + +# [0.15.0](https://github.com/koory1st/svelement-ui/compare/v0.14.4...v0.15.0) (2023-10-13) + +**Note:** Version bump only for package @svelement-ui/util-errors + +# [0.14.0](https://github.com/koory1st/svelement-ui/compare/v0.13.12...v0.14.0) (2023-10-06) + +**Note:** Version bump only for package @svelement-ui/util-errors + +## [0.13.12](https://github.com/koory1st/svelement-ui/compare/v0.13.11...v0.13.12) (2023-10-06) + +**Note:** Version bump only for package @svelement-ui/util-errors + +# [0.13.0](https://github.com/koory1st/svelement-ui/compare/v0.12.8...v0.13.0) (2023-09-28) + +**Note:** Version bump only for package @svelement-ui/util-errors + +# [0.12.0](https://github.com/koory1st/svelement-ui/compare/v0.11.7...v0.12.0) (2023-09-18) + +**Note:** Version bump only for package @svelement-ui/util-errors + +# [0.11.0](https://github.com/koory1st/svelement-ui/compare/v0.10.8...v0.11.0) (2023-09-11) + +**Note:** Version bump only for package @svelement-ui/util-errors + +# [0.10.0](https://github.com/koory1st/svelement-ui/compare/v0.9.15...v0.10.0) (2023-09-05) + +**Note:** Version bump only for package @svelement-ui/util-errors + +## [0.9.15](https://github.com/koory1st/svelement-ui/compare/v0.9.14...v0.9.15) (2023-09-04) + +**Note:** Version bump only for package @svelement-ui/util-errors + +## [0.9.13](https://github.com/koory1st/svelement-ui/compare/v0.9.12...v0.9.13) (2023-08-30) + +**Note:** Version bump only for package @svelement-ui/util-errors + +## [0.9.11](https://github.com/koory1st/svelement-ui/compare/v0.9.10...v0.9.11) (2023-08-27) + +**Note:** Version bump only for package @svelement-ui/util-errors + +## [0.9.10](https://github.com/koory1st/svelement-ui/compare/v0.9.9...v0.9.10) (2023-08-27) + +**Note:** Version bump only for package @svelement-ui/util-errors + +## [0.9.9](https://github.com/koory1st/svelement-ui/compare/v0.9.8...v0.9.9) (2023-08-26) + +**Note:** Version bump only for package @svelement-ui/util-errors + +## [0.9.8](https://github.com/koory1st/svelement-ui/compare/v0.9.7...v0.9.8) (2023-08-26) + +### Bug Fixes + +* **ts:** add check ([fa5491b](https://github.com/koory1st/svelement-ui/commit/fa5491bd2e536d48143c922e3d00876b30fdeb58)) + +## [0.9.5](https://github.com/koory1st/svelement-ui/compare/v0.9.4...v0.9.5) (2023-08-25) + +### Bug Fixes + +* **package:** add pulish config ([f341c6a](https://github.com/koory1st/svelement-ui/commit/f341c6acb368908716a745d6d2e0d534202a54c9)) + +## [0.9.4](https://github.com/koory1st/svelement-ui/compare/v0.9.3...v0.9.4) (2023-08-25) + +**Note:** Version bump only for package @svelement-ui/util-errors + +## [0.9.3](https://github.com/koory1st/svelement-ui/compare/v0.9.2...v0.9.3) (2023-08-25) + +**Note:** Version bump only for package @svelement-ui/util-errors + +# [0.9.0](https://github.com/koory1st/svelement-ui/compare/v0.8.5...v0.9.0) (2023-08-20) + +**Note:** Version bump only for package @svelement-ui/util-errors + +## [0.8.3](https://github.com/koory1st/svelement-ui/compare/v0.8.2...v0.8.3) (2023-08-18) + +**Note:** Version bump only for package @svelement-ui/util-errors + +# [0.8.0](https://github.com/koory1st/svelement-ui/compare/v0.7.2...v0.8.0) (2023-08-16) + +**Note:** Version bump only for package @svelement-ui/util-errors + +## [0.7.2](https://github.com/koory1st/svelement-ui/compare/v0.7.1...v0.7.2) (2023-08-15) + +**Note:** Version bump only for package @svelement-ui/util-errors + +# [0.7.0](https://github.com/koory1st/svelement-ui/compare/v0.6.1...v0.7.0) (2023-08-13) + +**Note:** Version bump only for package @svelement-ui/util-errors + +# [0.6.0](https://github.com/koory1st/svelement-ui/compare/v0.5.0...v0.6.0) (2023-08-13) + +**Note:** Version bump only for package @svelement-ui/util-errors + +# [0.5.0](https://github.com/koory1st/svelement-ui/compare/v0.4.3...v0.5.0) (2023-08-12) + +**Note:** Version bump only for package @svelement-ui/util-errors + +## [0.4.3](https://github.com/koory1st/svelement-ui/compare/v0.4.1...v0.4.3) (2023-08-11) + +**Note:** Version bump only for package @svelement-ui/util-errors + +# [0.4.0](https://github.com/koory1st/svelement-ui/compare/v0.3.0...v0.4.0) (2023-08-09) + +**Note:** Version bump only for package @svelement-ui/util-errors + +# [0.3.0](https://github.com/koory1st/svelement-ui/compare/v0.2.1...v0.3.0) (2023-08-08) + +### Features + +* **util-errors:** add ([b03bfe5](https://github.com/koory1st/svelement-ui/commit/b03bfe5519e013bf4097b025896feed1a29a19d7)) diff --git a/packages/utils/package.json b/packages/utils/package.json new file mode 100644 index 00000000..5c2dd8b7 --- /dev/null +++ b/packages/utils/package.json @@ -0,0 +1,22 @@ +{ + "name": "@svelement-ui/utils", + "version": "0.18.0", + "type": "module", + "files": [ + "dist" + ], + "exports": { + ".": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + } + }, + "scripts": { + "build": "vite build", + "clean": "rimraf dist" + }, + "publishConfig": { + "access": "public", + "registry": "https://registry.npmjs.org" + } +} diff --git a/packages/utils/src/index.js b/packages/utils/src/index.js new file mode 100644 index 00000000..855995c6 --- /dev/null +++ b/packages/utils/src/index.js @@ -0,0 +1,2 @@ +export { isNull } from './is_null.js'; +export { isNumber } from './is_number.js'; diff --git a/packages/utils/src/is_null.js b/packages/utils/src/is_null.js new file mode 100644 index 00000000..9abe5248 --- /dev/null +++ b/packages/utils/src/is_null.js @@ -0,0 +1,11 @@ +export function isNull(input) { + if (input === null) { + return true; + } + + if (input === undefined) { + return true; + } + + return false; +} diff --git a/packages/utils/src/is_number.js b/packages/utils/src/is_number.js new file mode 100644 index 00000000..743916f6 --- /dev/null +++ b/packages/utils/src/is_number.js @@ -0,0 +1,3 @@ +export function isNumber(input) { + return typeof input === 'number'; +} diff --git a/packages/utils/src/is_undefined.js b/packages/utils/src/is_undefined.js new file mode 100644 index 00000000..e5e30ee2 --- /dev/null +++ b/packages/utils/src/is_undefined.js @@ -0,0 +1,3 @@ +export function isUndefined(input) { + return input === undefined; +} diff --git a/packages/utils/tsconfig.json b/packages/utils/tsconfig.json new file mode 100644 index 00000000..ef8ffdbc --- /dev/null +++ b/packages/utils/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "module": "ESNext", + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "skipLibCheck": true, + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "emitDeclarationOnly": true, // 只输出声明文件(ts 产物) + "declaration": true, // 自动生成声明文件 + "declarationDir": "dist" // 声明文件生成的目录 + }, + "include": ["src"] +} diff --git a/packages/utils/vite.config.js b/packages/utils/vite.config.js new file mode 100644 index 00000000..2172dc60 --- /dev/null +++ b/packages/utils/vite.config.js @@ -0,0 +1,12 @@ +import { defineConfig } from 'vite'; +import { resolve } from 'path'; + +export default defineConfig({ + build: { + lib: { + entry: resolve(__dirname, 'src/index.js'), + name: 'index', + fileName: 'index', + }, + }, +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6abd3936..17c1ea9c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -271,6 +271,9 @@ importers: '@svelement-ui/util-array-2-style-string': specifier: workspace:^ version: link:../util-array-2-style-string + '@svelement-ui/utils': + specifier: workspace:^ + version: link:../utils packages/layout: devDependencies: @@ -344,6 +347,8 @@ importers: packages/util-errors: {} + packages/utils: {} + packages/vite-plugin-prismjs: dependencies: '@babel/core':