Skip to content

Commit

Permalink
fix(filter): remove unsupported Vue.filter (#81)
Browse files Browse the repository at this point in the history
Vue 3 doesn't support Vue.filter anymore but we can use the masker directly instead.

closes #44
  • Loading branch information
Robo-Rin committed Jul 12, 2023
1 parent 14dd001 commit 2fe4afd
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 28 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ yarn add vue-input-facade@beta

### Globally

Installs the component, directive and filter for your entire application.
Installs the component and directive for your entire application.

```javascript
import InputFacade from 'vue-input-facade'
Expand All @@ -45,12 +45,14 @@ app.use(InputFacade)
Install per component as needed

```javascript
import { InputFacade, facade, filter } from 'vue-input-facade'
import { InputFacade, facade, masker } from 'vue-input-facade'

export default {
components: { InputFacade },
directives: { facade },
filters: { facade: filter },
setup() {
return { masker }
}
// ... rest of component config
}
```
Expand Down
8 changes: 0 additions & 8 deletions docs/filter.md

This file was deleted.

8 changes: 8 additions & 0 deletions docs/masker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
You may use the library to mask values in static text as well, taking advantage of the same mask tokens.

```js
let phoneNumber = 18001234567
let orderNumber = 'ABC1234510'

<p>Thanks for ordering with us. Your order number is <b>{{ masker(orderNumber, 'SSS-#####-##').masked }}</b>. If you need assistance please call us at <b>{{ facade(phoneNumber, '#-###-###-####').masked }}</b></p>
```
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"build:docs": "vue-cli-service styleguidist:build --config styleguide/config.js",
"test": "jest --coverage",
"test:filter": "func() { yarn test \"$1\" --coverage-reporters=\"lcov\" --coverageThreshold={} ${@:2}; }; func",
"test:watch": "jest --coverage --watchAll"
"test:watch": "jest --coverage --watchAll",
"preyalcpublish": "yarn build:plugin"
},
"main": "dist/vue-input-facade.umd.min.js",
"files": [
Expand Down
14 changes: 1 addition & 13 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,10 @@ function install(Vue, options = {}) {

Vue.component(InputFacade.name, InputFacade)
Vue.directive(options.name || 'facade', facade)
Vue.filter(options.name || 'facade', filter)
}

/**
* Utility function to be used as a vue filter
*
* @param {String} value the value to apply the filter to
* @param {*} config the masking config
* @returns {string} the masked value as returned by the masker function
*/
function filter(value, config) {
return masker(value, config).masked
}

export default install
export { InputFacade, facade, tokens, masker, filter }
export { InputFacade, facade, tokens, masker }

// Install by default if included from script tag
if (typeof window !== 'undefined' && window.Vue) {
Expand Down
6 changes: 3 additions & 3 deletions styleguide/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path')
const pkg = require('../package.json')
const { execSync } = require('child_process');
const { execSync } = require('child_process')

const root = path.resolve(__dirname, '../')

Expand Down Expand Up @@ -35,8 +35,8 @@ module.exports = {
content: `${root}/docs/directive.md`
},
{
name: 'Filter',
content: `${root}/docs/filter.md`
name: 'Masker',
content: `${root}/docs/masker.md`
},
{
name: 'Advanced',
Expand Down

0 comments on commit 2fe4afd

Please sign in to comment.