npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-common-filters

v1.1.0

Published

Collection of common filters used in projects

Downloads

6

Readme

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

import Vue from 'vue'
import VueCommonFilters from 'vue-common-filters'

// 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.use(VueCommonFilters, config)

Usage

Text filters

truncate

Arguments:

{Number} [length] {string} [clamp] - default: '...'

Example:

{{ string | truncate(3) }} // '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 | placeholder('no data yet') }} // null || false => 'no data yet'

Array / object filters

implode

Arguments:

{string} [delimiter] - default: ', '

Example:

{{ array | implode }} // ['Danny', 'Bobby', 'Mima'] => Danny, Boby, Mima
{{ array | implode('and') }} // ['Danny', 'Bobby', 'Mima'] => Danny and Boby and Mima

implodeObjects

Arguments:

{string} [key] {string} [delimiter] - default: ', '

Example:

{{ users | implodeObjects('name') }} // [{id: 1, name:'Danny'}, {id: 2, name:'Bobby'}] => Danny, Bobby
{{ users | implodeObjects('name', ' and ') }} // [{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 | search('Danny') | implodeObjects('name') }} 
// [{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.locale('en')

formatDate

Arguments:

{string} [format] - default: DD MMMM YYYY

Example:

{{ date | formatDate('DD MMMM') }} // '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 | from('2019-07-02') }} // '2019-07-01' => '1 year ago'

to

Arguments:

{string} [to]

Example:

{{ date | to('2019-07-01') }} // '2019-06-01' => 'in 1 month'

add / subtract

Arguments:

{number} [number] {string} [type]

Example:

{{ date | add(2, 'days') }} // '2019-06-01' => '2019-06-03'
{{ date | subtract(2, 'days') }} // '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 | currency('EUR', 2, false) }} // 12 => 12.00 EUR

You can change the defaults from settings, as shown in installation section

Programatic Usage

using functions

this.$options.filters.filterName(value)
this.$options.filters.currency(10) => '$ 10.00'
this.$options.filters.search([{}, {}..])

changing settings

import vueCommonFilters from 'vue-common-filters'

// Pass options which u want to customize, no need to pass the whole settings object
vueCommonFilters.config = {
    currency: {
        symbol: 'EUR'
    }
}

License

MIT License

Copyright (c) 2019 EpicWeb