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

@fizzmod/utils

v1.3.0

Published

Utitities functions and validations

Downloads

164

Readme

@fizzmod/utils

Funciones utiles para desarrollar un ecommerce en vtex

Install

npm install --save @fizzmod/utils

Peer Dependecies

Utils : object

Kind: global namespace

Utils.Functions : object

Kind: static namespace of Utils

Functions.setCurrency(currency)

Sets the currency that will be used by helper functions

Kind: static method of Functions

| Param | Type | Description | | --- | --- | --- | | currency | string | The currency |

Functions.formatPrice(number, [thousands], [decimals], [length], [currency]) ⇒ string

Formats a number

Kind: static method of Functions
Returns: string - The formatted price

| Param | Type | Default | Description | | --- | --- | --- | --- | | number | number | string | | The number to format | | [thousands] | string | ""."" | thousands delimiter | | [decimals] | string | "","" | decimal delimiter | | [length] | integer | 2 | length of decimal | | [currency] | string | | If true, the currency setted with Utils.setCurrency("$") will be added, if a currency (string) is passed it will use that instead; |

Functions.sanitizeString(str, [replace]) ⇒ string

Sanitize a string, removing/replacing all special characters and spaces with underscore

Kind: static method of Functions
Returns: string - The modified string

| Param | Type | Default | Description | | --- | --- | --- | --- | | str | string | | The string to sanitize | | [replace] | string | ""-"" | The string to replace white spaces with, default "-" |

Example

Utils.sanitizeString("hóla múndo"); //Output "hola-mundo"

Functions.getResizedImage(src, width, height) ⇒ string

Change the width & height from a given VTEX image source

Kind: static method of Functions
Returns: string - The resized image source

| Param | Type | Description | | --- | --- | --- | | src | string | The source of the image | | width | int | string | The new image with | | height | int | string | The new image height |

Example

//Given an image thumb source
Fizzmod.Utils.getResizedImage('http://fizzmod.vteximg.com.br/arquivos/ids/155242-292-292/image.png', 500, 600);
//Output: http://fizzmod.vteximg.com.br/arquivos/ids/155242-500-600/image.png

//Given a full image source
Fizzmod.Utils.getResizedImage('http://fizzmod.vteximg.com.br/arquivos/ids/155242/image.png', 100, 100);
//Output: http://fizzmod.vteximg.com.br/arquivos/ids/155242-100-100/image.png

Functions.setCookie(cname, cvalue, [exdays], [isdomain]) ⇒ void

set a cookie

Kind: static method of Functions

| Param | Type | Description | | --- | --- | --- | | cname | string | The name of the cookie | | cvalue | mixed | The value of the cookie, if the value is an object, it will be JSON encoded | | [exdays] | int | Expiration days, if not set the cookie will last through the session only | | [isdomain] | bool | Set as domain cookie. (Default false, adding "." before the url.) |

Functions.getCookie(cname) ⇒ string

Kind: static method of Functions
Returns: string - - The cookie value

| Param | Type | Description | | --- | --- | --- | | cname | string | The name of the cookie to get |

Functions.deleteCookie(cname) ⇒ void

Remove cookie in docmuent

Kind: static method of Functions

| Param | Type | Description | | --- | --- | --- | | cname | string | The name of the cookie to delete |

Functions.addAnimation(name, callback)

Add an animation listener for the given animation name

Kind: static method of Functions

| Param | Type | Description | | --- | --- | --- | | name | string | The animation name | | callback | function | The animation callback |

Example

Fizzmod.Utils.addAnimation('nodeInserted', myFunction);

Functions.setStrLength(str, maxLength) ⇒

slice string if string is greater than maxLength

Kind: static method of Functions
Returns: new string with three dots

| Param | Type | Description | | --- | --- | --- | | str | string | | | maxLength | number | default 27 |

Example

Utils.setStrLength('Fizzmod', 3) // Fizz...

Functions.stripHost(URL) ⇒ string

Removes the host from an URL

Kind: static method of Functions
Returns: string - The modified string

| Param | Type | Description | | --- | --- | --- | | URL | string | The URL |

Example

Utils.stripHost("http://test.vtexcommercestable.com.br/contacto/test"); //  "/contacto/test"

Functions.detectIE() ⇒ string | false

Check whether the browser is IE and return the version if so.

Kind: static method of Functions
Returns: string | false - The IE version or false if other browser

Functions.calculatePercentDiscount(listprice, bestprice) ⇒ string

calculates discount percentage between two prices.

Kind: static method of Functions
Returns: string - - Return percent discunt rounded in Price

| Param | Type | Description | | --- | --- | --- | | listprice | number | Number price of list | | bestprice | number | Number price for selling |

Example

Utils.calculatePercentDiscount(100, 50) // 50%

Functions.isGoogleMapLoaded() ⇒ boolean

Check if google mao is loadedd

Kind: static method of Functions

Functions.getServerTime() ⇒ Promise

Get the VTEX server time

Kind: static method of Functions

Functions.getCustomDataInfo(customData, appName, fieldsToSearch) ⇒ object | null

Function for get info into especific fields in app into customData

Kind: static method of Functions

| Param | Type | Description | | --- | --- | --- | | customData | object | customData object into orderForm | | appName | string | CustomData App name | | fieldsToSearch | array | Array of string with CustomData app fields names |

Utils.Validations : object

Kind: static namespace of Utils

Validations.isEmail(email) ⇒ boolean

check if a string is a valid email

Kind: static method of Validations

| Param | Type | Description | | --- | --- | --- | | email | string | string to check |

Validations.isURL(URL) ⇒ boolean

Check if a string is a valid URL

Kind: static method of Validations

| Param | Type | Description | | --- | --- | --- | | URL | string | string to check |

Validations.isJSON(json) ⇒ boolean

Check if a string is a valid json

Kind: static method of Validations

| Param | Type | Description | | --- | --- | --- | | json | string | string to check |

Validations.isRUT(rut) ⇒ boolean

Validate RUT (Chile)

Kind: static method of Validations

| Param | Type | Description | | --- | --- | --- | | rut | string | The rut to validate |

Validations.isRUC(ruc) ⇒ boolean

Validate RUC (Perú)

Kind: static method of Validations

| Param | Type | Description | | --- | --- | --- | | ruc | string | The ruc to validate |

Validations.isRFC(RFC) ⇒ boolean

Validate RFC (Mexico)

Kind: static method of Validations

| Param | Type | Description | | --- | --- | --- | | RFC | string | The RFC to validate |