Skip to content

Commit 71e1e4a

Browse files
committed
linked from tracking branch
1 parent 41def28 commit 71e1e4a

16 files changed

+2601
-1101
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
!docs/.vitepress
22
dist
3+
examples

.eslintrc.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,5 @@ module.exports = {
66
env: {
77
node: true
88
},
9-
extends: ['plugin:vue/recommended', 'eslint:recommended', '@vue/eslint-config-typescript/recommended', '@vue/eslint-config-prettier'],
10-
rules: {
11-
// Customize your rules here
12-
}
9+
extends: ['plugin:vue/vue3-recommended', 'eslint:recommended', '@vue/eslint-config-typescript/recommended', '@vue/eslint-config-prettier']
1310
}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ npm-debug.log*
1010
yarn-debug.log*
1111
yarn-error.log*
1212
pnpm-debug.log*
13+
node_modules
1314
.temp
1415
.cache
15-
*.bak
1616
example*

.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"editor.formatOnSave": true,
3-
"editor.formatOnSaveMode": "modificationsIfAvailable"
2+
"editor.formatOnPaste": false,
3+
"editor.formatOnSave": true
44
}

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ npm install @coders-tm/vue-number-format
1717
or
1818
yarn add @coders-tm/vue-number-format
1919
```
20-
## Vue 2.0
21-
```bash
22-
npm install @coders-tm/vue-number-format@2.0.7
23-
or
24-
yarn add @coders-tm/vue-number-format@2.0.7
25-
```
20+
2621
## Features
2722

2823
- Lightweight

docs/guide/README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# Introduction
2-
Vue Number Format is used to format a number using fixed-point notation. It can be used to format a number with a specific number of digits to the right of the decimal.
3-
## Installation
4-
Install the npm package: @coders-tm/vue-number-format@2.0.7 for Vue 2.0
52

63
[![npm Version](https://badgen.net/npm/v/@coders-tm/vue-number-format?color=green)](https://www.npmjs.com/package/@coders-tm/vue-number-format)
74
[![npm Downloads](https://badgen.net/npm/dt/@coders-tm/vue-number-format?color=green)](https://www.npmjs.com/package/@coders-tm/vue-number-format)

docs/guide/config.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ The precision property returns the number of bits of precision that can be repre
5050
- Type: `string`
5151
- Default: `2`
5252
- Required: `false`
53-
## nullValue
5453

5554
## minimumFractionDigits
5655

package.json

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coders-tm/vue-number-format",
3-
"version": "2.2.1",
3+
"version": "3.2.0",
44
"private": false,
55
"description": "Easy formatted numbers, currency and percentage with input/directive mask for Vue.js",
66
"author": "Dipak Sarkar <hello@dipaksarkar.in> (https://dipaksarkar.in/)",
@@ -20,41 +20,15 @@
2020
},
2121
"sideeffects": false,
2222
"scripts": {
23-
"build": "tsc --emitDeclarationOnly --skipLibCheck --declaration --outDir .temp/types && rollup --c rollup.config.js",
24-
"docs:build": "vuepress build docs",
23+
"prebuild": "rimraf dist .temp/types",
24+
"build": "tsc --emitDeclarationOnly --declaration --outDir .temp/types && rollup -c rollup.config.js",
2525
"docs:dev": "vuepress dev docs",
26+
"docs:build": "vuepress build docs",
2627
"test": "vitest",
2728
"coverage": "vitest run --coverage",
28-
"lint": "eslint 'src/**/*.{js,vue}'",
29+
"lint": "eslint --no-fix --max-warnings 0 {**/*,*}.{js,ts,vue}",
2930
"push": "clear && git config core.ignorecase false && branch=\"$(git symbolic-ref -q HEAD)\" || \"dev\" && branch=${branch##refs/heads/} && branch=${branch:-HEAD} && echo Pushing to Branch \"$branch\" && echo Please type your commit message && read msg && clear && git add . && git commit -m \"$msg\" && git push origin \"$branch\""
3031
},
31-
"devDependencies": {
32-
"@rollup/plugin-node-resolve": "^15.0.1",
33-
"@rushstack/eslint-patch": "^1.2.0",
34-
"@types/jest": "^29.4.0",
35-
"@typescript-eslint/eslint-plugin": "^5.38.1",
36-
"@typescript-eslint/parser": "^5.38.1",
37-
"@vue/eslint-config-prettier": "^7.0.0",
38-
"@vue/eslint-config-typescript": "^11.0.2",
39-
"@vue/test-utils": "^1.3.0",
40-
"eslint": "^8.34.0",
41-
"eslint-config-prettier": "^8.5.0",
42-
"eslint-plugin-vue": "^9.9.0",
43-
"jsdom": "latest",
44-
"lint-staged": "^13.1.2",
45-
"prettier": "^2.7.1",
46-
"rimraf": "^3.0.2",
47-
"rollup": "^2.6.1",
48-
"rollup-plugin-dts": "^4.2.2",
49-
"rollup-plugin-filesize": "^9.1.2",
50-
"rollup-plugin-typescript2": "^0.34.1",
51-
"typescript": "^4.9.5",
52-
"vite": "^4.1.1",
53-
"vite-plugin-vue2": "^1.9.3",
54-
"vitest": "^0.28.5",
55-
"vue": "^2.6.0",
56-
"vue-template-compiler": "^2.6.0"
57-
},
5832
"bugs": {
5933
"url": "https://github.com/coders-tm/vue-number-format/issues"
6034
},
@@ -79,6 +53,47 @@
7953
"publishConfig": {
8054
"@coders-tm:registry": "https://npm.pkg.github.com"
8155
},
56+
"peerDependencies": {
57+
"vue": "^2.7 || ^3.0.0"
58+
},
59+
"devDependencies": {
60+
"@rushstack/eslint-patch": "^1.2.0",
61+
"@testing-library/dom": "^8.18.1",
62+
"@testing-library/user-event": "^13.5.0",
63+
"@types/jest": "^29.4.0",
64+
"@typescript-eslint/eslint-plugin": "^5.38.1",
65+
"@typescript-eslint/parser": "^5.38.1",
66+
"@vitejs/plugin-vue": "latest",
67+
"@vitest/coverage-c8": "^0.23.4",
68+
"@vue/eslint-config-prettier": "^7.0.0",
69+
"@vue/eslint-config-typescript": "^11.0.2",
70+
"@vue/test-utils": "^2.0.0",
71+
"@vuepress/plugin-google-analytics": "^2.0.0-beta.27",
72+
"@vuepress/plugin-medium-zoom": "^2.0.0-beta.27",
73+
"@vuepress/plugin-register-components": "2.0.0-beta.27",
74+
"@vuepress/plugin-search": "^2.0.0-beta.27",
75+
"eslint": "^8.24.0",
76+
"eslint-config-prettier": "^8.5.0",
77+
"eslint-plugin-vue": "^9.5.1",
78+
"jsdom": "latest",
79+
"lint-staged": "^13.0.3",
80+
"prettier": "^2.7.1",
81+
"rimraf": "^3.0.2",
82+
"rollup": "^2.79.1",
83+
"rollup-plugin-cleanup": "^3.2.1",
84+
"rollup-plugin-dts": "^4.2.2",
85+
"rollup-plugin-filesize": "^9.1.2",
86+
"rollup-plugin-typescript2": "^0.34.0",
87+
"simple-git-hooks": "^2.8.0",
88+
"typescript": "^4.8.4",
89+
"unplugin-vue-components": "^0.22.7",
90+
"vite": "^3.2.3",
91+
"vite-plugin-windicss": "^1.8.1",
92+
"vitest": "latest",
93+
"vue": "^3.0.0",
94+
"vuepress-vite": "^2.0.0-beta.27",
95+
"windicss": "^3.5.0"
96+
},
8297
"simple-git-hooks": {
8398
"pre-commit": "npx lint-staged"
8499
},

rollup.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import typescript from 'rollup-plugin-typescript2'
2-
import filesize from 'rollup-plugin-filesize'
3-
import resolve from '@rollup/plugin-node-resolve'
42
import dts from 'rollup-plugin-dts'
3+
import cleanup from 'rollup-plugin-cleanup'
4+
import filesize from 'rollup-plugin-filesize'
55
import pkg from './package.json'
66

77
const banner = `/**
@@ -12,7 +12,7 @@ const banner = `/**
1212

1313
export default [
1414
{
15-
input: 'src/index.ts',
15+
input: `src/index.ts`,
1616
output: [
1717
{
1818
file: pkg.main,
@@ -35,7 +35,7 @@ export default [
3535
}
3636
}
3737
}),
38-
resolve(),
38+
cleanup({ extensions: ['js', 'ts'] }),
3939
filesize()
4040
],
4141
external: ['vue']

src/component.ts

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import Vue from 'vue'
2-
import directive from './directive'
1+
import { defineComponent } from 'vue'
32
import { cloneDeep, CustomInputEvent, Input } from './core'
3+
import directive from './directive'
44
import defaultOptions from './options'
55

6-
Vue.directive('number', directive)
7-
86
const options = cloneDeep(defaultOptions)
97

10-
export default Vue.extend({
8+
export default defineComponent({
119
name: 'VueNumber',
10+
directives: {
11+
number: directive
12+
},
1213
props: {
13-
value: {
14-
required: true,
15-
type: [Number, String]
14+
modelValue: {
15+
type: [String, Number],
16+
required: true
1617
},
1718
nullValue: {
1819
type: [Number, String],
@@ -35,19 +36,19 @@ export default Vue.extend({
3536
default: () => options.precision
3637
},
3738
minimumFractionDigits: {
38-
type: Number,
39+
type: [Number, Boolean],
3940
default: () => options.minimumFractionDigits
4041
},
4142
decimal: {
4243
type: String,
4344
default: () => options.decimal
4445
},
4546
min: {
46-
type: Number,
47+
type: [Number, Boolean],
4748
default: () => options.min
4849
},
4950
max: {
50-
type: Number,
51+
type: [Number, Boolean],
5152
default: () => options.max
5253
},
5354
separator: {
@@ -63,9 +64,10 @@ export default Vue.extend({
6364
default: () => options.suffix
6465
}
6566
},
67+
emits: ['update:model-value', 'input:model-value'],
6668
data() {
6769
return {
68-
maskedValue: this.value,
70+
maskedValue: this.modelValue,
6971
unmaskedValue: '' as Input | undefined
7072
}
7173
},
@@ -90,33 +92,24 @@ export default Vue.extend({
9092
}
9193
}
9294
},
93-
watch: {
94-
value(val) {
95-
if (this.unmaskedValue !== val) {
96-
this.maskedValue = val
97-
}
98-
}
99-
},
10095
methods: {
10196
input(event: CustomInputEvent) {
10297
const { target } = event
10398
this.maskedValue = target.value
10499
this.unmaskedValue = target.unmaskedValue
105-
this.$emit('input', this.emittedValue)
100+
this.$emit('input:model-value', this.emittedValue)
106101
},
107102
change() {
108-
this.$emit('change', this.emittedValue)
103+
this.$emit('update:model-value', this.emittedValue)
109104
}
110105
},
111106
template: `<input
112107
v-number="config"
113108
type="text"
114109
autocomplete="off"
115110
:value="maskedValue"
116-
class="v-number"
111+
class="v-number vue-number-format"
117112
@change="change"
118113
@input="input"
119-
@blur="(evt) => $emit('blur', evt)"
120-
@focus="(evt) => $emit('focus', evt)"
121-
>`
114+
/>`
122115
})

src/core.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function updateCursor(el: HTMLInputElement, position: number) {
111111
*/
112112
export function updateValue(el: CustomInputElement, vnode: VNode | null, { emit = true, force = false, clean = false } = {}) {
113113
const { options, oldValue } = el
114-
const currentValue = vnode && vnode.data && vnode.data.domProps ? vnode.data.domProps.value : el.value
114+
const currentValue = vnode?.props?.value || el.value
115115

116116
if (force || oldValue !== currentValue) {
117117
const number = new NumberFormat(options).clean(clean && !options.reverseFill)
@@ -152,7 +152,7 @@ export function inputHandler(event: CustomInputEvent, el?: CustomInputElement) {
152152
const { target, detail } = event
153153

154154
// We dont need to run this method on the event we emit (prevent event loop)
155-
if (detail && detail.facade) {
155+
if (detail?.facade) {
156156
return false
157157
}
158158

@@ -191,7 +191,7 @@ export function blurHandler(event: Event, el?: CustomInputElement) {
191191
const { target, detail } = event as CustomInputEvent
192192

193193
// We dont need to run this method on the event we emit (prevent event loop)
194-
if (detail && detail.facade) {
194+
if (detail?.facade) {
195195
return false
196196
}
197197

src/directive.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import { VNode } from 'vue'
2-
import { DirectiveBinding } from 'vue/types/options'
1+
import { DirectiveBinding, VNode } from 'vue'
32
import * as core from './core'
43
import defaultOptions from './options'
54

65
export default {
7-
bind: (el: core.CustomInputElement, { value, modifiers }: DirectiveBinding, vnode: VNode) => {
6+
beforeMount: (el: core.CustomInputElement, { value, modifiers }: DirectiveBinding, vnode: VNode) => {
87
el = core.getInputElement(el)
98
const options = Object.assign(core.cloneDeep(defaultOptions), value, modifiers)
109
el.options = options
1110
// set initial value
1211
core.updateValue(el, vnode, { force: options.prefill, clean: true })
1312
},
1413

15-
inserted: (el: core.CustomInputElement) => {
14+
mounted: (el: core.CustomInputElement) => {
1615
el = core.getInputElement(el)
1716

1817
// prefer adding event listener to parent element to avoid Firefox bug which does not
@@ -38,7 +37,7 @@ export default {
3837
el.cleanup = () => handlerOwner.removeEventListener('input', oninput, true)
3938
},
4039

41-
update: (el: core.CustomInputElement, { value, oldValue, modifiers }: DirectiveBinding, vnode: VNode) => {
40+
updated: (el: core.CustomInputElement, { value, oldValue, modifiers }: DirectiveBinding, vnode: VNode) => {
4241
el = core.getInputElement(el)
4342
const options = el.options
4443
el.options = Object.assign(options, value, modifiers)
@@ -49,7 +48,7 @@ export default {
4948
}
5049
},
5150

52-
unbind: (el: core.CustomInputElement) => {
51+
unmounted: (el: core.CustomInputElement) => {
5352
core.getInputElement(el).cleanup()
5453
}
5554
}

src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import NumberFormat from './number-format'
55

66
export { component, directive, options, NumberFormat }
77

8-
export default {
9-
install(Vue: any, config?: Config) {
8+
const VueNumberFormat = {
9+
install(app: any, config?: Config) {
1010
if (config) {
1111
Object.assign(options, config)
1212
}
13-
Vue.directive('number', directive)
14-
Vue.component('VueNumber', component)
13+
app.directive('number', directive)
14+
app.component('VueNumber', component)
1515
}
1616
}
17+
18+
export default VueNumberFormat

0 commit comments

Comments
 (0)