vue-common-filters
Collection of most used filter in projects.
Contribution
If you found a bug, want to request a feature or want to contribute, create issue or submit pull request
Installation
Install via npm
npm install vue-common-filters
Download repo
git clone https://github.com/epicbg/vue-common-filters.git
// THESE ARE ALL OPTIONS YOU CAN CUSTOMIZE// YOU ARE NOT REQUIRED TO COPY ALL THESE OPTIONS// YOU CAN PASS EMPTY OR NO OPTIONS AT ALL let config = "currency": "symbol": "$" "decimalDigits": 2 "symbolOnLeft": true "spaceBetweenAmountAndSymbol": false "text": "truncateClamp": "..." "numbers": "decimalDigits": 2 "array": "implodeDelimiter": ", " "dates": "defaultFormat": "YYYY-MM-DD HH:mm:ss" "filterConvertFormat": "DD MMMM YYYY" Vue
Usage
Text filters
truncate
Arguments:
{Number} [length] {string} [clamp] - default: '...'
Example:
string | // 'hello world' => 'hel...'
trim
Example:
string | trim // removes spaces from string
capitalize
Example:
string | capitalize // 'george' => 'George'
uppercase / lowercase
Example:
string | uppercase // 'hey' => 'HEY'
string | lowercase // 'HEY' => 'hey'
placeholder
Example:
string | // null || false => 'no data yet'
Array / object filters
implode
Arguments:
{string} [delimiter] - default: ', '
Example:
array | implode // ['Danny', 'Bobby', 'Mima'] => Danny, Boby, Mima array | // ['Danny', 'Bobby', 'Mima'] => Danny and Boby and Mima
implodeObjects
Arguments:
{string} [key] {string} [delimiter] - default: ', '
Example:
users | // [{id: 1, name:'Danny'}, {id: 2, name:'Bobby'}] => Danny, Bobby users | // [{id: 1, name:'Danny'}, {id: 2, name:'Bobby'}] => Danny and Bobby
search
Searches all fields (inside array of objects) for a match with passed [key]
Arguments:
{string} [key]
Example:
users | | // [{name:'Danny Miller'}, {name:'Danny Grande'}, {name:'Bobby Miller'}]// => Danny Miller, Bobby Miller
Date filters
Examples are shown in default YYYY-MM-DD HH:mm:ss
. If you have different format you can change it from the config as shown in installation section
This packages uses moment and if you want to change the locale you can do it like so:
moment
formatDate
Arguments:
{string} [format] - default: DD MMMM YYYY
Example:
date | // '2018-02-01' => '1 February' date | formatDate // '2018-02-01' => '1 February 2019'
fromNow
date | fromNow // '2019-02-01' => '8 months ago'
from
Arguments:
{string} [from]
Example:
date | // '2019-07-01' => '1 year ago'
to
Arguments:
{string} [to]
Example:
date | // '2019-06-01' => 'in 1 month'
add / subtract
Arguments:
{number} [number] {string} [type]
Example:
date | // '2019-06-01' => '2019-06-03' date | // '2019-06-03' => '2019-06-01'
Number filters
decimal
Arguments:
{Number} [length] - default: 2
Example:
// '1' => '1.00'// '1.2' => '1.20' coefficient | decimal
currency
Arguments:
{string} [symbol] - default: $ {Number} [decimalDigits] - default: 2 {Boolean} [symbolOnLeft] - default: true {Number} [spaceBetweenAmountAndSymbol] - default: true
Example:
amount | currency // 12 => '$ 12.00' amount | // 12 => 12.00 EUR
You can change the defaults from settings, as shown in installation section
Programatic Usage
using functions
this$optionsfilters
this$optionsfilters '$ 10.00'this$optionsfilters
changing settings
// Pass options which u want to customize, no need to pass the whole settings objectvueCommonFiltersconfig = currency: symbol: 'EUR'
License
MIT License
Copyright (c) 2019 EpicWeb