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

@d-cat/utility-api

v1.3.3

Published

Utility API that offers some frequently used methods within the @d-cat namespace.

Downloads

2

Readme

Getting started with @d-cat/utility-api

codecov

@d-cat/utility-api is an API that offers some frequently used methods within the @d-cat namespace.

Install

npm i @d-cat/utility-api

Usage

The API contains several helpers which helps you to develop tags and tag managers faster within the D-CAT framework.

cleanUrl({ url, trailingSlash = true, addFilterParams = [] }: { url:string, trailingSlash?: boolean, addFilterParams: string[] }): string

Clear the URL of some predefined PII.

import cleanUrl from '@d-cat/utility-api/clean-url';

const url = 'username=foo&password=bar&id=3';

cleanUrl(url);
// => id=3

cloneObject<T extends object>(obj: T): T

Deep clone the object.

import cloneObject from '@d-cat/utility-api/clone-object';

const obj = { foo: 'bar' }
const obj2 = cloneObject(obj);

obj2.baz = 'foobar'

console.log(obj)
// => { foo: 'bar' }

deletePropAtPath<T extends object>(path: string, obj: T): void

Delete a property in an object.

import dltProp from '@d-cat/utility-api/del-prop-at-path';

const obj = { foo: 'bar' }

dltProp('foo.bar', obj)

console.log(obj)
// => { }

getCookie(cookieName: string): string

Get a cookie by name.

import getCookie from '@d-cat/utility-api/get-cookie';

getCookie('myCookie')
// => myCookie

getDifferences (obj1:object, obj2: object): string[]

Get deep differences between 2 objects.

import getDiff from '@d-cat/utility-api/get-differences';

const obj = { foo: 'bar' };
const obj2 = { bar: { foobaz: 'baz'} }

getDiff(obj, obj2);
// => ['foo', 'bar', 'bar.foobaz']

getDocument(): Document

Get document.

import getDocument from '@d-cat/utility-api/get-document';

getDocument()
// => Document

getGlobal<T extends typeof globalThis | NodeJS.Global | Window>(): T

Get the global scope of the current environment.

import getGlobal from '@d-cat/utility-api/get-global';

interface IGlobal extends NodeJS.global {
    _ddm: { emit: Function }
}

const root = getGlobal<IGlobal>();
// => NodeJS.global & _ddm

getParam(sourceStr: string, param: string): string

Return value of parameter in a given string.

import getParam from '@d-cat/utility-api/get-param';

getParam('vodafone.nl?foo=bar', 'foo');
// => 'bar'

getPropAtPath<T>(path: string, obj?: object): T

Get a property at a dot notated path.

import getPropAtPath from '@d-cat/utility-api/get-prop-at-path';

const obj = { foo: { bar: 'baz' } };
getPropAtPath<string>('foo.bar', obj);
// => 'baz'

getRootDomain(): string

Get the domains root.

import getDomain from '@d-cat/utility-api/get-root-domain';

getDomain()
// => 'vodafoneziggo.com'

getSearchParams(): {[index:string]:any } | string

Returns an object with search parameters. It should be the Object.values equivalent of new URL().searchParams.

import getSearchParams from '@d-cat/utility-api/get-search-params';

getSearchParams('vodafone.nl?foo=bar&baz=foobar')
// => { foo: 'bar', baz: 'foobar' }

getWindow<T extends Window>(): T

Get window.

import getWindow from '@d-cat/utility-api/get-window';

getWindow()
// => Window

injectPixel(url: string): Promise<void>

Injects pixel in body.

import injectPixel from '@d-cat/utility-api/inject-pixel'

injectPixel.then( () => {
    // your logic
})

injectScript(url: string): Promise<void>

Injects script in head.

import injectScript from '@d-cat/utility-api/inject-script'

injectScript.then( () => {
    // your logic
})

isArray(arr: any): boolean

Checks whether a given object is in fact an Array.

import isArray from '@d-cat/utility-api/is-array'

isArray([])
// => true

isArray({})
// => false

isInteger(int: any): boolean

Checks whether a given value is an integer.

import isInteger from '@d-cat/utility-api/is-integer'

isInteger(1)
// => true

isInteger('1')
// => false

isObject(obj: any): boolean

Checks whether a given value is a real object.

import isObject from '@d-cat/utility-api/is-object'

isObject({})
// => true

isObject([])
// => false

isString(str: any): boolean

Checks whether a given value is a string.

import isString from '@d-cat/utility-api/is-string'

isString('string')
// => true

isString([])
// => false

mergeObjects<A extends object, B extends object>(dist: A, ...sources: B[]): Spread<A, B>

Merge objects into destination object.

import mergeObjects from '@d-cat/utility-api/merge-objects'

mergeObjects({}, {foo:1}, {bar: 2}, {baz: 3});
// => { bar: 2, baz: 3, foo: 1 }

setCookie({ name: string, value:any, days?: number, path?: string, domain?:string }): void

Set cookie.

import setCookie from '@d-cat/utility-api/set-cookie'

setCookie({ name: 'foo', value: 'bar' })
// => void

setPropAtPath<T>(path: string, value: T, obj: { [index: string]: any }): T

Set property in a dot notated path of an object.

import setPropAtPath from '@d-cat/utility-api/set-prop-at-path'

const obj = { foo: { bar: 'baz' } }
setPropAtPath({ path: 'foo.baz', value: 2, obj})
// => { foo: { bar: 'baz', baz: 2 } }

uuid(): string

Returns a uuid.

import uuid from '@d-cat/utility-api/create-uuid'

uuid()
// => xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx

Regex

The regex subdirectory contains a set of regex utility helpers.

hasCustomerId = (str:string): boolean

import { hasCustomerId } from '@d-cat/utility-api/regex'

hasCustomerId('klantnr: 1234')
// => true

replaceCustomerId = (str:string): string

import { replaceCustomerId } from '@d-cat/utility-api/regex'

replaceCustomerId('klantnr: 1234')
// => 'klanrnr: [MASKED_CUSTOMER_ID]'

hasPhoneNumber = (str:string): boolean

import { hasPhoneNumber } from '@d-cat/utility-api/regex'

hasPhoneNumber('0612345678')
// => true

replacePhoneNumber = (str:string): string

import { replacePhoneNumber } from '@d-cat/utility-api/regex'

replacePhoneNumber('0612345678')
// => '[MASKED_PHONENR]'

hasZipCode = (str:string): boolean

import { hasZipCode } from '@d-cat/utility-api/regex'

hasZipCode('1111 AA')
// => true

replaceZipCode = (str:string): string

import { replaceZipCode } from '@d-cat/utility-api/regex'

replaceZipCode('1111 AA')
// => '[MASKED_ZIPCODE]'

hasEmailAddress = (str:string): boolean

import { hasEmailAddress } from '@d-cat/utility-api/regex'

hasEmailAddress('[email protected]')
// => true

replaceEmailAddress = (str:string): string

import { replaceEmailAddress } from '@d-cat/utility-api/regex'

replaceEmailAddress('[email protected]')
// => '[MASKED_EMAIL]'

hasIBAN = (str:string): boolean

import { hasIBAN } from '@d-cat/utility-api/regex'

hasIBAN('NL00ABNA0000123456')
// => true

replaceIBAN = (str:string): string

import { replaceIBAN } from '@d-cat/utility-api/regex'

replaceIBAN('NL00ABNA0000123456')
// => '[MASKED_IBAN]'