Skip to content

Commit e59f5e2

Browse files
committed
Merge branch 'bezyaev-feature/postfix'
2 parents d9a881b + 3895ba9 commit e59f5e2

18 files changed

+247
-93
lines changed

dist/cleave-angular.js

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ return /******/ (function(modules) { // webpackBootstrap
155155
pps.stripLeadingZeroes,
156156
pps.prefix,
157157
pps.signBeforePrefix,
158+
pps.tailPrefix,
158159
pps.delimiter
159160
);
160161
},
@@ -332,10 +333,7 @@ return /******/ (function(modules) { // webpackBootstrap
332333
value = Util.stripDelimiters(value, pps.delimiter, pps.delimiters);
333334

334335
// strip prefix
335-
value = Util.getPrefixStrippedValue(
336-
value, pps.prefix, pps.prefixLength,
337-
pps.result, pps.delimiter, pps.delimiters, pps.noImmediatePrefix
338-
);
336+
value = Util.getPrefixStrippedValue(value, pps.prefix, pps.prefixLength, pps.result, pps.delimiter, pps.delimiters, pps.noImmediatePrefix, pps.tailPrefix);
339337

340338
// strip non-numeric characters
341339
value = pps.numericOnly ? Util.strip(value, /[^\d]/g) : value;
@@ -346,7 +344,12 @@ return /******/ (function(modules) { // webpackBootstrap
346344

347345
// prevent from showing prefix when no immediate option enabled with empty input value
348346
if (pps.prefix && (!pps.noImmediatePrefix || value.length)) {
349-
value = pps.prefix + value;
347+
if (pps.tailPrefix) {
348+
value = value + pps.prefix;
349+
} else {
350+
value = pps.prefix + value;
351+
}
352+
350353

351354
// no blocks specified, no need to do formatting
352355
if (pps.blocksLength === 0) {
@@ -474,7 +477,7 @@ return /******/ (function(modules) { // webpackBootstrap
474477
rawValue = owner.element.value;
475478

476479
if (pps.rawValueTrimPrefix) {
477-
rawValue = Util.getPrefixStrippedValue(rawValue, pps.prefix, pps.prefixLength, pps.result, pps.delimiter, pps.delimiters);
480+
rawValue = Util.getPrefixStrippedValue(rawValue, pps.prefix, pps.prefixLength, pps.result, pps.delimiter, pps.delimiters, pps.noImmediatePrefix, pps.tailPrefix);
478481
}
479482

480483
if (pps.numeral) {
@@ -606,6 +609,7 @@ return /******/ (function(modules) { // webpackBootstrap
606609
stripLeadingZeroes,
607610
prefix,
608611
signBeforePrefix,
612+
tailPrefix,
609613
delimiter) {
610614
var owner = this;
611615

@@ -617,6 +621,7 @@ return /******/ (function(modules) { // webpackBootstrap
617621
owner.stripLeadingZeroes = stripLeadingZeroes !== false;
618622
owner.prefix = (prefix || prefix === '') ? prefix : '';
619623
owner.signBeforePrefix = !!signBeforePrefix;
624+
owner.tailPrefix = !!tailPrefix;
620625
owner.delimiter = (delimiter || delimiter === '') ? delimiter : ',';
621626
owner.delimiterRE = delimiter ? new RegExp('\\' + delimiter, 'g') : '';
622627
};
@@ -706,6 +711,10 @@ return /******/ (function(modules) { // webpackBootstrap
706711
break;
707712
}
708713

714+
if (owner.tailPrefix) {
715+
return partSign + partInteger.toString() + (owner.numeralDecimalScale > 0 ? partDecimal.toString() : '') + owner.prefix;
716+
}
717+
709718
return partSignAndPrefix + partInteger.toString() + (owner.numeralDecimalScale > 0 ? partDecimal.toString() : '');
710719
}
711720
};
@@ -1408,30 +1417,35 @@ return /******/ (function(modules) { // webpackBootstrap
14081417
// PREFIX-123 | PEFIX-123 | 123
14091418
// PREFIX-123 | PREFIX-23 | 23
14101419
// PREFIX-123 | PREFIX-1234 | 1234
1411-
getPrefixStrippedValue: function (value, prefix, prefixLength, prevResult, delimiter, delimiters, noImmediatePrefix) {
1420+
getPrefixStrippedValue: function (value, prefix, prefixLength, prevResult, delimiter, delimiters, noImmediatePrefix, tailPrefix) {
14121421
// No prefix
14131422
if (prefixLength === 0) {
14141423
return value;
14151424
}
14161425

14171426
// Pre result prefix string does not match pre-defined prefix
1418-
if (prevResult.slice(0, prefixLength) !== prefix) {
1419-
// Check if the first time user entered something
1420-
if (noImmediatePrefix && !prevResult && value) return value;
1421-
1422-
return '';
1427+
if (prevResult.slice(0, prefixLength) !== prefix && !tailPrefix) {
1428+
// Check if the first time user entered something
1429+
if (noImmediatePrefix && !prevResult && value) return value;
1430+
return '';
1431+
} else if (prevResult.slice(-prefixLength) !== prefix && tailPrefix) {
1432+
// Check if the first time user entered something
1433+
if (noImmediatePrefix && !prevResult && value) return value;
1434+
return '';
14231435
}
14241436

14251437
var prevValue = this.stripDelimiters(prevResult, delimiter, delimiters);
14261438

14271439
// New value has issue, someone typed in between prefix letters
14281440
// Revert to pre value
1429-
if (value.slice(0, prefixLength) !== prefix) {
1430-
return prevValue.slice(prefixLength);
1441+
if (value.slice(0, prefixLength) !== prefix && !tailPrefix) {
1442+
return prevValue.slice(prefixLength);
1443+
} else if (value.slice(-prefixLength) !== prefix && tailPrefix) {
1444+
return prevValue.slice(0, -prefixLength - 1);
14311445
}
14321446

14331447
// No issue, strip prefix for new value
1434-
return value.slice(prefixLength);
1448+
return tailPrefix ? value.slice(0, -prefixLength) : value.slice(prefixLength);
14351449
},
14361450

14371451
getFirstDiffIndex: function (prev, current) {
@@ -1627,6 +1641,7 @@ return /******/ (function(modules) { // webpackBootstrap
16271641
target.numeralPositiveOnly = !!opts.numeralPositiveOnly;
16281642
target.stripLeadingZeroes = opts.stripLeadingZeroes !== false;
16291643
target.signBeforePrefix = !!opts.signBeforePrefix;
1644+
target.tailPrefix = !!opts.tailPrefix;
16301645

16311646
// others
16321647
target.numericOnly = target.creditCard || target.date || !!opts.numericOnly;

dist/cleave-angular.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cleave-esm.js

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var NumeralFormatter = function (numeralDecimalMark,
88
stripLeadingZeroes,
99
prefix,
1010
signBeforePrefix,
11+
tailPrefix,
1112
delimiter) {
1213
var owner = this;
1314

@@ -19,6 +20,7 @@ var NumeralFormatter = function (numeralDecimalMark,
1920
owner.stripLeadingZeroes = stripLeadingZeroes !== false;
2021
owner.prefix = (prefix || prefix === '') ? prefix : '';
2122
owner.signBeforePrefix = !!signBeforePrefix;
23+
owner.tailPrefix = !!tailPrefix;
2224
owner.delimiter = (delimiter || delimiter === '') ? delimiter : ',';
2325
owner.delimiterRE = delimiter ? new RegExp('\\' + delimiter, 'g') : '';
2426
};
@@ -108,6 +110,10 @@ NumeralFormatter.prototype = {
108110
break;
109111
}
110112

113+
if (owner.tailPrefix) {
114+
return partSign + partInteger.toString() + (owner.numeralDecimalScale > 0 ? partDecimal.toString() : '') + owner.prefix;
115+
}
116+
111117
return partSignAndPrefix + partInteger.toString() + (owner.numeralDecimalScale > 0 ? partDecimal.toString() : '');
112118
}
113119
};
@@ -775,30 +781,35 @@ var Util = {
775781
// PREFIX-123 | PEFIX-123 | 123
776782
// PREFIX-123 | PREFIX-23 | 23
777783
// PREFIX-123 | PREFIX-1234 | 1234
778-
getPrefixStrippedValue: function (value, prefix, prefixLength, prevResult, delimiter, delimiters, noImmediatePrefix) {
784+
getPrefixStrippedValue: function (value, prefix, prefixLength, prevResult, delimiter, delimiters, noImmediatePrefix, tailPrefix) {
779785
// No prefix
780786
if (prefixLength === 0) {
781787
return value;
782788
}
783789

784790
// Pre result prefix string does not match pre-defined prefix
785-
if (prevResult.slice(0, prefixLength) !== prefix) {
786-
// Check if the first time user entered something
787-
if (noImmediatePrefix && !prevResult && value) return value;
788-
789-
return '';
791+
if (prevResult.slice(0, prefixLength) !== prefix && !tailPrefix) {
792+
// Check if the first time user entered something
793+
if (noImmediatePrefix && !prevResult && value) return value;
794+
return '';
795+
} else if (prevResult.slice(-prefixLength) !== prefix && tailPrefix) {
796+
// Check if the first time user entered something
797+
if (noImmediatePrefix && !prevResult && value) return value;
798+
return '';
790799
}
791800

792801
var prevValue = this.stripDelimiters(prevResult, delimiter, delimiters);
793802

794803
// New value has issue, someone typed in between prefix letters
795804
// Revert to pre value
796-
if (value.slice(0, prefixLength) !== prefix) {
797-
return prevValue.slice(prefixLength);
805+
if (value.slice(0, prefixLength) !== prefix && !tailPrefix) {
806+
return prevValue.slice(prefixLength);
807+
} else if (value.slice(-prefixLength) !== prefix && tailPrefix) {
808+
return prevValue.slice(0, -prefixLength - 1);
798809
}
799810

800811
// No issue, strip prefix for new value
801-
return value.slice(prefixLength);
812+
return tailPrefix ? value.slice(0, -prefixLength) : value.slice(prefixLength);
802813
},
803814

804815
getFirstDiffIndex: function (prev, current) {
@@ -987,6 +998,7 @@ var DefaultProperties = {
987998
target.numeralPositiveOnly = !!opts.numeralPositiveOnly;
988999
target.stripLeadingZeroes = opts.stripLeadingZeroes !== false;
9891000
target.signBeforePrefix = !!opts.signBeforePrefix;
1001+
target.tailPrefix = !!opts.tailPrefix;
9901002

9911003
// others
9921004
target.numericOnly = target.creditCard || target.date || !!opts.numericOnly;
@@ -1131,6 +1143,7 @@ Cleave.prototype = {
11311143
pps.stripLeadingZeroes,
11321144
pps.prefix,
11331145
pps.signBeforePrefix,
1146+
pps.tailPrefix,
11341147
pps.delimiter
11351148
);
11361149
},
@@ -1308,10 +1321,7 @@ Cleave.prototype = {
13081321
value = Util.stripDelimiters(value, pps.delimiter, pps.delimiters);
13091322

13101323
// strip prefix
1311-
value = Util.getPrefixStrippedValue(
1312-
value, pps.prefix, pps.prefixLength,
1313-
pps.result, pps.delimiter, pps.delimiters, pps.noImmediatePrefix
1314-
);
1324+
value = Util.getPrefixStrippedValue(value, pps.prefix, pps.prefixLength, pps.result, pps.delimiter, pps.delimiters, pps.noImmediatePrefix, pps.tailPrefix);
13151325

13161326
// strip non-numeric characters
13171327
value = pps.numericOnly ? Util.strip(value, /[^\d]/g) : value;
@@ -1322,7 +1332,12 @@ Cleave.prototype = {
13221332

13231333
// prevent from showing prefix when no immediate option enabled with empty input value
13241334
if (pps.prefix && (!pps.noImmediatePrefix || value.length)) {
1325-
value = pps.prefix + value;
1335+
if (pps.tailPrefix) {
1336+
value = value + pps.prefix;
1337+
} else {
1338+
value = pps.prefix + value;
1339+
}
1340+
13261341

13271342
// no blocks specified, no need to do formatting
13281343
if (pps.blocksLength === 0) {
@@ -1450,7 +1465,7 @@ Cleave.prototype = {
14501465
rawValue = owner.element.value;
14511466

14521467
if (pps.rawValueTrimPrefix) {
1453-
rawValue = Util.getPrefixStrippedValue(rawValue, pps.prefix, pps.prefixLength, pps.result, pps.delimiter, pps.delimiters);
1468+
rawValue = Util.getPrefixStrippedValue(rawValue, pps.prefix, pps.prefixLength, pps.result, pps.delimiter, pps.delimiters, pps.noImmediatePrefix, pps.tailPrefix);
14541469
}
14551470

14561471
if (pps.numeral) {

dist/cleave-esm.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cleave-react-node.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ return /******/ (function(modules) { // webpackBootstrap
192192
return;
193193
}
194194

195-
pps.numeralFormatter = new NumeralFormatter(pps.numeralDecimalMark, pps.numeralIntegerScale, pps.numeralDecimalScale, pps.numeralThousandsGroupStyle, pps.numeralPositiveOnly, pps.stripLeadingZeroes, pps.prefix, pps.signBeforePrefix, pps.delimiter);
195+
pps.numeralFormatter = new NumeralFormatter(pps.numeralDecimalMark, pps.numeralIntegerScale, pps.numeralDecimalScale, pps.numeralThousandsGroupStyle, pps.numeralPositiveOnly, pps.stripLeadingZeroes, pps.prefix, pps.signBeforePrefix, pps.tailPrefix, pps.delimiter);
196196
},
197197

198198
initTimeFormatter: function initTimeFormatter() {
@@ -268,7 +268,7 @@ return /******/ (function(modules) { // webpackBootstrap
268268
rawValue = pps.result;
269269

270270
if (pps.rawValueTrimPrefix) {
271-
rawValue = Util.getPrefixStrippedValue(rawValue, pps.prefix, pps.prefixLength, pps.result, pps.delimiter, pps.delimiters);
271+
rawValue = Util.getPrefixStrippedValue(rawValue, pps.prefix, pps.prefixLength, pps.result, pps.delimiter, pps.delimiters, pps.noImmediatePrefix, pps.tailPrefix);
272272
}
273273

274274
if (pps.numeral) {
@@ -408,7 +408,7 @@ return /******/ (function(modules) { // webpackBootstrap
408408
value = Util.stripDelimiters(value, pps.delimiter, pps.delimiters);
409409

410410
// strip prefix
411-
value = Util.getPrefixStrippedValue(value, pps.prefix, pps.prefixLength, pps.result, pps.delimiter, pps.delimiters, pps.noImmediatePrefix);
411+
value = Util.getPrefixStrippedValue(value, pps.prefix, pps.prefixLength, pps.result, pps.delimiter, pps.delimiters, pps.noImmediatePrefix, pps.tailPrefix);
412412

413413
// strip non-numeric characters
414414
value = pps.numericOnly ? Util.strip(value, /[^\d]/g) : value;
@@ -419,7 +419,11 @@ return /******/ (function(modules) { // webpackBootstrap
419419

420420
// prevent from showing prefix when no immediate option enabled with empty input value
421421
if (pps.prefix && (!pps.noImmediatePrefix || value.length)) {
422-
value = pps.prefix + value;
422+
if (pps.tailPrefix) {
423+
value = value + pps.prefix;
424+
} else {
425+
value = pps.prefix + value;
426+
}
423427

424428
// no blocks specified, no need to do formatting
425429
if (pps.blocksLength === 0) {
@@ -1795,7 +1799,7 @@ return /******/ (function(modules) { // webpackBootstrap
17951799

17961800
'use strict';
17971801

1798-
var NumeralFormatter = function NumeralFormatter(numeralDecimalMark, numeralIntegerScale, numeralDecimalScale, numeralThousandsGroupStyle, numeralPositiveOnly, stripLeadingZeroes, prefix, signBeforePrefix, delimiter) {
1802+
var NumeralFormatter = function NumeralFormatter(numeralDecimalMark, numeralIntegerScale, numeralDecimalScale, numeralThousandsGroupStyle, numeralPositiveOnly, stripLeadingZeroes, prefix, signBeforePrefix, tailPrefix, delimiter) {
17991803
var owner = this;
18001804

18011805
owner.numeralDecimalMark = numeralDecimalMark || '.';
@@ -1806,6 +1810,7 @@ return /******/ (function(modules) { // webpackBootstrap
18061810
owner.stripLeadingZeroes = stripLeadingZeroes !== false;
18071811
owner.prefix = prefix || prefix === '' ? prefix : '';
18081812
owner.signBeforePrefix = !!signBeforePrefix;
1813+
owner.tailPrefix = !!tailPrefix;
18091814
owner.delimiter = delimiter || delimiter === '' ? delimiter : ',';
18101815
owner.delimiterRE = delimiter ? new RegExp('\\' + delimiter, 'g') : '';
18111816
};
@@ -1900,6 +1905,10 @@ return /******/ (function(modules) { // webpackBootstrap
19001905
break;
19011906
}
19021907

1908+
if (owner.tailPrefix) {
1909+
return partSign + partInteger.toString() + (owner.numeralDecimalScale > 0 ? partDecimal.toString() : '') + owner.prefix;
1910+
}
1911+
19031912
return partSignAndPrefix + partInteger.toString() + (owner.numeralDecimalScale > 0 ? partDecimal.toString() : '');
19041913
}
19051914
};
@@ -2596,30 +2605,35 @@ return /******/ (function(modules) { // webpackBootstrap
25962605
// PREFIX-123 | PEFIX-123 | 123
25972606
// PREFIX-123 | PREFIX-23 | 23
25982607
// PREFIX-123 | PREFIX-1234 | 1234
2599-
getPrefixStrippedValue: function getPrefixStrippedValue(value, prefix, prefixLength, prevResult, delimiter, delimiters, noImmediatePrefix) {
2608+
getPrefixStrippedValue: function getPrefixStrippedValue(value, prefix, prefixLength, prevResult, delimiter, delimiters, noImmediatePrefix, tailPrefix) {
26002609
// No prefix
26012610
if (prefixLength === 0) {
26022611
return value;
26032612
}
26042613

26052614
// Pre result prefix string does not match pre-defined prefix
2606-
if (prevResult.slice(0, prefixLength) !== prefix) {
2615+
if (prevResult.slice(0, prefixLength) !== prefix && !tailPrefix) {
2616+
// Check if the first time user entered something
2617+
if (noImmediatePrefix && !prevResult && value) return value;
2618+
return '';
2619+
} else if (prevResult.slice(-prefixLength) !== prefix && tailPrefix) {
26072620
// Check if the first time user entered something
26082621
if (noImmediatePrefix && !prevResult && value) return value;
2609-
26102622
return '';
26112623
}
26122624

26132625
var prevValue = this.stripDelimiters(prevResult, delimiter, delimiters);
26142626

26152627
// New value has issue, someone typed in between prefix letters
26162628
// Revert to pre value
2617-
if (value.slice(0, prefixLength) !== prefix) {
2629+
if (value.slice(0, prefixLength) !== prefix && !tailPrefix) {
26182630
return prevValue.slice(prefixLength);
2631+
} else if (value.slice(-prefixLength) !== prefix && tailPrefix) {
2632+
return prevValue.slice(0, -prefixLength - 1);
26192633
}
26202634

26212635
// No issue, strip prefix for new value
2622-
return value.slice(prefixLength);
2636+
return tailPrefix ? value.slice(0, -prefixLength) : value.slice(prefixLength);
26232637
},
26242638

26252639
getFirstDiffIndex: function getFirstDiffIndex(prev, current) {
@@ -2817,6 +2831,7 @@ return /******/ (function(modules) { // webpackBootstrap
28172831
target.numeralPositiveOnly = !!opts.numeralPositiveOnly;
28182832
target.stripLeadingZeroes = opts.stripLeadingZeroes !== false;
28192833
target.signBeforePrefix = !!opts.signBeforePrefix;
2834+
target.tailPrefix = !!opts.tailPrefix;
28202835

28212836
// others
28222837
target.numericOnly = target.creditCard || target.date || !!opts.numericOnly;

dist/cleave-react-node.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)