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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@janiscommerce/apps-helpers

v2.2.0

Published

Helpers for janis apps

Downloads

861

Readme

Apps helpers

Build Status Coverage Status npm version

This package provides utilities for use in Janis apps.

📦 Installation

npm install @janiscommerce/apps-helpers

Utils

Members

Functions

isEqualObj ⇒ boolean

Kind: global variable
Returns: boolean - Returns true if the objects are equivalent, else false.

| Param | Type | Description | | ------ | ------------------- | ----------------------------------- | | object | Object | The object to compare. | | other | Object | The other object to compare. |

Example

// eslint-disable-next-line no-restricted-syntax
import { isEqualObj } from '@janiscommerce/apps-helpers';
isEqualObj({ items: [{ id: 123 }] }, { items: [{ id: 123, ean: 456 }] }); // false

isValidIsoString ⇒ boolean

Kind: global variable
Returns: boolean - returns true if the date passed as an argument is valid

| Param | Type | Description | | ----- | ----------------- | ------------------------- | | date | Date | date in ISO format |

debounce(fn, [wait]) ⇒

Kind: global function
Returns: A function that will be called after the specified wait time.

| Param | Default | Description | | ------ | ---------------- | ------------------------------------------------------------------------ | | fn | | The function to be debounced. | | [wait] | 300 | The number of milliseconds to wait before executing the function. |

formatIsoToDate(params) ⇒ string

Kind: global function
Returns: string -

| Param | Type | Description | | ------------------- | ------------------- | ------------------------------------------------------ | | params | Object | param | | params.date | Date | iso format. Example: '2022-02-03T17:29:28.637Z' | | params.locale | String | iso format. Example: 'es-Ar' | | params.customFormat | String | iso format. Example: 'pp' |

generateRandomId() ⇒ string

Kind: global function
Example

import { generateRandomId } from '@janiscommerce/apps-helpers';
generateRandomId(); // '6kj4nk9c5so'

getHeaders([params], [deviceDataHeaders], [customHeaders]) ⇒ object

Kind: global function

| Param | Type | Default | Description | | -------------------- | -------------------- | --------------- | ----------------------------------------------- | | [params] | object | {} | object with params | | [deviceDataHeaders] | object | {} | headers with the device info | | [customHeaders] | object | {} | extra custom headers | | params.client | string | | client name for janis api | | params.accessToken | string | | access token for janis api | | params.page | number | | number of page | | params.pageSize | number | | quantity per page | | params.getTotals | boolean | | request api totals | | params.getOnlyTotals | boolean | | request api totals without body response |

Example

const params = {
	client: 'my-client',
	accessToken: 'my-access-token',
	page: 1,
	pageSize: 10,
	getTotals: true,
	getOnlyTotals: false
};
const deviceDataHeaders = {
	'janis-app-name': 'MyApp',
	'janis-app-version': '1.0.0',
	'janis-app-device-os-name': 'iOS',
	'janis-app-device-os-version': '14.5',
	'janis-app-device-name': 'iPhone 12',
	'janis-app-device-id': '123456789'
};
const customHeaders = {
	'custom-header': 'custom-value'
};
const headers = getHeaders(params, deviceDataHeaders, customHeaders);
// {
//   'content-Type': 'application/json',
//   'janis-api-key': 'Bearer',
//   'janis-client': 'my-client',
//   'janis-api-secret': 'my-access-token',
//   'x-janis-page': 1,
//   'x-janis-page-size': 10,
//   'x-janis-totals': true,
//   'x-janis-only-totals': false,
//   'user-agent': 'MyApp/1.0.0 (iOS 14.5; iPhone 12; 123456789)',
//   'custom-header': 'custom-value'
// }

isArray(arr) ⇒ bool

Kind: global function

| Param | Type | | ----- | ------------------ | | arr | array |

Example

import { isArray } from '@janiscommerce/apps-helpers';
isArray(['Janis']); // true

isBoolean(fn) ⇒ bool

Kind: global function

| Param | Type | | ----- | -------------------- | | fn | boolean |

Example

import {isBoolean} from '@janiscommerce/apps-helpers'
isBoolean((true) // true

isEmptyArray(arr) ⇒ bool

Kind: global function

| Param | Type | | ----- | ------------------ | | arr | array |

Example

import { isEmptyArray } from '@janiscommerce/apps-helpers';
isEmptyArray(['Janis']); // false

isEmptyObject(obj) ⇒ bool

Kind: global function

| Param | Type | | ----- | ------------------- | | obj | object |

Example

import { isEmptyObject } from '@janiscommerce/apps-helpers';
isEmptyObject('Janis'); // false

isFunction(fn) ⇒ bool

Kind: global function

| Param | Type | | ----- | --------------------- | | fn | function |

Example

import { isFunction } from '@janiscommerce/apps-helpers';
isFunction(() => true); // true

isJSON(param) ⇒ bool

Kind: global function

| Param | Type | | ----- | ------------------- | | param | string |

Example

import { isJSON } from '@janiscommerce/apps-helpers';
isJSON('{"key": "value"}'); // true

isObject(obj) ⇒ bool

Kind: global function

| Param | Type | | ----- | ------------------- | | obj | object |

Example

import { isObject } from '@janiscommerce/apps-helpers';
isObject('Janis'); // false

isRequired(param) ⇒ Error

Kind: global function

| Param | Type | Description | | ----- | ------------------- | ----------------------------------------- | | param | string | name of the param that is required |

Example

import { isRequired } from '@janiscommerce/apps-helpers';
const promise = async (arg = isRequired('arg')) => {
	return arg;
};

promise(); // Error: 'arg is required'

isString(str) ⇒ bool

Kind: global function

| Param | Type | Description | | ----- | ------------------- | -------------------------- | | str | string | String to validate. |

Example

import { isString } from '@janiscommerce/apps-helpers';
isString('Janis'); // true

isValidFormatPosition(position) ⇒ boolean

Kind: global function

| Param | Type | Description | | -------------------- | ------------------- | ---------------------- | | position | object | position object | | position.positionKey | string | positionKey | | position.positionId | string | positionId |

Example

import { isValidFormatPosition } from '@janiscommerce/apps-helpers';
isValidFormatPosition({ positionKey: '001-D-01-1', positionId: '632b40c90adf68f197caa91f' }); // true
isValidFormatPosition({ positionKey: '001-D-01-1' }); // true
isValidFormatPosition({ positionId: '632b40c90adf68f197caa91f' }); // true
isValidFormatPosition({ positionKey: 123 }); // false
isValidFormatPosition({}); // false

isValidUrl(str) ⇒ boolean

Kind: global function
Returns: boolean - true or false

| Param | Type | | ----- | ------------------- | | str | string |

Example

isValidUrl('www.valid-url.com'); // true

Example

isValidUrl('invalid-url.com'); // false

Example

isValidUrl(); // false

promiseWrapper(fn) ⇒ array.<data, error>

Kind: global function

| Param | Type | | ----- | --------------------- | | fn | function |

Example

import { promiseWrapper } from '@janiscommerce/apps-helpers';
const [data, error] = await promiseWrapper(promise());