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

ng-lollipop

v0.5.4

Published

Normalize HTTP requests for Angular applications

Downloads

2

Readme

ng-lollipop

Normalize HTTP requests for Angular applications

By default, Angular posts data as JSON, which is often not what you want. Also, data received as JSON needs some massaging (date to actual Date objects, numbers to actual Number objects etc.). This package handles all that for you.

Installation

Via NPM (recommended):

npm install --save ng-lollipop

Include the package in your application. This can be done via a tool like Browserify (recommended) or by simply adding a <script> tag pointing to the location where you installed it.

Add it as a dependency for your Angular application:

var app = angular.module('myAwesomeProject', ['lollipop']);

Registering the helpers

Lollipop exposes two main services: postRegularForm to replace JSON posts with normal urlencoded data strings, and normalizeIncomingHttpData to massage the received data. You'll need to inject them once in your application for them to take effect (since you might want to use just one of them):

app.run(['postRegularForm', 'normalizeIncomingHttpData', function (a, b) {
    // We're not using `a` and `b`, we just need them to be injected.
}]);

Normalizing data from non-HTTP sources

Since you might get your data from other sources (e.g. a Socket server), Lollipop also offers a more low level normalizeData service. You might for instance need to do something like this:

app.factory('Socket', ['SocketFactory', 'normalizeData', function (SocketFactory, normalizeData) {
    var socket = socketFactory({ioSocket: window.io.connect('')});
    var on = socket.on;
    socket.on = function (event, callback) {
        on.call(socket, event, function (data) {
            callback(normalizeData(data));
        });
    };
}]);

Handling alternative date formats

Out of the box, Lollipop recognizes date strings in a format compatible with most RMDBSs. Of course, your source might be a bit more exotic. There are a number of pluggable helpers you can modify to account for that:

The dateRegexes value

Lollipop defines a dateRegexes Angular value which you can override. It is simply an array of patterns to check. The first pattern matched gets returned (with index 0, the full match, already removed). The default implementation assumes that the date parts are "in order", i.e. they are passed directly to the Date constructor.

The dateCallbacks service

An object where each key matching the index in the matched date is called if present. The default implementation is to only offset key 1 by -1 since Javascript months are 0-indexed.

The convertValueToDate factory

Returns a function which converts matched date parts into a Date object. If your date parts are in a "weird" order, override this.

The isValueDate factory

This you'll rarely need to override; it loops through the dateRegexes array and applies dateCallbacks for defined keys.