Skip to content

Commit

Permalink
Change plugin to addon
Browse files Browse the repository at this point in the history
  • Loading branch information
nosir committed Jul 7, 2016
1 parent 5290235 commit a9e4f98
Show file tree
Hide file tree
Showing 503 changed files with 103 additions and 81 deletions.
4 changes: 2 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
src/build/**/*.js
src/plugin/**/*.js
test/plugin/**/*.js
src/addons/**/*.js
test/addons/**/*.js
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ Cleave.js has a simple purpose: to help you format input text content automatica
## Features

- Credit card number formatting
- Phone number formatting (i18n pattern js separated by countries to reduce size)
- Phone number formatting (i18n js lib separated by country to reduce size)
- Date formatting
- Numeral formatting
- Custom delimiter, prefix and blocks pattern
- CommonJS / AMD mode
- ReactJS component port

**TL;DR** [the demo page]()
**TL;DR** [the demo page](https://nosir.github.io/cleave.js)

## Why?

The idea is to provide an easy way to increase readability when you are typing. By using the library, you won't need to write any mind-blowing regular expressions or mask patterns to format input text.
The idea is to provide an easy way to increase input field readability by formatting your typed data. By using this library, you won't need to write any mind-blowing regular expressions or mask patterns to format input text.

However, this isn't meant to replace any validation or mask library, you should still sanitize and validate your data in backend.

Expand Down Expand Up @@ -50,7 +50,7 @@ Simply include
<script src="cleave-phone.{country}.js"></script>
```

> `cleave-phone.js` plugin is only required when phone shortcut mode is enabled. See more in documentation: [phone lib plugin](https://github.com/nosir/cleave.js/blob/master/doc/phone-lib-plugin.md) section
> `cleave-phone.{country}.js` addon is only required when phone shortcut mode is enabled. See more in documentation: [phone lib addon](https://github.com/nosir/cleave.js/blob/master/doc/phone-lib-addon.md) section
Then have a text field

Expand All @@ -67,20 +67,20 @@ var cleave = new Cleave('.input-phone', {
});
```

More examples: [the demo page](https://github.com)
More examples: [the demo page](https://nosir.github.io/cleave.js)

#### CommonJS
```js
var Cleave = require('cleave.js');
require('cleave.js/dist/plugin/cleave-phone.{country}');
require('cleave.js/dist/addons/cleave-phone.{country}');

var cleave = new Cleave(...)
```

#### AMD

```js
require(['cleave.js/dist/cleave.min', 'cleave.js/dist/plugin/cleave-phone.{country}'], function (Cleave) {
require(['cleave.js/dist/cleave.min', 'cleave.js/dist/addons/cleave-phone.{country}'], function (Cleave) {
var cleave = new Cleave(...)
});
```
Expand Down Expand Up @@ -130,7 +130,7 @@ See more in documentation: [ReactJS component usage](https://github.com/nosir/cl
- [Constructor](https://github.com/nosir/cleave.js/blob/master/doc/constructor.md)
- [Options](https://github.com/nosir/cleave.js/blob/master/doc/options.md)
- [Public methods](https://github.com/nosir/cleave.js/blob/master/doc/public-methods.md)
- [Phone lib plugin](https://github.com/nosir/cleave.js/blob/master/doc/phone-lib-plugin.md)
- [Phone lib addon](https://github.com/nosir/cleave.js/blob/master/doc/phone-lib-addon.md)
- [ReactJS component usage](https://github.com/nosir/cleave.js/blob/master/doc/reactjs-component-usage.md)

## Building & Running tests
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions doc/constructor.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Documentation
# Cleave.js Documentation

[Cleave.js](https://github.com/nosir/cleave.js#documentation) > [JavaScript API](https://github.com/nosir/cleave.js/blob/master/doc/js-api.md) > Constructor
[Documentation](https://github.com/nosir/cleave.js/blob/master/doc/doc.md) > [JavaScript API](https://github.com/nosir/cleave.js/blob/master/doc/js-api.md) > Constructor

## Constructor

Expand Down
8 changes: 8 additions & 0 deletions doc/doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Cleave.js Documentation

- [JavaScript API](https://github.com/nosir/cleave.js/blob/master/doc/js-api.md)
- [Constructor](https://github.com/nosir/cleave.js/blob/master/doc/constructor.md)
- [Options](https://github.com/nosir/cleave.js/blob/master/doc/options.md)
- [Public methods](https://github.com/nosir/cleave.js/blob/master/doc/public-methods.md)
- [Phone lib addon](https://github.com/nosir/cleave.js/blob/master/doc/phone-lib-addon.md)
- [ReactJS component usage](https://github.com/nosir/cleave.js/blob/master/doc/reactjs-component-usage.md)
4 changes: 2 additions & 2 deletions doc/js-api.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Documentation
# Cleave.js Documentation

[Cleave.js](https://github.com/nosir/cleave.js#documentation) > JavaScript API
[Documentation](https://github.com/nosir/cleave.js/blob/master/doc/doc.md) > JavaScript API

- [Constructor](https://github.com/nosir/cleave.js/blob/master/doc/constructor.md)
- [Options](https://github.com/nosir/cleave.js/blob/master/doc/options.md)
Expand Down
6 changes: 3 additions & 3 deletions doc/options.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Documentation
# Cleave.js Documentation

[Cleave.js](https://github.com/nosir/cleave.js#documentation) > [JavaScript API](https://github.com/nosir/cleave.js/blob/master/doc/js-api.md) > Options
[Documentation](https://github.com/nosir/cleave.js/blob/master/doc/doc.md) > [JavaScript API](https://github.com/nosir/cleave.js/blob/master/doc/js-api.md) > Options

- Credit card numbers:
- [creditCard](#creditcard)
Expand Down Expand Up @@ -60,7 +60,7 @@ This phone mode has to be used together with `phoneRegionCode` below.

A `String` value indicates the country region code for phone number formatting.

You can find country code in [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) list.
You can find your country code in [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) list.

**Default value**: `AU`

Expand Down
62 changes: 62 additions & 0 deletions doc/phone-lib-addon.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Cleave.js Documentation

[Documentation](https://github.com/nosir/cleave.js/blob/master/doc/doc.md) > Phone lib addon

## Why separate phone lib as an addon

Phone lib uses `AsYouTypeFormatter` from google [libphonenumber](https://github.com/googlei18n/libphonenumber/) to format phone numbers.

Since the original lib includes patterns for all the countries, the file size is relatively large (gzipped 50K). In order to reduce the size, Cleave.js helped you separate the module based on countries, so that you can include any of them as an extension (gzipped 5KB each).

## How to include phone lib addon

Under `dist/addons` directory, you can find:

- Individual `cleave-phone.{country}.js` for each country

e.g. `cleave-phone.au.js` for `AU` Australia.

- i18n all-in-one `cleave-phone.i18n.js` but with large size

> You can find your country code in [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) list.
### Simply HTML include

```html
<script src="cleave.min.js"></script>
<script src="cleave-phone.{country}.js"></script>

<script>var cleave = new Cleave(...)</script>
```

### CommonJS

```javascript
var Cleave = require('cleave.js');
require('cleave.js/dist/addons/cleave-phone.{country}');

var cleave = new Cleave(...)
```

### AMD

```javascript
require(['dist/cleave.min', 'dist/addons/cleave-phone.{country}'], function (Cleave) {
var cleave = new Cleave(...)
});
```

## Customize building

Sometimes you might want to use phone lib addon for multiple counties. In order to do so, you **shouldn't** include the lib one by one like:

```html
<script src="cleave-phone.ca.js"></script>
<script src="cleave-phone.us.js"></script>
```

Instead, you will need to build your owner country combination lib like `(US & CA).js`

To build it by yourself, please see [here](https://github.com/nosir/libphonenumber-country-metadata#build-phone-type-formatterjs-for-cleavejs)

Alternatively, just create an issue [here](https://github.com/nosir/cleave.js/issues), specify which ones you would like to build in.
48 changes: 0 additions & 48 deletions doc/phone-lib-plugin.md

This file was deleted.

6 changes: 3 additions & 3 deletions doc/public-methods.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Documentation
# Cleave.js Documentation

[Cleave.js](https://github.com/nosir/cleave.js#documentation) > [JavaScript API](https://github.com/nosir/cleave.js/blob/master/doc/js-api.md) > Public methods
[Documentation](https://github.com/nosir/cleave.js/blob/master/doc/doc.md) > [JavaScript API](https://github.com/nosir/cleave.js/blob/master/doc/js-api.md) > Public methods

- [getRawValue](#getrawvalue)
- [setRawValue](#setrawvaluevalue)
Expand Down Expand Up @@ -46,5 +46,5 @@ Sets / Changes country region code.

You will only need to call this when dealing with country switching for a phone input field.

e.g. user selected a different country option via a form `<select>`, which triggered the country change. See more in documentation [phone lib plugin](https://github.com/nosir/cleave.js/blob/master/doc/phone-lib-plugin.md) section.
e.g. user selected a different country option via a form `<select>`, which triggered the country change. See more in documentation [phone lib addon](https://github.com/nosir/cleave.js/blob/master/doc/phone-lib-addon.md) section.

10 changes: 5 additions & 5 deletions doc/reactjs-component-usage.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Documentation
# Cleave.js Documentation

[Cleave.js](https://github.com/nosir/cleave.js#documentation) > ReactJS component usage
[Documentation](https://github.com/nosir/cleave.js/blob/master/doc/doc.md) > ReactJS component usage

## Usage

Expand Down Expand Up @@ -33,7 +33,7 @@ import React from 'react';
import ReactDOM from 'react-dom';

import Cleave from 'cleave.js/react';
import CleavePhone from 'cleave.js/dist/plugin/cleave-phone.{country}';
import CleavePhone from 'cleave.js/dist/addons/cleave-phone.{country}';
```

And define the component:
Expand Down Expand Up @@ -95,7 +95,7 @@ If your project doesn't support ES6 compiling, just include cleave.js like this.
var React = require('...');

require('cleave.js/dist/cleave-react');
require('cleave.js/dist/plugin/cleave-phone.{country}.js');
require('cleave.js/dist/addons/cleave-phone.{country}.js');
```

And define the component:
Expand Down Expand Up @@ -129,7 +129,7 @@ Alternatively you can shim `Cleave.js` module. In your html:
<script src="react-dom/dist/react-dom.min.js"></script>

<script src="cleave.js/dist/cleave-react.min.js"></script>
<script src="cleave.js/dist/plugin/cleave-phone.{country}.js"></script>
<script src="cleave.js/dist/addons/cleave-phone.{country}.js"></script>
```

The global expose name is `Cleave`
Expand Down
14 changes: 7 additions & 7 deletions gulp-tasks/plugin.js → gulp-tasks/addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ var gulpsync = require('gulp-sync')(gulp);

var paths = {
src: './src',
plugin: 'plugin',
addons: 'addons',
dist: './dist'
};

gulp.task('plugin:clean', function () {
gulp.task('addon:clean', function () {
return gulp.src([
path.join(paths.dist, paths.plugin, '*.js')
path.join(paths.dist, paths.addons, '*.js')
])
.pipe(rimraf());
});

gulp.task('plugin:build', function () {
return gulp.src(path.join(paths.src, paths.plugin, '*.js'))
gulp.task('addon:build', function () {
return gulp.src(path.join(paths.src, paths.addons, '*.js'))
.pipe(rename(function (path) {
path.basename = path.basename.replace('phone-type-formatter', 'cleave-phone');
}))
.pipe(uglify({
preserveComments: 'all'
}))
.pipe(gulp.dest(path.join(paths.dist, paths.plugin)));
.pipe(gulp.dest(path.join(paths.dist, paths.addons)));
});

gulp.task('plugin', gulpsync.sync(['plugin:clean', 'plugin:build']));
gulp.task('addon', gulpsync.sync(['addon:clean', 'addon:build']));
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit a9e4f98

Please sign in to comment.