number-separator-js v1.0.1
Number Separator JS v1.0.1
Welcome to Number Separator JS, the library that makes working with numbers in string format a breeze. This library offers essential functionality to manipulate and format numbers within a string. Currently, it exports two main functions:
numberSeparator
: This function identifies all numbers within your input string and separates them with commas every three digits.separateStringNumber
: This function takes a complete string and returns an object with two attributes:numericParts
(an array of numeric parts) andnonNumericParts
(an array of non-numeric parts).removeUselessZeros
: This function take a numeric amount(called number but it can be a number or string) and If the number is decimal, Deletes useless zeros after the decimal point.
by the way you can use this library on both CommonJs and Es6 Modules!
Demo
you can checkout demo of the project in this link
Installation
You can install Number Separator JS using npm or yarn with the following commands:
npm install number-separator-js
# or
yarn add number-separator-js
Changes in this version
we added removeUselessZeros function to this library thanks to @mary139 so now you can use it directly or use some of it functionalities from our basic numberSeparator function (check usage part) and we added test cases on repo for our contributors and reliability of project.
Usage
CommonJS (require)
const {
numberSeparator,
separateStringNumber,
removeUselessZeros,
} = require("number-separator-js");
const formattedString = numberSeparator({
text: "Your input string containing numbers",
symbol: ",", // Optional, replace with your preferred symbol
fixed: 2, // Optional, fixes all numbers to two decimal places
separateMore: true, // Optional, separates decimal parts too
});
console.log(formattedString);
const result = separateStringNumber("Your input string containing numbers");
console.log(result.numericParts); // Array of numeric parts
console.log(result.nonNumericParts); // Array of non-numeric parts
const resultNumber = removeUselessZeros({
number: "12.000", // it takes both string or numbers
returnType: "number", // Optional, it takes "number" | "string" for the return type
acceptDecimal: true, // Optional, it's default value is true change it to false if you want to remove decimal part of number
fixed: 2, // Optional, fixes all numbers to two decimal places
});
console.log(resultNumber);
ES6 Modules (import)
import {
numberSeparator,
separateStringNumber,
removeUselessZeros,
} from "number-separator-js";
const formattedString = numberSeparator({
text: "Your input string containing numbers",
symbol: ",", // Optional, replace with your preferred symbol
fixed: 2, // Optional, fixes all numbers to two decimal places
separateMore: true, // Optional, separates decimal parts too
allowUselessZeros: false, // Optional, the default value is true if you set it to false it will remove useless zeros for you
});
console.log(formattedString);
const result = separateStringNumber("Your input string containing numbers");
console.log(result.numericParts); // Array of numeric parts
console.log(result.nonNumericParts); // Array of non-numeric parts
const resultNumber = removeUselessZeros({
number: "12.000", // it takes both string or numbers
returnType: "number", // Optional, it takes "number" | "string" for the return type
acceptDecimal: true, // Optional, it's default value is true change it to false if you want to remove decimal part of number
fixed: 2, // Optional, fixes all numbers to two decimal places
allowUselessZeros: false, // Optional, the default value is true if you set it to false it will remove useless zeros for you
});
console.log(resultNumber);
Features
- Find all numbers in a string and format them with commas.
- Customize formatting with optional attributes like symbol, fixed, and separateMore.
- Identify and separate numeric and non-numeric parts of a string.
- remove useless zero of numbers for example : 012.00 => 12
Contributing
We welcome contributions to make Number Separator JS even better! If you're interested in enhancing this library or have specific ideas in mind, here's how you can contribute:
- Fork the Number Separator JS GitHub repository.
- Make your changes and improvements.
- Ensure that your code passes the CI tests.
- Submit a pull request, and we'll review your changes.
Contributors
Maryam Alishahi: our first contributor We owe remove useless zero function to her
Contact Information
We also encourage discussions and knowledge sharing! Feel free to reach out on my social media pages, where we can chat and collaborate:
- GitHub: @shayan1999
- GitLab: @shayan1999
- Telegram: @shyn99
- LinkedIn: Ali Rostami
Check the "Contributing" section in the project repository for details on future features we're looking to add to this library(Coming Soon).
License
Number Separator JS is licensed under the MIT License.
Acknowledgements
in this version we get our first contributor Maryam
We'll be acknowledging our contributors in this section in the future. Stay tuned for updates!
Hi, I'm Shayan! 👋
🚀 About Me
I am a front-end developer who knows a little bit of back-end you can follow me on my git accounts and LinkedIn