Skip to content

Repository files navigation

@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

ParamTypeDescription
currencystringThe currency

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

Formats a number

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

ParamTypeDefaultDescription
numbernumber | stringThe number to format
[thousands]string"".""thousands delimiter
[decimals]string"",""decimal delimiter
[length]integer2length of decimal
[currency]stringIf 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

ParamTypeDefaultDescription
strstringThe 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

ParamTypeDescription
srcstringThe source of the image
widthint | stringThe new image with
heightint | stringThe new image height

Example

//Given an image thumb sourceFizzmod.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 sourceFizzmod.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

ParamTypeDescription
cnamestringThe name of the cookie
cvaluemixedThe value of the cookie, if the value is an object, it will be JSON encoded
[exdays]intExpiration days, if not set the cookie will last through the session only
[isdomain]boolSet as domain cookie. (Default false, adding "." before the url.)

Functions.getCookie(cname) ⇒ string

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

ParamTypeDescription
cnamestringThe name of the cookie to get

Functions.deleteCookie(cname) ⇒ void

Remove cookie in docmuent

Kind: static method of Functions

ParamTypeDescription
cnamestringThe name of the cookie to delete

Functions.addAnimation(name, callback)

Add an animation listener for the given animation name

Kind: static method of Functions

ParamTypeDescription
namestringThe animation name
callbackfunctionThe 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

ParamTypeDescription
strstring
maxLengthnumberdefault 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

ParamTypeDescription
URLstringThe 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

ParamTypeDescription
listpricenumberNumber price of list
bestpricenumberNumber 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

ParamTypeDescription
customDataobjectcustomData object into orderForm
appNamestringCustomData App name
fieldsToSearcharrayArray 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

ParamTypeDescription
emailstringstring to check

Validations.isURL(URL) ⇒ boolean

Check if a string is a valid URL

Kind: static method of Validations

ParamTypeDescription
URLstringstring to check

Validations.isJSON(json) ⇒ boolean

Check if a string is a valid json

Kind: static method of Validations

ParamTypeDescription
jsonstringstring to check

Validations.isRUT(rut) ⇒ boolean

Validate RUT (Chile)

Kind: static method of Validations

ParamTypeDescription
rutstringThe rut to validate

Validations.isRUC(ruc) ⇒ boolean

Validate RUC (Perú)

Kind: static method of Validations

ParamTypeDescription
rucstringThe ruc to validate

Validations.isRFC(RFC) ⇒ boolean

Validate RFC (Mexico)

Kind: static method of Validations

ParamTypeDescription
RFCstringThe RFC to validate

About

Funciones utiles para uso general en ecommerce de vtex

Resources

Stars

0 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages