Skip to content

Commit

Permalink
refactor: reorganize helper modules
Browse files Browse the repository at this point in the history
  • Loading branch information
assisrafael committed Sep 24, 2017
1 parent 7abc08d commit 640aa7f
Show file tree
Hide file tree
Showing 27 changed files with 125 additions and 127 deletions.
2 changes: 1 addition & 1 deletion src/br/boleto-bancario/boleto-bancario.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var StringMask = require('string-mask');
var maskFactory = require('../../libs/mask-factory');
var maskFactory = require('../../helpers/mask-factory');

var boletoBancarioMask = new StringMask('00000.00000 00000.000000 00000.000000 0 00000000000000');

Expand Down
4 changes: 1 addition & 3 deletions src/br/br-masks.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

var m = angular.module('ui.utils.masks.br', [
require('../helpers'),
])
var m = angular.module('ui.utils.masks.br', [])
.directive('uiBrBoletoBancarioMask', require('./boleto-bancario/boleto-bancario'))
.directive('uiBrCarPlateMask', require('./car-plate/car-plate'))
.directive('uiBrCepMask', require('./cep/cep'))
Expand Down
2 changes: 1 addition & 1 deletion src/br/car-plate/car-plate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var StringMask = require('string-mask');
var maskFactory = require('../../libs/mask-factory');
var maskFactory = require('../../helpers/mask-factory');

var carPlateMask = new StringMask('UUU-0000');

Expand Down
2 changes: 1 addition & 1 deletion src/br/cep/cep.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var StringMask = require('string-mask');
var maskFactory = require('../../libs/mask-factory');
var maskFactory = require('../../helpers/mask-factory');

var cepMask = new StringMask('00000-000');

Expand Down
3 changes: 2 additions & 1 deletion src/br/cnpj/cnpj.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

var StringMask = require('string-mask');
var BrV = require('br-validations');
var maskFactory = require('../../libs/mask-factory');

var maskFactory = require('../../helpers/mask-factory');

var cnpjPattern = new StringMask('00.000.000\/0000-00');

Expand Down
2 changes: 1 addition & 1 deletion src/br/cpf-cnpj/cpf-cnpj.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var StringMask = require('string-mask');
var BrV = require('br-validations');
var maskFactory = require('../../libs/mask-factory');
var maskFactory = require('../../helpers/mask-factory');

var cnpjPattern = new StringMask('00.000.000\/0000-00');
var cpfPattern = new StringMask('000.000.000-00');
Expand Down
3 changes: 2 additions & 1 deletion src/br/cpf/cpf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

var StringMask = require('string-mask');
var BrV = require('br-validations');
var maskFactory = require('../../libs/mask-factory');

var maskFactory = require('../../helpers/mask-factory');

var cpfPattern = new StringMask('000.000.000-00');

Expand Down
60 changes: 30 additions & 30 deletions src/br/inscricao-estadual/ie.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@
var StringMask = require('string-mask');
var BrV = require('br-validations');

function BrIeMaskDirective($parse) {
var ieMasks = {
'AC': [{mask: new StringMask('00.000.000/000-00')}],
'AL': [{mask: new StringMask('000000000')}],
'AM': [{mask: new StringMask('00.000.000-0')}],
'AP': [{mask: new StringMask('000000000')}],
'BA': [{chars: 8, mask: new StringMask('000000-00')}, {mask: new StringMask('0000000-00')}],
'CE': [{mask: new StringMask('00000000-0')}],
'DF': [{mask: new StringMask('00000000000-00')}],
'ES': [{mask: new StringMask('00000000-0')}],
'GO': [{mask: new StringMask('00.000.000-0')}],
'MA': [{mask: new StringMask('000000000')}],
'MG': [{mask: new StringMask('000.000.000/0000')}],
'MS': [{mask: new StringMask('000000000')}],
'MT': [{mask: new StringMask('0000000000-0')}],
'PA': [{mask: new StringMask('00-000000-0')}],
'PB': [{mask: new StringMask('00000000-0')}],
'PE': [{chars: 9, mask: new StringMask('0000000-00')}, {mask: new StringMask('00.0.000.0000000-0')}],
'PI': [{mask: new StringMask('000000000')}],
'PR': [{mask: new StringMask('000.00000-00')}],
'RJ': [{mask: new StringMask('00.000.00-0')}],
'RN': [{chars: 9, mask: new StringMask('00.000.000-0')}, {mask: new StringMask('00.0.000.000-0')}],
'RO': [{mask: new StringMask('0000000000000-0')}],
'RR': [{mask: new StringMask('00000000-0')}],
'RS': [{mask: new StringMask('000/0000000')}],
'SC': [{mask: new StringMask('000.000.000')}],
'SE': [{mask: new StringMask('00000000-0')}],
'SP': [{mask: new StringMask('000.000.000.000')}, {mask: new StringMask('-00000000.0/000')}],
'TO': [{mask: new StringMask('00000000000')}]
};
var ieMasks = {
'AC': [{mask: new StringMask('00.000.000/000-00')}],
'AL': [{mask: new StringMask('000000000')}],
'AM': [{mask: new StringMask('00.000.000-0')}],
'AP': [{mask: new StringMask('000000000')}],
'BA': [{chars: 8, mask: new StringMask('000000-00')}, {mask: new StringMask('0000000-00')}],
'CE': [{mask: new StringMask('00000000-0')}],
'DF': [{mask: new StringMask('00000000000-00')}],
'ES': [{mask: new StringMask('00000000-0')}],
'GO': [{mask: new StringMask('00.000.000-0')}],
'MA': [{mask: new StringMask('000000000')}],
'MG': [{mask: new StringMask('000.000.000/0000')}],
'MS': [{mask: new StringMask('000000000')}],
'MT': [{mask: new StringMask('0000000000-0')}],
'PA': [{mask: new StringMask('00-000000-0')}],
'PB': [{mask: new StringMask('00000000-0')}],
'PE': [{chars: 9, mask: new StringMask('0000000-00')}, {mask: new StringMask('00.0.000.0000000-0')}],
'PI': [{mask: new StringMask('000000000')}],
'PR': [{mask: new StringMask('000.00000-00')}],
'RJ': [{mask: new StringMask('00.000.00-0')}],
'RN': [{chars: 9, mask: new StringMask('00.000.000-0')}, {mask: new StringMask('00.0.000.000-0')}],
'RO': [{mask: new StringMask('0000000000000-0')}],
'RR': [{mask: new StringMask('00000000-0')}],
'RS': [{mask: new StringMask('000/0000000')}],
'SC': [{mask: new StringMask('000.000.000')}],
'SE': [{mask: new StringMask('00000000-0')}],
'SP': [{mask: new StringMask('000.000.000.000')}, {mask: new StringMask('-00000000.0/000')}],
'TO': [{mask: new StringMask('00000000000')}]
};

function BrIeMaskDirective($parse) {
function clearValue(value) {
if (!value) {
return value;
Expand Down
6 changes: 3 additions & 3 deletions src/br/nfe/nfe.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

var StringMask = require('string-mask');
var maskFactory = require('../../libs/mask-factory');

var nfeAccessKeyMask = new StringMask('0000 0000 0000 0000 0000' +
' 0000 0000 0000 0000 0000 0000');
var maskFactory = require('../../helpers/mask-factory');

var nfeAccessKeyMask = new StringMask('0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000');

module.exports = maskFactory({
clearValue: function(rawValue) {
Expand Down
3 changes: 2 additions & 1 deletion src/br/phone/br-phone.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

var StringMask = require('string-mask');
var maskFactory = require('../../libs/mask-factory');

var maskFactory = require('../../helpers/mask-factory');

/**
* FIXME: all numbers will have 9 digits after 2016.
Expand Down
4 changes: 1 addition & 3 deletions src/ch/ch-masks.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

var m = angular.module('ui.utils.masks.ch', [
require('../helpers'),
])
var m = angular.module('ui.utils.masks.ch', [])
.directive('uiChPhoneNumber', require('./phone/ch-phone'));

module.exports = m.name;
3 changes: 2 additions & 1 deletion src/ch/phone/ch-phone.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

var StringMask = require('string-mask');
var maskFactory = require('../../libs/mask-factory');

var maskFactory = require('../../helpers/mask-factory');

var phoneMask = new StringMask('+00 00 000 00 00');

Expand Down
4 changes: 1 addition & 3 deletions src/fr/fr-masks.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

var m = angular.module('ui.utils.masks.fr', [
require('../helpers')
])
var m = angular.module('ui.utils.masks.fr', [])
.directive('uiFrPhoneNumber', require('./phone/fr-phone'));

module.exports = m.name;
2 changes: 1 addition & 1 deletion src/fr/phone/fr-phone.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var StringMask = require('string-mask');
var maskFactory = require('../../libs/mask-factory');
var maskFactory = require('../../helpers/mask-factory');

var phoneMaskFR = new StringMask('00 00 00 00 00');

Expand Down
2 changes: 1 addition & 1 deletion src/global/credit-card/credit-card.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var StringMask = require('string-mask');
var maskFactory = require('../../libs/mask-factory');
var maskFactory = require('../../helpers/mask-factory');

var ccSize = 16;

Expand Down
4 changes: 1 addition & 3 deletions src/global/global-masks.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

var m = angular.module('ui.utils.masks.global', [
require('../helpers'),
])
var m = angular.module('ui.utils.masks.global', [])
.directive('uiCreditCard', require('./credit-card/credit-card'))
.directive('uiDateMask', require('./date/date'))
.directive('uiMoneyMask', require('./money/money'))
Expand Down
7 changes: 4 additions & 3 deletions src/global/money/money.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';

var StringMask = require('string-mask');
var validators = require('../../libs/validators');
var validators = require('../../helpers/validators');
var PreFormatters = require('../../helpers/pre-formatters');

function MoneyMaskDirective($locale, $parse, PreFormatters) {
function MoneyMaskDirective($locale, $parse) {
return {
restrict: 'A',
require: 'ngModel',
Expand Down Expand Up @@ -160,6 +161,6 @@ function MoneyMaskDirective($locale, $parse, PreFormatters) {
}
};
}
MoneyMaskDirective.$inject = ['$locale', '$parse', 'PreFormatters'];
MoneyMaskDirective.$inject = ['$locale', '$parse'];

module.exports = MoneyMaskDirective;
8 changes: 5 additions & 3 deletions src/global/number/number.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict';

var validators = require('../../libs/validators');
var validators = require('../../helpers/validators');
var NumberMasks = require('../../helpers/number-mask-builder');
var PreFormatters = require('../../helpers/pre-formatters');

function NumberMaskDirective($locale, $parse, PreFormatters, NumberMasks) {
function NumberMaskDirective($locale, $parse) {
return {
restrict: 'A',
require: 'ngModel',
Expand Down Expand Up @@ -111,6 +113,6 @@ function NumberMaskDirective($locale, $parse, PreFormatters, NumberMasks) {
}
};
}
NumberMaskDirective.$inject = ['$locale', '$parse', 'PreFormatters', 'NumberMasks'];
NumberMaskDirective.$inject = ['$locale', '$parse'];

module.exports = NumberMaskDirective;
8 changes: 5 additions & 3 deletions src/global/percentage/percentage.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict';

var validators = require('../../libs/validators');
var validators = require('../../helpers/validators');
var NumberMasks = require('../../helpers/number-mask-builder');
var PreFormatters = require('../../helpers/pre-formatters');

function PercentageMaskDirective($locale, $parse, PreFormatters, NumberMasks) {
function PercentageMaskDirective($locale) {
function preparePercentageToFormatter(value, decimals, modelMultiplier) {
return PreFormatters.clearDelimitersAndLeadingZeros((parseFloat(value)*modelMultiplier).toFixed(decimals));
}
Expand Down Expand Up @@ -147,6 +149,6 @@ function PercentageMaskDirective($locale, $parse, PreFormatters, NumberMasks) {
}
};
}
PercentageMaskDirective.$inject = ['$locale', '$parse', 'PreFormatters', 'NumberMasks'];
PercentageMaskDirective.$inject = ['$locale'];

module.exports = PercentageMaskDirective;
1 change: 1 addition & 0 deletions src/global/time/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var StringMask = require('string-mask');

//TODO: refactor to use the mask factory
module.exports = function TimeMaskDirective() {
return {
restrict: 'A',
Expand Down
59 changes: 0 additions & 59 deletions src/helpers.js

This file was deleted.

File renamed without changes.
38 changes: 38 additions & 0 deletions src/helpers/number-mask-builder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

var StringMask = require('string-mask');

function viewMask(decimals, decimalDelimiter, thousandsDelimiter) {
var mask = '#' + thousandsDelimiter + '##0';

if (decimals > 0) {
mask += decimalDelimiter;
for (var i = 0; i < decimals; i++) {
mask += '0';
}
}

return new StringMask(mask, {
reverse: true
});
}

function modelMask(decimals) {
var mask = '###0';

if (decimals > 0) {
mask += '.';
for (var i = 0; i < decimals; i++) {
mask += '0';
}
}

return new StringMask(mask, {
reverse: true
});
}

module.exports = {
viewMask: viewMask,
modelMask: modelMask
};
Loading

0 comments on commit 640aa7f

Please sign in to comment.