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

vue2-utils

v0.1.51

Published

Vue2Utils: Vue2 component

Downloads

52

Readme

Vue2Utils

Vue2Utils: Common Javascript functions as mixins

Install

    npm install vue2-utils --save

Usage

1. Import any function as mixin

import {function-name} from 'vue2-utils';

2. Use it inside your components

import {today} from 'vue2-utils';

export default {
    mixins: [today],
    methods: {
        ...
}

2. Use all the functions

//not recommended

import everything from 'vue2-utils';

export default {
    mixins: [everything],
    methods: {
        ...
}

*3. Use it anywhere in your Vue app!

if(this.empty([])) {
}

List of functions

Array related

  • is_array check if value is an Array type

    • Params: value
  • is_object check if value is an Object type

    • Params: value
  • is_scalar checks if value is a primitive like number, string, etc

    • Params: value
  • to_array converts any value into an array if not already

    • Params: value
  • obj_values returns all the values of a object

    • Params: obj
  • for_each iterates over an array or hash using callback. quits if callback returns false

    • Params: value, fn
  • clone Deep copies an object replacing all old references

    • Params: obj
  • json_safe_stringify Stringifies an object ignoring circular references

    • Params: o
  • array_filter_items returns only matching items (if array item matches, or hash has any matching values)

    • Params: arr, match, exact = false, ignore_case = true
  • array_merge merges multiple arrays into one

    • Params: ...arrays
  • array_unique return unique elements of array

    • Params: array
  • where Looks through each value in the list, returning all values that matches the key-value pairs listed in properties.

    • Params: arr, match
  • randomize randomizes the array

    • Params: array
  • pluck returns only a set key from a hash

    • Params: obj, ...keys
  • in_array checks if a value exists inside array

    • Params: needle, haystack, ignore_case = false
  • toggle_array_item removes or inserts an array item

    • Params: needle, haystack, ignore_case = false
  • sort_by_key sort an array by key

    • Params: array, key, reverse
  • group_by groups an array by key

    • Params: array, key
  • chunk chunks array in size of len

    • Params: arr, len
  • obj_extend

    • Params: dest, ...objects
  • obj_set set an obj using dot path notation

    • Params: object, path, value
  • obj_get gets an obj using dot path notation

    • Params: object, path
  • obj_init only sets an obj if there is no existing value

    • Params: object, path, value, type = null
  • obj_vue_set

    • Params: o, key, value
  • obj_flat flattens a object (optionally applying a filter function to values/key before adding)

    • Params: data, filter = null
  • array_clean removes empty elements of an array or non empty keys from hash

    • Params: actual
  • remove_item removes an item from array or object (modes: 'ignore_case' = for scalar array, 'fuzzy' = for objects [compares using JSON.stringify each object))

    • Params: needle, haystack, mode = null
  • equals deep compares two objects for equality

    • Params: x, y

String related

  • lines breaks long text into lines (delimited by \r?\n)

    • Params: string
  • sentences breaks long text into sentences (by period, question mark, etc)

    • Params: str
  • words break text into words

    • Params: str
  • single_line combine array into long text

    • Params: lines, delim = ''
  • ascii remove non ascii chars from a string (utf8)

    • Params: str
  • slugify turns a string into slug format

    • Params: str
  • password generates random password

    • Params: len
  • kebab converts string (including camelCase) into kebab case

    • Params: str, delim = '-'
  • camel turns string to camelCase

    • Params: str
  • remove_parens remove parenthesis from text

    • Params: Input
  • str_replace replace placeholders in string

    • Params: str, replacements
  • str_equals compares two strings for equality with/without case-sensitivity

    • Params: str1, str2, ignore_case = true
  • empty checks if a value is empty incl. array and hash

    • Params: value
  • ucfirst capitalizes the first letter of string

    • Params: string
  • ucwords capitalizes all words

    • Params: string
  • trim trims a string from both sides

    • Params: value, char = "\s\s*"
  • ltrim trims a string from left

    • Params: value, char = "\s\s*"
  • rtrim trims a string from right

    • Params: value, char = "\s\s*"
  • truncate truncates a string at maxlen (adds ellipses if truncated)

    • Params: str, maxlen = 20, html = false
  • stop_words returns a promise that resolves with most common stop words

    • Params: none
  • html2text converts html to plain text

    • Params: html
  • quotemeta add backslashes to a string for quoting regex, etc

    • Params: text

Internet related

  • is_url checks if value is URL

    • Params: url
  • google creates a google search link for a keyword

    • Params: keyword, lucky = false
  • http_get performs a simple get request

    • Params: url
  • parse_query parses a query string into hash

    • Params: queryString = null
  • query_get_param parses current url for named param

    • Params: name, fallback = ''
  • get_hash_value parses current url for param in hash (part after #)

    • Params: key
  • image_size returns a promise that gives width and height of images

    • Params: src
  • domain return the TLD for any url or hostname

    • Params: url, tld = true
  • check_email checks if an email address is valid or not (with details)

    • Params: email
  • get_youtube_id returns youtube-id from any youtube url

    • Params: url
  • get_youtube_thumb gets the thumbnail of a youtube video

    • Params: url, hq = true
  • get_thumb generates a thumbnail from any url including youtube videos

    • Params: url, width = 200, height = ''
  • random_photo returns a random photo for placeholder

    • Params: width = 300, height = 200
  • random_user_data returns a random user data for testing

    • Params: none

Number related

  • to_num always returns a number or 0 (fix NaN issues)

    • Params: value
  • random returns a random number between min and max

    • Params: min, max

File related

  • basename returns the basename of a file

    • Params: str
  • extension return the extension of a file

    • Params: filename
  • noop this function does nothing

    • Params: none
  • hash_code Generate a Hash from string

    • Params: str
  • today returns today's date in dd/mm/yy

    • Params: date = null, delim = '/'
  • to_date parses a date string into Javascript Date

    • Params: str
  • hms converts seconds in hh:mm:ss

    • Params: secs
  • parse_date parses any time into a date

    • Params: time, tz = false
  • time_ago human readable relative time

    • Params: time, tz = false
  • debounce makes a debounced version of a function, let debounced = debounce(() => console.log(111), 1500); debounced(); debounced();

    • Params: func, wait, immediate = false
  • is_debug checks if debug mode is on

    • Params: none
  • browser return browser's name

    • Params: none
  • redirect redirect to another page using GET or POST with data

    • Params: url, target = '_self', method = 'get', data = {}
  • clipboard_copy copies text to clipboard (must be initiated by a user click)

    • Params: text
  • set_cookie sets a cookie

    • Params: name, value, days = 30
  • get_cookie gets a cookie by name

    • Params: name
  • erase_cookie deletes a cookie by name

    • Params: name
  • save_object saves an object in localStorage

    • Params: key, value
  • load_object gets an object from localStorage

    • Params: key
  • load_script loads a script and returns promise

    • Params: src
  • debug writes arguments to console.log

    • Params: ...args
  • is_mobile_device

    • Params: width = 768, checkAgent = false
  • mime_type

    • Params: filename

Bootstrap related

  • mobile_text wraps text in html that changes based on browser resolution

    • Params: normal, mobile, split = 'md', block = 'inline'
  • fa_icon return html for a font awesome icon

    • Params: value, fw = false

Contributing

Contributions are welcome

Build Setup

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build for production with minification
npm run build