New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vue-currency-input

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-currency-input - npm Package Compare versions

Comparing version 2.5.1 to 3.0.0

91

dist/index.cjs.js

@@ -10,3 +10,3 @@ /**

var vueDemi = require('vue-demi');
var vue = require('vue');

@@ -245,3 +245,2 @@ const escapeRegExp = (str) => {

currencyDisplay: undefined,
exportValueAsInteger: false,
hideGroupingSeparatorOnFocus: true,

@@ -253,3 +252,2 @@ hideCurrencySymbolOnFocus: true,

valueRange: undefined,
autoSign: true,
useGrouping: true,

@@ -303,8 +301,3 @@ valueScaling: undefined

};
if (this.options.exportValueAsInteger) {
this.valueScaling = valueScalingOptions[exports.ValueScaling.precision];
}
else {
this.valueScaling = this.options.valueScaling ? valueScalingOptions[this.options.valueScaling] : undefined;
}
this.valueScaling = this.options.valueScaling ? valueScalingOptions[this.options.valueScaling] : undefined;
this.valueScalingFractionDigits =

@@ -323,5 +316,2 @@ this.valueScaling !== undefined && this.options.valueScaling !== exports.ValueScaling.precision

}
if (!this.options.autoSign && min < 0) {
min = 0;
}
return min;

@@ -335,5 +325,2 @@ }

}
if (!this.options.autoSign && max < 0) {
max = this.toFloat(Number.MAX_SAFE_INTEGER);
}
return max;

@@ -390,10 +377,8 @@ }

}
if (this.options.autoSign) {
if (this.maxValue <= 0 && !this.currencyFormat.isNegative(formattedValue) && this.currencyFormat.parse(formattedValue) !== 0) {
formattedValue = formattedValue.replace(this.currencyFormat.prefix, this.currencyFormat.negativePrefix);
}
if (this.minValue >= 0) {
formattedValue = formattedValue.replace(this.currencyFormat.negativePrefix, this.currencyFormat.prefix);
}
if (this.maxValue <= 0 && !this.currencyFormat.isNegative(formattedValue) && this.currencyFormat.parse(formattedValue) !== 0) {
formattedValue = formattedValue.replace(this.currencyFormat.prefix, this.currencyFormat.negativePrefix);
}
if (this.minValue >= 0) {
formattedValue = formattedValue.replace(this.currencyFormat.negativePrefix, this.currencyFormat.prefix);
}
if (this.options.currencyDisplay === exports.CurrencyDisplay.hidden || (this.focus && this.options.hideCurrencySymbolOnFocus)) {

@@ -535,20 +520,20 @@ formattedValue = formattedValue

var useCurrencyInput = (options, autoEmit) => {
var _a;
var _a, _b, _c, _d;
let numberInput;
let input;
const inputRef = vueDemi.ref(null);
const formattedValue = vueDemi.ref(null);
const numberValue = vueDemi.ref(null);
const instance = vueDemi.getCurrentInstance();
const emit = (event, value) => instance === null || instance === void 0 ? void 0 : instance.emit(event, value);
const lazyModel = vueDemi.isVue3 && ((_a = instance === null || instance === void 0 ? void 0 : instance.attrs.modelModifiers) === null || _a === void 0 ? void 0 : _a.lazy);
const modelValue = vueDemi.computed(() => instance === null || instance === void 0 ? void 0 : instance.props[vueDemi.isVue3 ? 'modelValue' : 'value']);
const inputEvent = vueDemi.isVue3 ? 'update:modelValue' : 'input';
const inputRef = vue.ref(null);
const formattedValue = vue.ref(null);
const numberValue = vue.ref(null);
const vm = vue.getCurrentInstance();
const emit = (vm === null || vm === void 0 ? void 0 : vm.emit) || ((_b = (_a = vm === null || vm === void 0 ? void 0 : vm.proxy) === null || _a === void 0 ? void 0 : _a.$emit) === null || _b === void 0 ? void 0 : _b.bind(vm === null || vm === void 0 ? void 0 : vm.proxy));
const props = ((vm === null || vm === void 0 ? void 0 : vm.props) || ((_c = vm === null || vm === void 0 ? void 0 : vm.proxy) === null || _c === void 0 ? void 0 : _c.$props));
const isVue3 = vue.version.startsWith('3');
const lazyModel = isVue3 && ((_d = vm === null || vm === void 0 ? void 0 : vm.attrs.modelModifiers) === null || _d === void 0 ? void 0 : _d.lazy);
const modelValue = vue.computed(() => props === null || props === void 0 ? void 0 : props[isVue3 ? 'modelValue' : 'value']);
const inputEvent = isVue3 ? 'update:modelValue' : 'input';
const changeEvent = lazyModel ? 'update:modelValue' : 'change';
const hasInputEventListener = !vueDemi.isVue3 || !lazyModel;
const hasChangeEventListener = !vueDemi.isVue3 || lazyModel || !(instance === null || instance === void 0 ? void 0 : instance.attrs.onChange);
const onInput = (e) => {
if (e.detail) {
if (autoEmit !== false && modelValue.value !== e.detail.number) {
emit(inputEvent, e.detail.number);
if (!lazyModel && autoEmit !== false && modelValue.value !== e.detail.number) {
emit === null || emit === void 0 ? void 0 : emit(inputEvent, e.detail.number);
}

@@ -561,21 +546,13 @@ numberValue.value = e.detail.number;

if (e.detail) {
if (autoEmit !== false) {
emit(changeEvent, e.detail.number);
}
numberValue.value = e.detail.number;
formattedValue.value = e.detail.formatted;
emit === null || emit === void 0 ? void 0 : emit(changeEvent, e.detail.number);
}
};
vueDemi.watch(inputRef, (value) => {
var _a, _b;
vue.watch(inputRef, (value) => {
var _a;
if (value) {
input = findInput((_b = (_a = value) === null || _a === void 0 ? void 0 : _a.$el) !== null && _b !== void 0 ? _b : value);
input = findInput((_a = value === null || value === void 0 ? void 0 : value.$el) !== null && _a !== void 0 ? _a : value);
if (input) {
input.addEventListener('input', onInput);
input.addEventListener('change', onChange);
numberInput = new CurrencyInput(input, options);
if (hasInputEventListener) {
input.addEventListener('input', onInput);
}
if (hasChangeEventListener) {
input.addEventListener('change', onChange);
}
numberInput.setValue(modelValue.value);

@@ -591,9 +568,5 @@ }

});
vueDemi.onUnmounted(() => {
if (hasInputEventListener) {
input === null || input === void 0 ? void 0 : input.removeEventListener('input', onInput);
}
if (hasChangeEventListener) {
input === null || input === void 0 ? void 0 : input.removeEventListener('change', onChange);
}
vue.onUnmounted(() => {
input === null || input === void 0 ? void 0 : input.removeEventListener('input', onInput);
input === null || input === void 0 ? void 0 : input.removeEventListener('change', onChange);
});

@@ -609,8 +582,2 @@ return {

const parse = (formattedValue, options) => {
return new CurrencyFormat(options).parse(formattedValue);
};
exports["default"] = useCurrencyInput;
exports.parse = parse;
exports.useCurrencyInput = useCurrencyInput;

@@ -1,2 +0,2 @@

import { Ref } from 'vue-demi';
import { Ref } from 'vue';

@@ -32,6 +32,2 @@ interface CurrencyInputValue {

interface CurrencyInputOptions extends CurrencyFormatOptions {
/**
* @deprecated Use `valueScaling` instead.
*/
exportValueAsInteger?: boolean;
hideCurrencySymbolOnFocus?: boolean;

@@ -41,3 +37,2 @@ hideGroupingSeparatorOnFocus?: boolean;

autoDecimalDigits?: boolean;
autoSign?: boolean;
valueRange?: NumberRange;

@@ -55,6 +50,4 @@ useGrouping?: boolean;

declare const _default: (options: CurrencyInputOptions, autoEmit?: boolean | undefined) => UseCurrencyInput;
declare const _default: (options: CurrencyInputOptions, autoEmit?: boolean) => UseCurrencyInput;
declare const parse: (formattedValue: string | null, options: CurrencyFormatOptions) => number | null;
export { CurrencyDisplay, CurrencyFormatOptions, CurrencyInputOptions, CurrencyInputValue, NumberRange, UseCurrencyInput, ValueScaling, _default as default, parse, _default as useCurrencyInput };
export { CurrencyDisplay, CurrencyFormatOptions, CurrencyInputOptions, CurrencyInputValue, NumberRange, UseCurrencyInput, ValueScaling, _default as useCurrencyInput };

@@ -6,3 +6,3 @@ /**

*/
import { ref, getCurrentInstance, isVue3, computed, watch, onUnmounted } from 'vue-demi';
import { ref, getCurrentInstance, version, computed, watch, onUnmounted } from 'vue';

@@ -241,3 +241,2 @@ const escapeRegExp = (str) => {

currencyDisplay: undefined,
exportValueAsInteger: false,
hideGroupingSeparatorOnFocus: true,

@@ -249,3 +248,2 @@ hideCurrencySymbolOnFocus: true,

valueRange: undefined,
autoSign: true,
useGrouping: true,

@@ -299,8 +297,3 @@ valueScaling: undefined

};
if (this.options.exportValueAsInteger) {
this.valueScaling = valueScalingOptions[ValueScaling.precision];
}
else {
this.valueScaling = this.options.valueScaling ? valueScalingOptions[this.options.valueScaling] : undefined;
}
this.valueScaling = this.options.valueScaling ? valueScalingOptions[this.options.valueScaling] : undefined;
this.valueScalingFractionDigits =

@@ -319,5 +312,2 @@ this.valueScaling !== undefined && this.options.valueScaling !== ValueScaling.precision

}
if (!this.options.autoSign && min < 0) {
min = 0;
}
return min;

@@ -331,5 +321,2 @@ }

}
if (!this.options.autoSign && max < 0) {
max = this.toFloat(Number.MAX_SAFE_INTEGER);
}
return max;

@@ -386,10 +373,8 @@ }

}
if (this.options.autoSign) {
if (this.maxValue <= 0 && !this.currencyFormat.isNegative(formattedValue) && this.currencyFormat.parse(formattedValue) !== 0) {
formattedValue = formattedValue.replace(this.currencyFormat.prefix, this.currencyFormat.negativePrefix);
}
if (this.minValue >= 0) {
formattedValue = formattedValue.replace(this.currencyFormat.negativePrefix, this.currencyFormat.prefix);
}
if (this.maxValue <= 0 && !this.currencyFormat.isNegative(formattedValue) && this.currencyFormat.parse(formattedValue) !== 0) {
formattedValue = formattedValue.replace(this.currencyFormat.prefix, this.currencyFormat.negativePrefix);
}
if (this.minValue >= 0) {
formattedValue = formattedValue.replace(this.currencyFormat.negativePrefix, this.currencyFormat.prefix);
}
if (this.options.currencyDisplay === CurrencyDisplay.hidden || (this.focus && this.options.hideCurrencySymbolOnFocus)) {

@@ -531,3 +516,3 @@ formattedValue = formattedValue

var useCurrencyInput = (options, autoEmit) => {
var _a;
var _a, _b, _c, _d;
let numberInput;

@@ -538,14 +523,14 @@ let input;

const numberValue = ref(null);
const instance = getCurrentInstance();
const emit = (event, value) => instance === null || instance === void 0 ? void 0 : instance.emit(event, value);
const lazyModel = isVue3 && ((_a = instance === null || instance === void 0 ? void 0 : instance.attrs.modelModifiers) === null || _a === void 0 ? void 0 : _a.lazy);
const modelValue = computed(() => instance === null || instance === void 0 ? void 0 : instance.props[isVue3 ? 'modelValue' : 'value']);
const vm = getCurrentInstance();
const emit = (vm === null || vm === void 0 ? void 0 : vm.emit) || ((_b = (_a = vm === null || vm === void 0 ? void 0 : vm.proxy) === null || _a === void 0 ? void 0 : _a.$emit) === null || _b === void 0 ? void 0 : _b.bind(vm === null || vm === void 0 ? void 0 : vm.proxy));
const props = ((vm === null || vm === void 0 ? void 0 : vm.props) || ((_c = vm === null || vm === void 0 ? void 0 : vm.proxy) === null || _c === void 0 ? void 0 : _c.$props));
const isVue3 = version.startsWith('3');
const lazyModel = isVue3 && ((_d = vm === null || vm === void 0 ? void 0 : vm.attrs.modelModifiers) === null || _d === void 0 ? void 0 : _d.lazy);
const modelValue = computed(() => props === null || props === void 0 ? void 0 : props[isVue3 ? 'modelValue' : 'value']);
const inputEvent = isVue3 ? 'update:modelValue' : 'input';
const changeEvent = lazyModel ? 'update:modelValue' : 'change';
const hasInputEventListener = !isVue3 || !lazyModel;
const hasChangeEventListener = !isVue3 || lazyModel || !(instance === null || instance === void 0 ? void 0 : instance.attrs.onChange);
const onInput = (e) => {
if (e.detail) {
if (autoEmit !== false && modelValue.value !== e.detail.number) {
emit(inputEvent, e.detail.number);
if (!lazyModel && autoEmit !== false && modelValue.value !== e.detail.number) {
emit === null || emit === void 0 ? void 0 : emit(inputEvent, e.detail.number);
}

@@ -558,21 +543,13 @@ numberValue.value = e.detail.number;

if (e.detail) {
if (autoEmit !== false) {
emit(changeEvent, e.detail.number);
}
numberValue.value = e.detail.number;
formattedValue.value = e.detail.formatted;
emit === null || emit === void 0 ? void 0 : emit(changeEvent, e.detail.number);
}
};
watch(inputRef, (value) => {
var _a, _b;
var _a;
if (value) {
input = findInput((_b = (_a = value) === null || _a === void 0 ? void 0 : _a.$el) !== null && _b !== void 0 ? _b : value);
input = findInput((_a = value === null || value === void 0 ? void 0 : value.$el) !== null && _a !== void 0 ? _a : value);
if (input) {
input.addEventListener('input', onInput);
input.addEventListener('change', onChange);
numberInput = new CurrencyInput(input, options);
if (hasInputEventListener) {
input.addEventListener('input', onInput);
}
if (hasChangeEventListener) {
input.addEventListener('change', onChange);
}
numberInput.setValue(modelValue.value);

@@ -589,8 +566,4 @@ }

onUnmounted(() => {
if (hasInputEventListener) {
input === null || input === void 0 ? void 0 : input.removeEventListener('input', onInput);
}
if (hasChangeEventListener) {
input === null || input === void 0 ? void 0 : input.removeEventListener('change', onChange);
}
input === null || input === void 0 ? void 0 : input.removeEventListener('input', onInput);
input === null || input === void 0 ? void 0 : input.removeEventListener('change', onChange);
});

@@ -606,6 +579,2 @@ return {

const parse = (formattedValue, options) => {
return new CurrencyFormat(options).parse(formattedValue);
};
export { CurrencyDisplay, ValueScaling, useCurrencyInput as default, parse, useCurrencyInput };
export { CurrencyDisplay, ValueScaling, useCurrencyInput };
{
"name": "vue-currency-input",
"description": "Easy input of currency formatted numbers for Vue.js.",
"version": "2.5.1",
"version": "3.0.0",
"license": "MIT",

@@ -46,10 +46,4 @@ "module": "./dist/index.esm.js",

"peerDependencies": {
"@vue/composition-api": "^1.4.0",
"vue": "^2.6 || ^3.0.0"
"vue": "^2.7 || ^3.0.0"
},
"peerDependenciesMeta": {
"@vue/composition-api": {
"optional": true
}
},
"devDependencies": {

@@ -62,3 +56,2 @@ "@rushstack/eslint-patch": "^1.1.3",

"@typescript-eslint/parser": "^5.26.0",
"@vue/composition-api": "^1.6.2",
"@vue/eslint-config-prettier": "^7.0.0",

@@ -91,5 +84,2 @@ "@vue/eslint-config-typescript": "^10.0.0",

},
"dependencies": {
"vue-demi": "^0.12.1"
},
"simple-git-hooks": {

@@ -96,0 +86,0 @@ "pre-commit": "npx lint-staged"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc