# vue2-utils

> Vue2Utils: Vue2 component

Latest version **0.1.51** (published 2018-11-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install vue2-utils
pnpm add vue2-utils
yarn add vue2-utils
bun add vue2-utils
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.51 |
| Published | 2018-11-30 |
| First published | 2018-04-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 4.2.0 |
| Dependencies | 0 |
| Unpacked size | 160.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | sanchit |
| Maintainers | san-kumar |
| Keywords | vue, bootstrap, Vue2Utils, vue2-utils |

## Links

- npm: https://www.npmjs.com/package/vue2-utils
- Repository: https://github.com/san-kumar/vue2-utils
- Issues: https://github.com/san-kumar/vue2-utils/issues
- npm.io page: https://npm.io/package/vue2-utils

## Alternatives

- [@sveltejs/kit](https://npm.io/package/@sveltejs/kit.md) — 2.2M weekly downloads
- [@atlaskit/theme](https://npm.io/package/@atlaskit/theme.md) — 402.0K weekly downloads
- [@tangle-network/brand](https://npm.io/package/@tangle-network/brand.md) — 10.0K weekly downloads
- [seneca](https://npm.io/package/seneca.md) — 7.4K weekly downloads
- [@bsb/base](https://npm.io/package/@bsb/base.md) — 7.2K weekly downloads

## Recent versions

- 0.1.51 (latest) — 2018-11-30
- 0.1.50 — 2018-11-30
- 0.1.49 — 2018-11-10
- 0.1.48 — 2018-11-10
- 0.1.47 — 2018-09-20
- 0.1.46 — 2018-09-20
- 0.1.45 — 2018-09-20
- 0.1.44 — 2018-09-05
- 0.1.43 — 2018-07-24
- 0.1.42 — 2018-07-21
- 0.1.41 — 2018-07-21
- 0.1.40 — 2018-07-21
- 0.1.39 — 2018-07-21
- 0.1.38 — 2018-07-19
- 0.1.37 — 2018-07-19
- … 46 more at https://npm.io/package/vue2-utils/versions

## README

# Vue2Utils
> Vue2Utils: Common Javascript functions as mixins

## Install

``` bash
    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

<!-- functions start -->

### Array related
- [**is_array**](src/methods.js#L3) check if value is an *Array* type
    - <small>Params: value</small>

- [**is_object**](src/methods.js#L6) check if value is an *Object* type
    - <small>Params: value</small>

- [**is_scalar**](src/methods.js#L9) checks if value is a primitive like number, string, etc
    - <small>Params: value</small>

- [**to_array**](src/methods.js#L12) converts any value into an array if not already
    - <small>Params: value</small>

- [**obj_values**](src/methods.js#L15) returns all the values of a object
    - <small>Params: obj</small>

- [**for_each**](src/methods.js#L24) iterates over an array or hash using callback. quits if callback returns false
    - <small>Params: value, fn</small>

- [**clone**](src/methods.js#L33) Deep copies an object replacing all old references
    - <small>Params: obj</small>

- [**json_safe_stringify**](src/methods.js#L36) Stringifies an object ignoring circular references
    - <small>Params: o</small>

- [**array_filter_items**](src/methods.js#L52) returns only matching items (if array item matches, or hash has any matching values)
    - <small>Params: arr, match, exact = false, ignore_case = true</small>

- [**array_merge**](src/methods.js#L78) merges multiple arrays into one
    - <small>Params: ...arrays</small>

- [**array_unique**](src/methods.js#L86) return unique elements of array
    - <small>Params: array</small>

- [**where**](src/methods.js#L91) Looks through each value in the list, returning all values that matches the key-value pairs listed in properties.
    - <small>Params: arr, match</small>

- [**randomize**](src/methods.js#L111) randomizes the array
    - <small>Params: array</small>

- [**pluck**](src/methods.js#L120) returns only a set key from a hash
    - <small>Params: obj, ...keys</small>

- [**in_array**](src/methods.js#L130) checks if a value exists inside array
    - <small>Params: needle, haystack, ignore_case = false</small>

- [**toggle_array_item**](src/methods.js#L140) removes or inserts an array item
    - <small>Params: needle, haystack, ignore_case = false</small>

- [**sort_by_key**](src/methods.js#L153) sort an array by key
    - <small>Params: array, key, reverse</small>

- [**group_by**](src/methods.js#L170) groups an array by key
    - <small>Params: array, key</small>

- [**chunk**](src/methods.js#L176) chunks array in size of len
    - <small>Params: arr, len</small>

- [**obj_extend**](src/methods.js#L185) 
    - <small>Params: dest, ...objects</small>

- [**obj_set**](src/methods.js#L198) set an obj using dot path notation
    - <small>Params: object, path, value</small>

- [**obj_get**](src/methods.js#L220) gets an obj using dot path notation
    - <small>Params: object, path</small>

- [**obj_init**](src/methods.js#L242) only sets an obj if there is no existing value
    - <small>Params: object, path, value, type = null</small>

- [**obj_vue_set**](src/methods.js#L250) 
    - <small>Params: o, key, value</small>

- [**obj_flat**](src/methods.js#L253) flattens a object (optionally applying a filter function to values/key before adding)
    - <small>Params: data, filter = null</small>

- [**array_clean**](src/methods.js#L284) removes empty elements of an array or non empty keys from hash
    - <small>Params: actual</small>

- [**remove_item**](src/methods.js#L302) removes an item from array or object (modes: 'ignore_case' = for scalar array, 'fuzzy' = for objects [compares using JSON.stringify each object))
    - <small>Params: needle, haystack, mode = null</small>

- [**equals**](src/methods.js#L331)  deep compares two objects for equality
    - <small>Params: x, y</small>


### String related
- [**lines**](src/methods.js#L367) breaks long text into lines (delimited by \r?\n)
    - <small>Params: string</small>

- [**sentences**](src/methods.js#L370) breaks long text into sentences (by period, question mark, etc)
    - <small>Params: str</small>

- [**words**](src/methods.js#L375) break text into words
    - <small>Params: str</small>

- [**single_line**](src/methods.js#L378) combine array into long text
    - <small>Params: lines, delim = ''</small>

- [**ascii**](src/methods.js#L382) remove non ascii chars from a string (utf8)
    - <small>Params: str</small>

- [**slugify**](src/methods.js#L387) turns a string into slug format
    - <small>Params: str</small>

- [**password**](src/methods.js#L406) generates random password
    - <small>Params: len</small>

- [**kebab**](src/methods.js#L409) converts string (including camelCase) into kebab case
    - <small>Params: str, delim = '-'</small>

- [**camel**](src/methods.js#L412) turns string to camelCase
    - <small>Params: str</small>

- [**remove_parens**](src/methods.js#L417) remove parenthesis from text
    - <small>Params: Input</small>

- [**str_replace**](src/methods.js#L435) replace placeholders in string
    - <small>Params: str, replacements</small>

- [**str_equals**](src/methods.js#L440) compares two strings for equality with/without case-sensitivity
    - <small>Params: str1, str2, ignore_case = true</small>

- [**empty**](src/methods.js#L447) checks if a value is empty incl. array and hash
    - <small>Params: value</small>

- [**ucfirst**](src/methods.js#L450) capitalizes the first letter of string
    - <small>Params: string</small>

- [**ucwords**](src/methods.js#L453) capitalizes all words
    - <small>Params: string</small>

- [**trim**](src/methods.js#L456) trims a string from both sides
    - <small>Params: value, char = "\s\s*"</small>

- [**ltrim**](src/methods.js#L459) trims a string from left
    - <small>Params: value, char = "\s\s*"</small>

- [**rtrim**](src/methods.js#L463) trims a string from right
    - <small>Params: value, char = "\s\s*"</small>

- [**truncate**](src/methods.js#L467) truncates a string at maxlen (adds ellipses if truncated)
    - <small>Params: str, maxlen = 20, html = false</small>

- [**stop_words**](src/methods.js#L475) returns a promise that resolves with most common stop words
    - <small>Params: *none*</small>

- [**html2text**](src/methods.js#L480) converts html to plain text
    - <small>Params: html</small>

- [**quotemeta**](src/methods.js#L485) add backslashes to a string for quoting regex, etc
    - <small>Params: text</small>


### Internet related
- [**is_url**](src/methods.js#L489) checks if value is URL
    - <small>Params: url</small>

- [**google**](src/methods.js#L492) creates a google search link for a keyword
    - <small>Params: keyword, lucky = false</small>

- [**http_get**](src/methods.js#L495) performs a simple get request
    - <small>Params: url</small>

- [**parse_query**](src/methods.js#L514) parses a query string into hash
    - <small>Params: queryString = null</small>

- [**query_get_param**](src/methods.js#L528) parses current url for named param
    - <small>Params: name, fallback = ''</small>

- [**get_hash_value**](src/methods.js#L532) parses current url for param in hash (part after #)
    - <small>Params: key</small>

- [**image_size**](src/methods.js#L536) returns a promise that gives width and height of images
    - <small>Params: src</small>

- [**domain**](src/methods.js#L546) return the TLD for any url or hostname
    - <small>Params: url, tld = true</small>

- [**check_email**](src/methods.js#L564) checks if an email address is valid or not (with details)
    - <small>Params: email</small>

- [**get_youtube_id**](src/methods.js#L568) returns youtube-id from any youtube url
    - <small>Params: url</small>

- [**get_youtube_thumb**](src/methods.js#L574) gets the thumbnail of a youtube video
    - <small>Params: url, hq = true</small>

- [**get_thumb**](src/methods.js#L579) generates a thumbnail from any url including youtube videos
    - <small>Params: url, width = 200, height = ''</small>

- [**random_photo**](src/methods.js#L589) returns a random photo for placeholder
    - <small>Params: width = 300, height = 200</small>

- [**random_user_data**](src/methods.js#L592) returns a random user data for testing
    - <small>Params: *none*</small>


### Number related
- [**to_num**](src/methods.js#L604) always returns a number or 0 (fix NaN issues)
    - <small>Params: value</small>

- [**random**](src/methods.js#L607) returns a random number between min and max
    - <small>Params: min, max</small>


### File related
- [**basename**](src/methods.js#L611) returns the basename of a file
    - <small>Params: str</small>

- [**extension**](src/methods.js#L617) return the extension of a file
    - <small>Params: filename</small>

- [**noop**](src/methods.js#L621) this function does nothing
    - <small>Params: *none*</small>

- [**hash_code**](src/methods.js#L624) Generate a Hash from string
    - <small>Params: str</small>

- [**today**](src/methods.js#L634) returns today's date in dd/mm/yy
    - <small>Params: date = null, delim = '/'</small>

- [**to_date**](src/methods.js#L648) parses a date string into Javascript Date
    - <small>Params: str</small>

- [**hms**](src/methods.js#L651) converts seconds in hh:mm:ss
    - <small>Params: secs</small>

- [**parse_date**](src/methods.js#L656) parses any time into a date
    - <small>Params: time, tz = false</small>

- [**time_ago**](src/methods.js#L674) human readable relative time
    - <small>Params: time, tz = false</small>

- [**debounce**](src/methods.js#L721) makes a debounced version of a function, let debounced = debounce(() => console.log(111), 1500); debounced(); debounced();
    - <small>Params: func, wait, immediate = false</small>

- [**is_debug**](src/methods.js#L736) checks if debug mode is on
    - <small>Params: *none*</small>

- [**browser**](src/methods.js#L739) return browser's name
    - <small>Params: *none*</small>

- [**redirect**](src/methods.js#L765) redirect to another page using GET or POST with data
    - <small>Params: url, target = '_self', method = 'get', data = {}</small>

- [**clipboard_copy**](src/methods.js#L786) copies text to clipboard (must be initiated by a user click)
    - <small>Params: text</small>

- [**set_cookie**](src/methods.js#L803)  sets a cookie
    - <small>Params: name, value, days = 30</small>

- [**get_cookie**](src/methods.js#L812)  gets a cookie by name
    - <small>Params: name</small>

- [**erase_cookie**](src/methods.js#L822)  deletes a cookie by name
    - <small>Params: name</small>

- [**save_object**](src/methods.js#L825)  saves an object in localStorage
    - <small>Params: key, value</small>

- [**load_object**](src/methods.js#L828)  gets an object from localStorage
    - <small>Params: key</small>

- [**load_script**](src/methods.js#L832) loads a script and returns promise
    - <small>Params: src</small>

- [**debug**](src/methods.js#L843) writes arguments to console.log
    - <small>Params: ...args</small>

- [**is_mobile_device**](src/methods.js#L846) 
    - <small>Params: width = 768, checkAgent = false</small>

- [**mime_type**](src/methods.js#L853) 
    - <small>Params: filename</small>


### Bootstrap related
- [**mobile_text**](src/methods.js#L864) wraps text in html that changes based on browser resolution
    - <small>Params: normal, mobile, split = 'md', block = 'inline'</small>

- [**fa_icon**](src/methods.js#L867) return html for a font awesome icon
    - <small>Params: value, fw = false</small>


<!-- functions end -->

## Contributing
Contributions are welcome

## Build Setup

``` bash
# install dependencies
npm install

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

# build for production with minification
npm run build
```

---
_Source: https://npm.io/package/vue2-utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
