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

cliengo-fe-utils

v1.0.7

Published

Javascript shared methods

Downloads

294

Readme

fe-utils (Frontend utils)

Js library to share useful methods

Installation

npm install cliengo-fe-utils

or

yarn add cliengo-fe-utils

Usage

import { method } from 'cliengo-fe-utils';

method();

Available functionality


copyToClipboard

Takes a value to send it to clipboard asynchronously and returns a boolean to indicates success or failure

import { copyToClipboard } from 'cliengo-fe-utils';

async function myFunction() {
  const hasSuccess = copyToClipboard('Hello world');
  if (hasSuccess) {
    // ...do stuff
  }
}

isEmpty

Takes a value and checks if it's any kind of empty

import { isEmpty } from 'cliengo-fe-utils';

async function myFunction() {
  const value = isEmpty('Hello world');
  //value = false

  const value2 = isEmpty('');
  //value2 = true
}

IframeMessagePublisher

Its a Class which uses the singleton pattern to set a unique instance with an initial configuration ready to be used across your application.

This was developed thinking on make the iframe communication with its parent much easier.

methods

setInstance

Initialize the instance with the configuration which will be used in the whole application

params:

postMessage

Send messages to parent

params:

Usage

import { IframeMessagePublisher } from 'cliengo-fe-utils';

// Initialize the instance
IframeMessagePublisher.setInstance('my-project');

// Use where you need
IframeMessagePublisher.postMessage('do-stuff');
IframeMessagePublisher.postMessage('do-stuff-with-params', {
  refresh: true,
  id: 12345
});

Analytics

methods

initialize

Initialize the analytics tracking

params: Object{segmentWriteKey, sendAnalytics, account, user}

properties:

Usage

import { Analytics } from 'cliengo-fe-utils';

// Initialize the instance
Analytics.initialize({
  segmentWriteKey: 'XXXXXXXXX',
  sendAnalytics: 'YES',
  account: JsonObject,
  user: JsonObject
});

trackEvent

Wrapper around the Segment's trackEvent method. it is how you tell Segment about which actions your users are performing on your site.

params: Object{ eventName, category, action, ...moreProps }

properties:

rest of the properties depends on the case

Usage

import { Analytics } from 'cliengo-fe-utils';

Analytics.trackEvent({
  eventName: 'user_registration',
  category: 'register',
  action: 'user_registration'
});

trackPage

Wrapper around method Segment's page method. it lets you record page views on your website, along with optional information about the page being viewed.

params:

rest of the properties depends on the case

Usage

import { Analytics } from 'cliengo-fe-utils';

Analytics.trackPage('/live/visitors');

setTraits

Lets you set the information about the current user and account.

params:

Usage

import { Analytics } from 'cliengo-fe-utils';

Analytics.setTraits(account, user);

isInitialized

Indicates if analytics script is already initialized.

Usage

import { Analytics } from 'cliengo-fe-utils';

Analytics.isInitialized();

isAnonymousMode

Indicates if analytics don't count with account and user information.

Usage

import { Analytics } from 'cliengo-fe-utils';

Analytics.isAnonymousMode();

Some flags: This utils set some flags at window level.

  • window.analytics.initialized
  • window.analyticsInAnonymousMode

Contributing

  1. Check out repo and create a branch
  2. Do your thing
  3. Bump version following SemVer
  4. Transpile code with yarn build
  5. Create a tag with the same name as the new version, otherwise the new version won't be downloadable! git tag X.Y.Z
  6. Submit a PR

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.