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

ngx-common

v1.0.3

Published

Common functions to be used for React, Angular and Node.js

Downloads

4

Readme

NGX COMMON lt;dr Common JS/TS functions

This repository is a set of functions that might be useful during developing JavaScript applications.

Installing

You can install this repository from npm:

npm install ngx-common --save

Map/Geographical functions

Here you can see most of the public available functions and classes.

FindBoundsCenter

Finds a center position inside a map, a rectangular area. Can be useful to put a marker in middle of a map which user can see.

import { FindBoundsCenter } from 'ngx-common/maps';

Example:

import { MapBounds, FindBoundsCenter } from 'ngx-common/maps';

const bounds: MapBounds = {
  b: {
    b: 100,
    f: 500
  },
  f: {
    b: 500,
    f: 100
  }
};

test('FindBoundsCenter must return a point in center', function () {
  const center = FindBoundsCenter(bounds);
  expect(center.lat).toBe(300);
  expect(center.lng).toBe(300);
});

FindInnerRandomPosition

Finds a random position inside a rectangular area. In case you want to mock some maps, you can use this function to create a randomly marker for map (google map, etc)

Usage:

import { MapBounds, FindInnerRandomPosition } from 'ngx-common/maps';

Please review the package tests, in order to see how it's being tested and worked in action.

Routing and mocking

In many applications, we are working with webservers. It's totally invauable to make mock data before the api being ready. The reason is, many application are being developed by different teams so you are not relaying on other people work to be ready. Besides, your application works without being dependent on another package partially or simulated.

We are giving a set of functions to integrate these kind of implementations easier.

GetMatchRoute

Finds specific route in your routes which is compatible with user requsted url. Let's specify your routes in an array:

const routes: Array<HttpRoute> = [
  {
    url: '/api/users',
    method: 'GET'
  },
  {
    url: '/api/user',
    method: 'POST'
  },
  {
    url: '/api/user/:id',
    method: 'GET'
  }
];

Now, when user asks for `/api/user/313' how can you find out which url is being requsted? User id is different from each request. So if you want to implement this more smoothly and more real, you need to detect this.

const $search: HttpRoute = { url: '/api/user', method: 'POST'};
const $match = GetMatchRoute($search, routes);
expect($match.method).toBe($search.method);
});