@fizzmod/utils

1.3.0 • Public • Published

@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

Readme

Keywords

none

Package Sidebar

Install

npm i @fizzmod/utils

Weekly Downloads

56

Version

1.3.0

License

none

Unpacked Size

52.3 kB

Total Files

5

Last publish

Collaborators

  • devfizzmod