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

docomo-utils

v1.3.0

Published

set of utilities function

Downloads

19

Readme

docomo-utils.js

A set of utilities function for docomo products. Exports as Javascript Universal Module Definition (UMD)

Import in html

// Specific range version
<script src="https://unpkg.com/docomo-utils@^1.2.0/dist/docomo-utils.min.js"></script>
//Last version
<script src="https://unpkg.com/docomo-utils/dist/docomo-utils.min.js"></script>
<script type="text/javascript">
    var settings = window.docomoUtils.merge({a:1}, {b:2}); // => { a:1, b:2 }
</script>

Import in CommonJS style

npm install docomot-utils
import docomoUtils from 'docomo-utils';
//OR
import { queryfy, dequeryfy, merge, JSONPRequest } from 'docomo-utils';

API

Iterator

Iterator

Parameters

  • array Array the array you want to transform in iterator

Examples

var myArray = ["pippo", "pluto", "paperino"];
var it = Iterator(myArray);
it.next().value === "pippo"; //true
it.next().value === "pluto"; //true
it.next(true).value === "paperino" //false because with true you can reset it!

Returns Object an iterator-like object

debounce

Debounce. Wait ms to execute a function

Parameters

  • fn Function the function to be wrapped
  • ms Number the number of ms to wait (optional, default 300)
  • immediate Boolean execute immediate and wait ms. If false only the last call
  • scope Object the this object. default is this-generated function (optional, default this)

Returns Function returns the function decorated

throttle

Throttle. Useful for resize event or scroll

Parameters

  • fn Function the function to be wrapped
  • limit Number only x call for ms (optional, default 300)
  • scope Object the this object. default to this-generated function (optional, default this)

Returns Function returns the function decorated

JSONPRequest

Make a jsonp request, remember only GET The function create a tag script and append a callback param in querystring. The promise will be reject after 3s if the url fail to respond

Parameters

  • url String the url with querystring but without &callback at the end or &function
  • timeout Number ms range for the response (optional, default 3000)

Examples

const request = new JSONPRequest("http://www.someapi.com/asd?somequery=1");
request.promise.then((data) => {});
request.prom.then((data) => {});

Returns Promise<(Object | String)>

getType

getType

Parameters

  • obj

Returns string the type of the object. date for date array etc

memoize

Simple memoization function. A memoizated function cache the results of a function computation when it receives the same params

Parameters

  • fn Function the function to memoize
  • deps Function should returns an array with dependencies
  • scope Object the this object. default to this-generated function (optional, default this)

Examples

function Person(){
this.name = 'aldo';
this.surname = 'baglio';
};

Person.prototype.getFullName = function(title) {
var _title = title ? title : '';
return _title + this.name + ' ' + this.surname;
};

var person = new Person();
//remember to bind it
var memoized = memoize(person.getFullName, function(){ return [this.name, this.surname];}.bind(person), person);

Returns any what the real function returns

merge

Merge n objects

Parameters

  • N ...Object object to merge together

Returns Object

extend

extend: this function merge two objects in a new one with the properties of both

Parameters

Returns Object a brand new object results of the merging

queryfy

A function to compose query string

Parameters

  • _api Strinq the endpoint
  • query Object a key value object: will be append to ?key=value&key2=value2

Examples

var API = "http://jsonplaceholder.typicode.com/comments"
var url = queryfy(API, {postId:1});
// url will be "http://jsonplaceholder.typicode.com/comments?postId=1"

Returns String the string composed

dequeryfy

A function to dequerify query string

Parameters

  • _url Strinq

Examples

var url = "http://jsonplaceholder.typicode.com/comments?postId=1"
var obj = dequeryfy(url); //obj is {"postId":"1"}

Returns Object the object with key-value pairs, empty if no querystring is present

addEvent

Cross browsing addEvent

Parameters

Returns HTMLElement

isLocalStorageSupported

Check if local storage is supported

Returns Boolean

checkObject

Check if the object has the nested keys list

Parameters

  • object Object the object to be checked
  • keys (Array | String) a string point separated or a list of string keys
  • defaultReturn any (optional, default null)

Examples

checkObject({a:{b:[1,2,3]}}, ["a", "b", 2])); // returns 3
checkObject({a:{b:[1,2,3]}}),"a.b.0"); // returns the b[0]

Returns (any | null) returns any value for that key or null if the key is undefined

arrayContains

Returns true if the first array is contained in the second one.

Parameters

Examples

arrayContains([1,2,3] [4,5,6,1,2,3]) // true
Works even with array of objects and string

Returns Boolean

setFingerPrint

setFingerPrint

Parameters

  • Config object the vhost configuration
  • pony string the token of the logged user
  • returnUrl string the url where to return once relogged

Returns Promise

contents_inapp

God forgive them because they don't know what they do

ponyToken

generatePony

Parameters

  • Config object the vhost configuration
  • options object - (optional, default {return_url:''})

Returns Promise<String> the pony string

readCookies

Read the cookies in document.cookie string

Parameters

  • cookies string the document.cookie string in this format key=val;

Returns object the cookies as object key value pairs