Skip to content

Commit

Permalink
fix(utils): add
Browse files Browse the repository at this point in the history
  • Loading branch information
koory1st committed Nov 23, 2023
1 parent e1491b2 commit f513358
Show file tree
Hide file tree
Showing 12 changed files with 246 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/input-number/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 7 additions & 4 deletions packages/input-number/src/lib/input-number.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
Expand Down
24 changes: 24 additions & 0 deletions packages/utils/.gitignore
Original file line number Diff line number Diff line change
@@ -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?
132 changes: 132 additions & 0 deletions packages/utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
22 changes: 22 additions & 0 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
2 changes: 2 additions & 0 deletions packages/utils/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { isNull } from './is_null.js';
export { isNumber } from './is_number.js';
11 changes: 11 additions & 0 deletions packages/utils/src/is_null.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function isNull(input) {
if (input === null) {
return true;
}

if (input === undefined) {
return true;
}

return false;
}
3 changes: 3 additions & 0 deletions packages/utils/src/is_number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function isNumber(input) {
return typeof input === 'number';
}
3 changes: 3 additions & 0 deletions packages/utils/src/is_undefined.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function isUndefined(input) {
return input === undefined;
}
23 changes: 23 additions & 0 deletions packages/utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"]
}
12 changes: 12 additions & 0 deletions packages/utils/vite.config.js
Original file line number Diff line number Diff line change
@@ -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',
},
},
});
5 changes: 5 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f513358

Please sign in to comment.