https://github.com/bcherny/format-as-currency
Angular directive to format an input as a currency as the user types
https://github.com/bcherny/format-as-currency
Last synced: 6 months ago
JSON representation
Angular directive to format an input as a currency as the user types
- Host: GitHub
- URL: https://github.com/bcherny/format-as-currency
- Owner: bcherny
- License: other
- Created: 2015-02-28T21:33:42.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-05-26T01:09:12.000Z (over 8 years ago)
- Last Synced: 2025-04-16T13:35:54.476Z (6 months ago)
- Language: JavaScript
- Homepage: http://bcherny.github.io/format-as-currency/demo
- Size: 35.2 KB
- Stars: 32
- Watchers: 3
- Forks: 23
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# format-as-currency
[![Build Status][build]](https://circleci.com/gh/bcherny/format-as-currency) [![Coverage Status][coverage]](https://coveralls.io/r/bcherny/format-as-currency) ![][bower] [![npm]](https://www.npmjs.com/package/format-as-currency) [![cc0]](http://creativecommons.org/about/cc0)
[build]: https://img.shields.io/circleci/project/bcherny/format-as-currency.svg?branch=master&style=flat-square
[coverage]: http://img.shields.io/coveralls/bcherny/format-as-currency.svg?branch=master&style=flat-square
[bower]: https://img.shields.io/bower/v/format-as-currency.svg?style=flat-square
[npm]: https://img.shields.io/npm/v/format-as-currency.svg?style=flat-square
[cc0]: https://img.shields.io/npm/l/format-as-currency.svg?style=flat-squareAngular directive to format an input as a currency as the user types. Like [autoNumeric](https://github.com/BobKnothe/autoNumeric) for Angular.
## Demo
http://bcherny.github.io/format-as-currency/demo
## Installation
Install via bower or NPM:
- Bower: `bower install --save format-as-currency`
- NPM: `npm install --save format-as-currency`## Usage
```html
angular
.module('myModule', [
'bcherny/formatAsCurrency'
])
.controller('myController', function ($scope) {
$scope.value = '' // currency input value
})```
### With a custom currency symbol
```html
angular
...
.filter('yuan', function ($filter) {
return function (value) {
return $filter('currency')(value, '¥')
}
})```
### With a custom currency formatter
```html
angular
...
.filter('myFilter', function () {
return function (value) {
return '¥' + value
}
})```
### With a module loader
#### Browserify
```js
var formatAsCurrency = require('format-as-currency')
angular.module('myModule', [formatAsCurrency])
```#### Rollup
```js
import * as formatAsCurrency from 'format-as-currency'
angular.module('myModule', [formatAsCurrency])
```#### Webpack
```js
var formatAsCurrency = require('format-as-currency/src/format-as-currency')
angular.module('myModule', [formatAsCurrency])
```## Running the tests
```sh
npm test
```## Contributing
Contributions are welcome! Please be sure to:
- File an issue for the problem that your PR addresses
- Test your fix thoroughly
- Follow the existing code style
- Add unit tests to cover your feature, or to prevent future regressions