Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
IAmYhvr authored Mar 1, 2019
1 parent 9f8b4c2 commit 94c687f
Showing 1 changed file with 73 additions and 21 deletions.
94 changes: 73 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# simpleformat.js
A simple number formatter. <br>
simpleformat.js has two functions- `format.normal()`, and `format.mixed()`

`format.normal()` has 2 inputs: `number` and `type`. <br>
`number` Is where you enter your variable. <br>
`type` Is the type of formatting you want. <br>
A simple number formatter.

simpleformat.js has three functions- `format.normal()`, `format.mixed()`, and `format.create()`.

## Normal Formatting
`format.normal()` has two fields.
`number` Is where you enter your variable.
`type` Is the type of formatting you want.

Some examples:
```
```javascript
format.normal(1.45e51, 'nor')
//OUTPUT: "1.45 Sexdecillion"

Expand All @@ -17,41 +21,87 @@ format.normal(15438932589032, 'eng')
//OUTPUT: "15.44e12"
```

`format.mixed()` also has 2 inputs: `number` and `config`. <br>
`number` Is where you enter your variable. <br>
`config` Is an object, and has 3 fields. `limit`, `type1`, and `type2`. <br>
## Mixed Formatting

`format.mixed()` has four fields.
`number` Is where you enter your variable.
`config.type1` Is the type used if the number is LESS than the limit.
`config.type2` Is the type used if the number is MORE than the limit.
`config.limit` Decides the limit.

Some examples:
```
```javascript
format.mixed(1.45e51, {
limit: 1e31,
type1: 'let',
type2: 'nor'
limit: Infinity,
type1: 'nor',
type2: 'let'
})
//OUTPUT: "1.45 Sexdecillion"

format.mixed(9.82e+4, {
limit: 1.5E+3,
type1: 'let2',
type2: 'sci'
format.mixed(9.82E+4, {
limit: 5.5e4,
type1: 'let2',
type2: 'sci'
})
//OUTPUT: "9.82e4"

format.mixed(15438932589032, {
limit: 78306,
type1: "custom type",
type2: 'eng'
})
//OUTPUT: "15.44e12"
```

## Type Creation

`format.create()` has three fields.
`name` Is the name of the notation.
`notation` Is an array, containing the text displayed after the mantissa.
`type` Is either `sci` or `eng`. It decides wether or not `notation` increments every 3 exponents (`eng`), or 1 (`sci`).

After you have created your notation, you can use it with `format.normal()` & `format.mixed()`.

You can add it to your website with this: <br>
IMPORTANT: If the item in notation is undefined, " Unknown" is used instead.

Some examples:
```javascript
format.create('custom type', [
' A little',
" A lot",
' A metric ton',
' Basically Infinity' // ' Unknown' will appear if the exponent is too large
], "sci")

format.create("short-nor", [
" K",
" M",
" B",
" T",
" Q",
" q",
"I give up" // ' Unknown' will appear if the exponent is too large
], "eng")
```

## Other

### Add it to your website

You can add it to your website with this:

```
<script type='text/javascript' src='https://raw.githubusercontent.com/YhvrWasTaken/simpleformat.js/master/simpleformat.min.js'></script>
```

Or this un-minified version: <br>

Or this un-minified version:
```
<script type='text/javascript' src='https://raw.githubusercontent.com/YhvrWasTaken/simpleformat.js/master/simpleformat.js'></script>
```

And here is an entire list of format types: <br>
Or you could download it.

### Format Types

| Name | Input | Output |
|:-------------:|:-------------:|:--------------:|
Expand All @@ -60,3 +110,5 @@ And here is an entire list of format types: <br>
| Normal | `nor` | 10.00 Thousand |
| 2 Letters | `let2` | 1.00ab |
| Letters | `let` | 1.00b |

Don't forget, You can create your own types!

0 comments on commit 94c687f

Please sign in to comment.