Git Product home page Git Product logo

numberseparatorjs's Introduction

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:

  1. numberSeparator: This function identifies all numbers within your input string and separates them with commas every three digits.

  2. separateStringNumber: This function takes a complete string and returns an object with two attributes: numericParts (an array of numeric parts) and nonNumericParts (an array of non-numeric parts).

  3. 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:

  1. Fork the Number Separator JS GitHub repository.
  2. Make your changes and improvements.
  3. Ensure that your code passes the CI tests.
  4. 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:

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

numberseparatorjs's People

Contributors

shayan1999 avatar

Stargazers

mary avatar

Watchers

 avatar

numberseparatorjs's Issues

removeUselessZeros doesn't have attribute to define useless zero

removeUselessZeros doesn't have attribute to define useless zero

we need an attribute for removeUselessZeros function to determine how many zeros on decimal part are useless zeros.

for example for now if you put 1234.02 it will give you exact number but if you put 1234.002 it will return 1234 because it thinks that 2 came after useless zeros if this attribute is 2 so our function now is working ok but maybe user wants bigger number for this purpose.

update demo page

update demo page

we have a demo on demo folder of project and it works correctly but we can make it look better functionally and visually so it will be great if someone make it cleaner and totally better.
if you think you can help us feel free to join us here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.