Logo
Chakra-UIReactJsNext.JS
Head

@codecraftkit

Documentation

Helpers

Description#

Helpers is package that has a bundle of useful functions to use in the project.

Installation#

Install Helpers package#

Code Example

npm install @codecraftkit/helpers

External dependencies#

Code Example

npm i @apollo/client graphql moment subscriptions-transport-ws
npm i isomorphic-unfetch is-electron slugify

Install each one separated#

Some components their own standalone package

Helpers Example#

Comet#

Code Example

npm i @codecraftkit/comet

This helper allows to make calls to the meteor backend

To use Comet first yo have to initialize it in you _app page like this

Code Example

import { Comet as CometApi} from '@codecraftkit/helpers'
// o import Comet from '@codecraftkit/comet'
/**
* Meteor Backend Connection
*/
global['Comet'] = CometApi({
host: process.env.NEXT_PUBLIC_METEOR_BACKEND,
ssl: process.env.NEXT_PUBLIC_METEOR_SSL,
tokenKey: 'token'
})

Running a fecth query

Code Example

const getDataSelect = async (value) => {
setLoading(true);
try {
const res = await Comet.call('service.name',{filters});
if(res.success){
setData(res.data)
}
setLoading(false)
} catch (e) {
}
};

toLowerCase#

Code Example

npm i @codecraftkit/texttransform

toLowerCase allows the user to transform the text into a camelCase Form

Code Example

toLowerCase("STRING TO CAMEL CASE") // string to camel case

phoneNumber#

Code Example

npm i @codecraftkit/phonenumber

phoneNumber allows us to add a prefix to a phone number and chose if we want to show it or not

Code Example

phoneNumber(58846141788,'58') // +58 (588) 461-4178

splitItem#

Code Example

npm i @codecraftkit/splititem

It gets a string with the keys of the object separate by a dot, Then it takes care of looping through each key to get the value from the object that is the second argument

Code Example

splitItem("user.name.name",{user:{name:{name:"Jose"}}}) // Jose

redirectTo#

Code Example

npm i @codecraftkit/redirectto

redirectTo is use to redirect the user to another route

Code Example

redirectTo(anotherRoute)

slug#

Code Example

npm i @codecraftkit/slug

Transform a String into slug form

Code Example

slug("ESTO ES UNA RUTA") // esto-es-una-ruta

NumberFormat#

Format any number to a more legible format

Code Example

NumberFormat(5000000000) // 5,000,000,000

getDuration#

Parse time in seconds to get its duration

Code Example

getDuration(5000000000) // 08:53:20