1.0.7 • Published 9 months ago

cliengo-fe-utils v1.0.7

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

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.

1.0.7

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago