Skip to content

Commit d3761a4

Browse files
committed
Fix building error
1 parent df05117 commit d3761a4

File tree

12 files changed

+160
-24
lines changed

12 files changed

+160
-24
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
[![Travis](https://img.shields.io/travis/nosir/cleave.js.svg?maxAge=2592000)](https://travis-ci.org/nosir/cleave.js)
44
[![Codacy branch grade](https://img.shields.io/codacy/grade/b1c0b0da42fa418f887076a3f7352aea/master.svg?maxAge=2592000)](https://www.codacy.com/app/nosir/cleave-js)
5+
[![npm version](https://badge.fury.io/js/cleave.js.svg)](https://badge.fury.io/js/cleave.js)
56

67
Cleave.js has a simple purpose: to help you format input text content automatically.
78

89
## Features
910

1011
- Credit card number formatting
11-
- Phone number formatting (metadata pattern js separated by countries to reduce size)
12+
- Phone number formatting (i18n pattern js separated by countries to reduce size)
1213
- Date formatting
1314
- Numeral formatting
1415
- Custom delimiter, prefix and blocks pattern
@@ -37,8 +38,8 @@ npm install --save cleave.js
3738
bower install --save cleave.js
3839
```
3940

40-
#### throwback
41-
Grab the file from [dist](https://github.com/nosir/cleave.js/tree/master/dist) directory
41+
#### old school
42+
Grab file from [dist](https://github.com/nosir/cleave.js/tree/master/dist) directory
4243

4344
## Usage
4445

@@ -68,7 +69,7 @@ var cleave = new Cleave('.input-phone', {
6869

6970
More examples: [the demo page](https://github.com)
7071

71-
#### CommonJS (Node.js)
72+
#### CommonJS
7273
```js
7374
var Cleave = require('cleave.js');
7475
require('cleave.js/dist/plugin/cleave-phone.{country}');
@@ -156,6 +157,12 @@ gulp mocha && gulp eslint
156157
- [x] Mocha unit tests for formatter classes
157158
- [ ] PhantomJS / Jest browser tests
158159

160+
## Get in touch
161+
- [x] ReactJS component port
162+
- [ ] AngularJS component port
163+
- [x] Mocha unit tests for formatter classes
164+
- [ ] PhantomJS / Jest browser tests
165+
159166
## References
160167

161168
- Payment credit card number IIN https://en.wikipedia.org/wiki/Payment_card_number#Issuer_identification_number_.28IIN.29

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"form",
99
"input"
1010
],
11-
"version": "0.2.0",
11+
"version": "0.2.1",
1212
"author": {
1313
"name": "Max Huang",
1414
"email": "[email protected]",

dist/cleave-react.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cleave-react.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cleave.js

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,132 @@ if (typeof module === 'object' && typeof module.exports === 'object') {
240240

241241
'use strict';
242242

243+
var Util = {
244+
noop: function () {
245+
},
246+
247+
strip: function (value, re) {
248+
return value.replace(re, '');
249+
},
250+
251+
headStr: function (str, length) {
252+
return str.slice(0, length);
253+
},
254+
255+
getMaxLength: function (blocks) {
256+
return blocks.reduce(function (previous, current) {
257+
return previous + current;
258+
}, 0);
259+
},
260+
261+
getPrefixAppliedValue: function (value, prefix) {
262+
var prefixLength = prefix.length,
263+
prefixLengthValue;
264+
265+
if (prefixLength === 0) {
266+
return value;
267+
}
268+
269+
prefixLengthValue = value.slice(0, prefixLength);
270+
271+
if (prefixLengthValue.length < prefixLength) {
272+
value = prefix;
273+
} else if (prefixLengthValue !== prefix) {
274+
value = prefix + value.slice(prefixLength);
275+
}
276+
277+
return value;
278+
},
279+
280+
getFormattedValue: function (value, blocks, blocksLength, delimiter) {
281+
var result = '';
282+
283+
blocks.forEach(function (length, index) {
284+
if (value.length > 0) {
285+
var sub = value.slice(0, length),
286+
rest = value.slice(length);
287+
288+
result += sub;
289+
290+
if (sub.length === length && index < blocksLength - 1) {
291+
result += delimiter;
292+
}
293+
294+
// update remaining string
295+
value = rest;
296+
}
297+
});
298+
299+
return result;
300+
}
301+
};
302+
303+
if (typeof module === 'object' && typeof module.exports === 'object') {
304+
module.exports = exports = Util;
305+
}
306+
307+
'use strict';
308+
309+
/**
310+
* Props Assignment
311+
*
312+
* Separate this, so react module can share the usage
313+
*/
314+
var DefaultProperties = {
315+
// Maybe change to object-assign
316+
// for now just keep it as simple
317+
assign: function (target, opts) {
318+
target = target || {};
319+
opts = opts || {};
320+
321+
// credit card
322+
target.creditCard = !!opts.creditCard;
323+
target.creditCardStrictMode = !!opts.creditCardStrictMode;
324+
325+
// phone
326+
target.phone = !!opts.phone;
327+
target.phoneRegionCode = opts.phoneRegionCode || 'AU';
328+
target.phoneFormatter = {};
329+
330+
// date
331+
target.date = !!opts.date;
332+
target.datePattern = opts.datePattern || ['d', 'm', 'Y'];
333+
target.dateFormatter = {};
334+
335+
// numeral
336+
target.numeral = !!opts.numeral;
337+
target.numeralDecimalScale = opts.numeralDecimalScale || 2;
338+
target.numeralDecimalMark = opts.numeralDecimalMark || '.';
339+
target.numeralThousandsGroupStyle = opts.numeralThousandsGroupStyle || 'thousand';
340+
341+
// others
342+
target.initValue = opts.initValue || '';
343+
344+
target.numericOnly = target.creditCard || target.date || !!opts.numericOnly;
345+
346+
target.prefix = (target.creditCard || target.phone || target.date) ? '' : (opts.prefix || '');
347+
348+
target.delimiter = opts.delimiter || (target.date ? '/' : (target.numeral ? ',' : ' '));
349+
target.delimiterRE = new RegExp(target.delimiter, 'g');
350+
351+
target.blocks = opts.blocks || [];
352+
target.blocksLength = target.blocks.length;
353+
354+
target.maxLength = 0;
355+
356+
target.backspace = false;
357+
target.result = '';
358+
359+
return target;
360+
}
361+
};
362+
363+
if (typeof module === 'object' && typeof module.exports === 'object') {
364+
module.exports = exports = DefaultProperties;
365+
}
366+
367+
'use strict';
368+
243369
var CreditCardDetector = {
244370
blocks: {
245371
uatp: [4, 5, 6],

dist/cleave.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)