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

@plasma-platform/helpers

v0.12.1

Published

helpers functions for storefront project

Downloads

130

Readme

version nextVersion downloads license dependency


Full documentation
install:
npm i @plasma-platform/helpers -S

Short documentation

Table of Contents

convertToAppFormat

Function for convert locale bd format (pt or etc) to app format (pt-br or etc)

Parameters

Examples

import { convertToAppFormat } from '@plasma-platform/helpers/lib/locales';
// or
import convertToAppFormat from '@plasma-platform/helpers/lib/locales/convertToAppFormat';

const locale = convertToAppFormat(uk);
// locale === 'ua'

Returns string

convertToDBFormat

Function for convert locale app format (pt-br or etc) to db format (pt or etc)

Parameters

Examples

import { convertToDBFormat } from '@plasma-platform/helpers/lib/locales';
// or
import convertToDBFormat from '@plasma-platform/helpers/lib/locales/convertToDBFormat';

const locale = convertToDBFormat(ua);
// locale === 'uk'

Returns string

getCurrent

Function for get current locale form location or from cookie

Parameters

Examples

import { getCurrent } from '@plasma-platform/helpers/lib/locales';
// or
import getCurrent from '@plasma-platform/helpers/lib/locales/getCurrent';

const locale = getCurrent(location);
// locale === { label: 'uk', value: 'ua' }

Returns object { label: 'uk', value: 'ua' }

getLocaleForUrl

Function for get locale for url

Parameters

Examples

import { getLocaleForUrl } from '@plasma-platform/helpers/lib/locales';
// or
import getLocaleForUrl from '@plasma-platform/helpers/lib/locales/getLocaleForUrl';

const locale = getLocaleForUrl('ua');
// locale === '/en'

Returns string /uk

Cookie

Cookie API

getItem

getItem

Parameters

  • sKey string (required) key to get cookie

Examples

const locale = Cookie.getItem('country_code');

Returns string cookie value

setItem

getItem

Parameters

Examples

const locale = Cookie.setItem('country_code', 'ua');

Returns boolean result

removeItem

getItem

Parameters

  • sKey string (required) key remove cookie
  • sPath string cookie path
  • sDomain string cookie domain

Examples

const locale = Cookie.removeItem('country_code');

Returns boolean result

hasItem

getItem

Parameters

  • sKey string (required) key for check cookie

Examples

const locale = Cookie.hasItem('country_code');

Returns boolean result

dispatchCustomEvent

Create and dispatch custom event with optional 'detail' parameter

Parameters

  • name string Event name
  • detail any? Additional data (read only)

Examples

dispatchCustomEvent('eventName', { data: 'myData' })

Returns boolean

getElement

Get element by selector

Parameters

Returns any

getAll

Get all elements by selector

Parameters

Returns any

data

Get data attributes

Parameters

  • element

Returns {}

addClass

Add class

Parameters

  • element
  • classList (optional, default [])

Returns any

attr

Attributes

Parameters

  • element
  • key
  • value

Returns any

removeClass

Remove class

Parameters

  • element
  • classList

Returns any

hasClass

Has class

Parameters

  • element
  • className

Returns boolean

removeAttribute

Remove Attribute

Parameters

  • element
  • name

Returns any

parseHtmlString

parses html string to child node

Parameters

Returns ChildNode

prepend

inserts element as first child of its parent

Parameters

  • parent
  • element

Returns (null | any)

append

inserts element as last child of its parent

Parameters

  • parent
  • element

Returns (null | any)

renderHtml

Appends timer to html page

IsomorphicCookie

Utility for interacting with cookies in isomorphic way

switchToServerMode

switchToServerMode

Parameters

  • oReq object (required) Express request object
  • oRes object (required) Express response object

Examples

IsomorphicCookie.switchToServerMode(req, res);

getItem

getItem

Parameters

  • sKey string (required) key to get cookie

Examples

const locale = IsomorphicCookie.getItem('country_code');

Returns string cookie value

setItem

setItem

Parameters

Examples

IsomorphicCookie.setItem('country_code', 'ua', 36000000, '/', '.templatemonster.me', false);

removeItem

removeItem

Parameters

  • sKey string (required) key remove cookie
  • sPath string (required) cookie path
  • sDomain string (required) cookie domain

Examples

IsomorphicCookie.removeItem('country_code', '/', '.templatemonster.com);

ClientCookie

Client-side utility for cookies

getItem

getItem

Parameters

  • sKey string (required) key to get cookie

Examples

const locale = ClientCookie.getItem('country_code');

Returns string cookie value

setItem

setItem

Parameters

Examples

ClientCookie.setItem('country_code', 'ua', 36000000, '/', '.templatemonster.me', false);

removeItem

removeItem

Parameters

  • sKey string (required) key remove cookie
  • sPath string (required) cookie path
  • sDomain string (required) cookie domain

Examples

ClientCookie.removeItem('country_code', '/', '.templatemonster.com);

ServerCookie

Creates server-side utility for cookies

Parameters

  • oReq object (required) request object from Express
  • oRes object (required) response object from Express

getItem

getItem

Parameters

  • sKey string (required) key to get cookie

Examples

const locale = IsomorphicCookie.getItem('country_code');

Returns string cookie value

setItem

setItem

Parameters

Examples

ServerCookie.setItem('country_code', 'ua', 36000000, '/', '.templatemonster.me', false);

removeItem

removeItem

Parameters

  • sKey string (required) key remove cookie
  • sPath string (required) cookie path
  • sDomain string (required) cookie domain

Examples

ServerCookie.removeItem('country_code', '/', '.templatemonster.com);

Observer

Observer lib

getObservers

Get observers

Parameters

  • name string (required) Event name

Examples

const observer = new Observer();
const observers = observer.getObservers('click');

Returns Array<function> Array of callback functions or empty array

subscribe

Subscribe for event and pass callback function to be called

Parameters

  • name string (required) Event name
  • callback function (required) Callback function

Examples

const observer = new Observer();
observer.subscribe('click');

Returns function Callback function

unsubscribe

Unsubscribe from event

Parameters

  • name string (required) Event name
  • callback function (required) Callback function

Examples

const observer = new Observer();
observer.subscribe('click');
observer.unsubscribe('click');

broadcast

Broadcast event

Parameters

  • name string (required) Event name
  • data any? Data to be passed as argument to callback function

Examples

const observer = new Observer();
observer.subscribe('click');
observer.broadcast('click', 'Hello!');