https://github.com/bfontaine/shortjs
Shorten numbers
https://github.com/bfontaine/shortjs
js library
Last synced: 9 months ago
JSON representation
Shorten numbers
- Host: GitHub
- URL: https://github.com/bfontaine/shortjs
- Owner: bfontaine
- License: mit
- Created: 2015-04-06T20:40:05.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-05-04T16:03:31.000Z (about 11 years ago)
- Last Synced: 2025-03-23T23:43:41.824Z (over 1 year ago)
- Topics: js, library
- Language: JavaScript
- Homepage:
- Size: 141 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Short.js
**Short.js** is a small library that shortens text in JS, and that’s all. It
currently only support numbers.
## Usage
Note: this is an alpha release, there’re no unit tests and it's only partially
hand-tested for now. I just wanted a small lib for something I coded quite a
few times in different projects.
### VanillaJS
Include `short.js`, then use it:
```js
console.log(short("foo bar")) // => "foo bar"
console.log(short("42")) // => "42"
console.log(short("42452")) // => "42.1k"
console.log(short("721452")) // => "0.7M"
console.log(short("1000721452")) // => "1.0G"
```
### Angular
Include `bfn-short.js` after Angular then add it in your app:
```js
angular.module("yourApp", ["bfn.short"]).
controller("foo", function() {
// ...
});
```
The module exposes only one filter:
```html
{{ thenumber | short }}
```
### jQuery
Include `jquery.short.js` after jQuery then use it:
```js
// replace the text of all elements of class 'myselector' using short.js
$(".myselector").short();
```