A simple function to separate user input with thousands separators.
npm install separate-user-input-by-thousandssh
npm install separate-user-input-by-thousands
`
Usage
$3
`javascript
import { separateByThousands } from "separate-user-input-by-thousands";
`
$3
`jsx
import React, { useState } from "react";
import { separateByThousands } from "separate-user-input-by-thousands";
function App() {
const [previousUserInput, setPreviousUserInput] = useState("");
const [value, setValue] = useState("");
return (
type="text"
value={value}
onChange={(e) => {
const getValue = separateByThousands(
e.target.value,
previousUserInput
);
setPreviousUserInput(getValue);
setValue(getValue);
console.log(getValue);
}}
/>
);
}
export default App;
`
$3
`vue
type="text"
v-model="value"
@input="formatInput"
/>
`
API
$3
Separates the user input with thousands separators.
- input (Type: string): The current user input as a string.
- previousInput (Type: string): The previous user input as a string.
- Returns: The formatted input with thousands separators.
Examples
$3
`javascript
const input = "1234567";
const previousInput = "";
const formattedInput = separateByThousands(input, previousInput);
console.log(formattedInput); // Output: "1,234,567"
``