A simple number formatting script
Go to file
Robert Morrison 1076cd2895
fix: Get language instead of hard coding
The language data that is used to set the locale of the session is now
grabbed from the DOM intstead of relying on a hardcoded value.
2022-10-08 03:45:55 +01:00
logo.png chore(Repo): Add logo 2022-10-07 22:15:47 +01:00
logo.svg chore(Repo): Add logo 2022-10-07 22:15:47 +01:00
numberFormat.js fix: Get language instead of hard coding 2022-10-08 03:45:55 +01:00
ReadMe.md Initial commit 2022-10-07 21:54:12 +01:00

numberFormat.js

A simple JS library that automatically formats numbers on your web page. Designed mainly for use on static websites to avoid the bother of formatting numbers manually.

Usage

  • Host the script somewhere on your system.
  • Ensure you set the language for your HTML
    (this will be essential with the first official release.)
  • Add a script tag to your document head that has the src set to this script.
    The script tag must also be set to defer
  • Surround any numbers you want formatting with <num> .. </num> tags.
    These 'custom' tags are used so the script can efficiently find numbers without needing to resort to jQuery or regex.
    This also allows you to specify numbers you don't want formatted.

Example

<html lang="YOUR-LANGUAGE">
	<head>
		<title>test</title>
		<script defer src="https://{YOUR_DOMAIN}/somewhere/numberFormat.js"></script>
	</head>
	<body>
		<p>This is a formatted number <num>1234567890</num></p>
	</body>
</html>

Design goals

  • Code simplicity
  • Easily extendable
  • Using only native JS

Design non-goals

  • Locale detection
    This is not useful since web pages should be consistent.
    Locale detection would break this.
  • Date formatting
    This should be an entirely different package.
    It is a completely different task.

TODO:

  • Add support for currency formatting
  • Change language/locale to use document language tag.
  • Check for optimisations
  • If this becomes popular host to a CDN
  • Automate releases that include a minified version
    I personally don't care for minified JS but some people love it
    This is an extremely low-priority task.

Changelog

  • 2022-10-07
    Initial Upload of basic script
    Robert Morrison <sherlock5512>