Skip to content

safer phoneNumber Helper #310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -12,6 +12,5 @@ node_js:
- '5'
- '4'
- '0.12'
before_script:
- npm install -g gulp-cli
script: gulp
allowed_failures:
node_js: '0.12'
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -2,26 +2,26 @@
environment:
matrix:
# node.js
- nodejs_version: "9.0"
- nodejs_version: "8.0"
- nodejs_version: "7.0"
- nodejs_version: "6.0"
- nodejs_version: "5.0"
- nodejs_version: "4.0"
- nodejs_version: "0.12"

# Install scripts. (runs after repo cloning)
install:
# Get the latest stable version of Node.js or io.js
- ps: Install-Product node $env:nodejs_version
# install modules
- npm install
- npm install -g gulp-cli

# Post-install test scripts.
test_script:
# Output useful info for debugging.
- node --version
- npm --version
# run tests
- gulp

# Don't actually build.
build: off
10 changes: 8 additions & 2 deletions lib/number.js
Original file line number Diff line number Diff line change
@@ -71,8 +71,14 @@ helpers.addCommas = function(num) {
* @api public
*/

helpers.phoneNumber = function(num) {
num = num.toString();
helpers.phoneNumber = function(value) {
var num = value.toString().replace(/\D+/, '');

// format only the numbers you can format.
// If it's not going to work, don't do it.
if (num === '' || num.length !== 10) {
return value;
}

return '(' + num.substr(0, 3) + ') '
+ num.substr(3, 3) + '-'