Skip to content

Commit

Permalink
Merge branch 'master' into greenkeeper/gulp-mocha-4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jrthib committed Jun 2, 2017
2 parents 3f750f9 + 83defd2 commit 9ac2216
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 383 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false
insert_final_newline = true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
coverage
npm-debug.log
.DS_Store
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
mongoose-intl-phone-number
====================

[![Greenkeeper badge](https://badges.greenkeeper.io/Dashride/mongoose-intl-phone-number.svg)](https://greenkeeper.io/)
[![Build Status](https://travis-ci.org/Dashride/mongoose-intl-phone-number.svg?branch=master)](https://travis-ci.org/Dashride/mongoose-intl-phone-number)
[![Coverage Status](https://coveralls.io/repos/Dashride/mongoose-intl-phone-number/badge.svg?branch=master&service=github)](https://coveralls.io/github/Dashride/mongoose-intl-phone-number?branch=master)
[![Dependency Status](https://david-dm.org/Dashride/mongoose-intl-phone-number.svg)](https://david-dm.org/Dashride/mongoose-intl-phone-number)
Expand Down
57 changes: 22 additions & 35 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,27 @@
'use strict';

require('babel-core/register');
const fs = require('fs');
const gulp = require('gulp');
const gutil = require('gulp-util');
const mocha = require('gulp-mocha');
const istanbul = require('gulp-istanbul');
const jshint = require('gulp-jshint');
const jsdoc2md = require('gulp-jsdoc-to-markdown');
const concat = require('gulp-concat');
const isparta = require('isparta');

var fs = require('fs'),
gulp = require('gulp'),
gutil = require("gulp-util"),
mocha = require('gulp-mocha'),
istanbul = require('gulp-istanbul'),
jshint = require('gulp-jshint'),
jsdoc2md = require('gulp-jsdoc-to-markdown'),
concat = require("gulp-concat"),
babel = require('gulp-babel'),
isparta = require('isparta');

var paths = {
es6: {
js: ['./src-es6/**/*.js', '!./**/*.spec.js'],
specs: ['./src-es6/**/*.spec.js'],
all: ['./src-es6/**/*.js', '!./coverage/**/*.js', '!./node_modules/**/*.js']
},
const paths = {
js: ['./**/*.js', '!./**/*.spec.js', '!./coverage/**/*.js', '!./node_modules/**/*.js'],
specs: ['./**/*.spec.js'],
specs: ['./lib/*.spec.js'],
coverage: ['./lib/*.js', '!./lib/*spec.js'],
all: ['./**/*.js', '!./coverage/**/*.js', '!./node_modules/**/*.js']
};

gulp.task('watch', ['test'], function (done) {
var glob = paths.es6.all;
const glob = paths.es6.all;
return gulp.watch(glob, ['test']);
});

gulp.task('6to5', function () {
return gulp.src(paths.es6.js)
.pipe(babel())
.pipe(gulp.dest('lib'));
});

gulp.task('lint', function() {
return gulp.src(paths.all)
.pipe(jshint())
Expand All @@ -43,53 +30,53 @@ gulp.task('lint', function() {
});

gulp.task('coveralls', function(done) {
return gulp.src(paths.es6.js)
return gulp.src(paths.coverage)
.pipe(istanbul({
instrumenter: isparta.Instrumenter,
includeUntested: true
}))
.pipe(istanbul.hookRequire())
.on('finish', function() {
return gulp.src(paths.es6.specs)
return gulp.src(paths.specs)
.pipe(mocha({
reporter: 'spec'
}))
.pipe(istanbul.writeReports({
reporters: [ 'lcovonly', 'text' ],
reporters: ['lcovonly', 'text'],
}));
});
});

gulp.task('coverage', function(done) {
return gulp.src(paths.es6.js)
return gulp.src(paths.coverage)
.pipe(istanbul({
instrumenter: isparta.Instrumenter,
includeUntested: false
}))
.pipe(istanbul.hookRequire())
.on('finish', function() {
return gulp.src(paths.es6.specs)
return gulp.src(paths.specs)
.pipe(mocha({
reporter: 'spec'
}))
.pipe(istanbul.writeReports({
reporters: [ 'text', 'html' ],
reporters: ['text', 'html'],
}));
});
});

gulp.task('test', [/*'lint'*/], function(done) {
return gulp.src(paths.es6.specs)
return gulp.src(paths.specs)
.pipe(mocha({
reporter: 'spec'
}));
});

gulp.task('docs', function() {
return gulp.src(paths.es6.js)
return gulp.src(paths.js)
.pipe(concat('README.md'))
.pipe(jsdoc2md({template: fs.readFileSync('./readme.hbs', 'utf8')}))
.on('error', function(err){
.on('error', function(err) {
gutil.log('jsdoc2md failed:', err.message);
})
.pipe(gulp.dest('.'));
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
'use strict';

module.exports = require('./lib/mongoose-intl-phone-number').mongooseIntlPhoneNumber;
164 changes: 69 additions & 95 deletions lib/intl-phone-number.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,43 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.IntlPhoneNumber = undefined;
const PhoneNumberUtil = require('google-libphonenumber').PhoneNumberUtil;

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
const phoneUtil = PhoneNumberUtil.getInstance();

var _googleLibphonenumber = require('google-libphonenumber');

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var phoneUtil = _googleLibphonenumber.PhoneNumberUtil.getInstance();

var PhoneNumberFormat = {
const PhoneNumberFormat = {
E164: 0,
INTERNATIONAL: 1,
NATIONAL: 2,
RFC3966: 3
};

var PhoneNumberErrorCodes = {
// https://github.com/seegno/google-libphonenumber/blob/4a210137662fd1d4c2d9d37f54c3f6c366458985/src/phonenumberutil.js#L965
const PhoneNumberErrorCodes = {
IS_POSSIBLE: 0,
INVALID_COUNTRY_CODE: 1,
TOO_SHORT: 2,
TOO_LONG: 3
TOO_LONG: 3,
IS_POSSIBLE_LOCAL_ONLY: 4,
INVALID_LENGTH: 5,
};

var PhoneNumberErrorReasons = ['Number is unknown.', 'Country code is invalid.', 'Number is too short.', 'Number is too long.'];
const PhoneNumberErrorReasons = [
'Number is unknown.',
'Country code is invalid.',
'Number is too short.',
'Number is too long.',
'Number is an unknown local number.',
'Number length is invalid for this region.',
];

/**
* @class IntlPhoneNumber
*/

var IntlPhoneNumber = function () {
class IntlPhoneNumber {
/**
* @param {string} phoneNumber
*/

function IntlPhoneNumber(phoneNumber) {
_classCallCheck(this, IntlPhoneNumber);

constructor(phoneNumber) {
this.phoneNumber = phoneNumber;
this.number = phoneUtil.parseAndKeepRawInput(phoneNumber);
}
Expand All @@ -49,89 +46,66 @@ var IntlPhoneNumber = function () {
* Determines if the number is valid.
* @return {boolean}
*/
get isValid() {
return phoneUtil.isValidNumber(this.number) && phoneUtil.isPossibleNumber(this.number);
}

/**
* Returns the country code for the parsed number.
* @return {string}
*/
get countryCode() {
return phoneUtil.getRegionCodeForNumber(this.number);
}

_createClass(IntlPhoneNumber, [{
key: 'isValid',
get: function get() {
return phoneUtil.isValidNumber(this.number) && phoneUtil.isPossibleNumber(this.number);
}

/**
* Returns the country code for the parsed number.
* @return {string}
*/

}, {
key: 'countryCode',
get: function get() {
return phoneUtil.getRegionCodeForNumber(this.number);
}

/**
* Returns the e164 format for the parsed number.
* @return {string}
*/

}, {
key: 'e164Format',
get: function get() {
return phoneUtil.format(this.number, PhoneNumberFormat.E164);
}

/**
* Returns the national format for the parsed number.
* @return {string}
*/

}, {
key: 'nationalFormat',
get: function get() {
return phoneUtil.format(this.number, PhoneNumberFormat.NATIONAL);
}

/**
* Returns the international format for the parsed number.
* @return {string}
*/
/**
* Returns the e164 format for the parsed number.
* @return {string}
*/
get e164Format() {
return phoneUtil.format(this.number, PhoneNumberFormat.E164);
}

}, {
key: 'internationalFormat',
get: function get() {
return phoneUtil.format(this.number, PhoneNumberFormat.INTERNATIONAL);
}
/**
* Returns the national format for the parsed number.
* @return {string}
*/
get nationalFormat() {
return phoneUtil.format(this.number, PhoneNumberFormat.NATIONAL);
}

/**
* Determines the proper error message based on the error code.
* @return {string}
*/
/**
* Returns the international format for the parsed number.
* @return {string}
*/
get internationalFormat() {
return phoneUtil.format(this.number, PhoneNumberFormat.INTERNATIONAL);
}

}, {
key: 'errorMsg',
get: function get() {
var message = 'Phone number is not valid.';
/**
* Determines the proper error message based on the error code.
* @return {string}
*/
get errorMsg() {
let message = 'Phone number is not valid.';

var errorCode = this.errorCode;
var reason = PhoneNumberErrorReasons[errorCode];
const errorCode = this.errorCode;
const reason = PhoneNumberErrorReasons[errorCode];

if (reason) {
message += ' ' + reason;

return message;
}

/**
* Determines the error code for a number that was not able to be parsed.
* @return {number}
*/

}, {
key: 'errorCode',
get: function get() {
return phoneUtil.isPossibleNumberWithReason(this.number);
}
}]);
return message;
}

return IntlPhoneNumber;
}();
/**
* Determines the error code for a number that was not able to be parsed.
* @return {number}
*/
get errorCode() {
return phoneUtil.isPossibleNumberWithReason(this.number);
}
}

exports.IntlPhoneNumber = IntlPhoneNumber;
exports.IntlPhoneNumber = IntlPhoneNumber;

0 comments on commit 9ac2216

Please sign in to comment.