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

angular-helpers

v1.0.197

Published

helpers functions and utils for angular projects

Readme

exports.safeAngularApply = function (scope, callback, args) { if (!scope.$$phase && (scope.$rootScope ? !scope.$rootScope.$$phase : true)) { if (typeof callback !== "function") scope.$apply(); else if (args instanceof Array) callback.apply(scope, Array.prototype.slice.call(args)) else callback(); } else { setTimeout(function () { exports.safeAngularApply(scope, callback, args); }, 250); } }

exports.safeParseJson = function (str) { try { var p = JSON.parse(str); return p; } catch (e) { return str; } }

exports.getElemById = function (collection, by, id) { for (var i in collection) { if (collection[i][by] == id) return collection[i]; } return null; }

exports.checkNested = function (obj) { var args = Array.prototype.slice.call(arguments, 1);

for (var i = 0; i < args.length; i++) {
    if (!obj || !obj.hasOwnProperty(args[i])) {
        return false;
    }
    obj = obj[args[i]];
}
return true;

}

exports.detectIE = function () { var ua = window.navigator.userAgent;

var msie = ua.indexOf('MSIE ');
if (msie > 0) {
    // IE 10 or older => return version number
    return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
}

var trident = ua.indexOf('Trident/');
if (trident > 0) {
    // IE 11 => return version number
    var rv = ua.indexOf('rv:');
    return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
}

var edge = ua.indexOf('Edge/');
if (edge > 0) {
    // Edge (IE 12+) => return version number
    return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
}

// other browser
return null;

}

exports.addToQuerystring = function (query, paramName, paramValue) { if (!query) query = ""; var char = (query.indexOf("?") > -1) ? "&" : "?"; return query + char + paramName + "=" + paramValue; }

exports.removeFromQuerystring = function (url, parameter) { //prefer to use l.search if you have a location/link object var urlparts = url.split('?'); if (urlparts.length >= 2) {

    var prefix = encodeURIComponent(parameter) + '=';
    var pars = urlparts[1].split(/[&;]/g);

    //reverse iteration as may be destructive
    for (var i = pars.length; i-- > 0;) {
        //idiom for string.startsWith
        if (pars[i].lastIndexOf(prefix, 0) !== -1) {
            pars.splice(i, 1);
        }
    }

    url = urlparts[0] + (pars.length > 0 ? '?' + pars.join('&') : "");
    return url;
} else {
    return url;
}

}

exports.fromObjectToQuerystring = function (obj, prefix) { var str = []; for (var p in obj) { if (obj.hasOwnProperty(p)) { var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p]; str.push(typeof v == "object" ? serialize(v, k) : encodeURIComponent(k) + "=" + encodeURIComponent(v)); } } return str.join("&"); }

exports.extractDomainFromURL = function (url) { var a = document.createElement('a'); a.href = url; return a.hostname; }

exports.replaceAll = function (str, find, replace) { var escapeRegExp = function (str) { return str.replace(/[.*+?^${}()|[]\]/g, "\$&"); // $& means the whole matched string } return str.replace(new RegExp(escapeRegExp(find), 'g'), replace); }

exports.storage = { get: function (key) { var val = null; try { val = localStorage.getItem(key); return JSON.parse(val); } catch (e) { return val; } }, set: function (key, value) { var final = ''; if (typeof value === 'object') final = JSON.stringify(value); else final = value; try { localStorage.setItem(key, final); } catch (e) { } }, remove: function (key) { try { localStorage.removeItem(key); } catch (e) { } } }

exports.isParamExist = function (field, url) { url = url ? url : window.location.href; if (url.indexOf('?' + field + '=') != -1) return true; else if (url.indexOf('&' + field + '=') != -1) return true; return false };

exports.getReferrerByUrl = function (url) { var protocol = ''; if (url.indexOf('http:') == 0) protocol = 'http:'; else if (url.indexOf('https:') == 0) protocol = 'https:'; else protocol = window.location.protocol; url = url.replace(protocol, '').replace('//', ''); var indexOfSlash = url.indexOf('/'); if (indexOfSlash > -1) url = url.substring(0, indexOfSlash); return protocol + '//' + url; };

// https://davidwalsh.name/nested-objects exports.Objectifier = (function () {

// Utility method to get and set objects that may or may not exist
var objectifier = function (splits, create, context) {
    var result = context || window;
    for (var i = 0, s; result && (s = splits[i]); i++) {
        result = (s in result ? result[s] : (create ? result[s] = {} : undefined));
    }
    return result;
};

return {
    // Creates an object if it doesn't already exist
    set: function (name, value, context) {
        var splits = name.split('.'), s = splits.pop(), result = objectifier(splits, true, context);
        return result && s ? (result[s] = value) : undefined;
    },
    get: function (name, create, context) {
        return objectifier(name.split('.'), create, context);
    },
    exists: function (name, context) {
        return this.get(name, false, context) !== undefined;
    }
};

})();

// https://jsfiddle.net/Guffa/DDn6W/ exports.randomPassword = function (length) { if (!length) length = 6; var chars = "abcdefghijklmnopqrstuvwxyz!@#$%^&*()-+<>ABCDEFGHIJKLMNOP1234567890"; var pass = ""; for (var x = 0; x < length; x++) { var i = Math.floor(Math.random() * chars.length); pass += chars.charAt(i); } return pass; }