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

ng2-device-detector

v1.0.1

Published

**<span style="color:#f45252">`ng2-device-detector` has been deprecated.</span> Please use the new package [`ngx-device-detector`](https://www.npmjs.com/package/ngx-device-detector)**

Downloads

1,473

Readme

DEPRECATED

ng2-device-detector has been deprecated. Please use the new package ngx-device-detector

ng2-device-detector (DEPRECATED)

npm version npm downloads npm GitHub stars npm

An Angular 2 (and beyond) powered AOT compatible device detector that helps to identify browser, os and other useful information regarding the device using the app. The processing is based on user-agent.

Breaking changes in 1.0.0

The module name and the service name has been changed. See the Usage and Change Log sections below

Live DEMO

Ng2 Device Detector Demo

Installation

To install this library, run:

$ npm install ng2-device-detector --save

Usage

Import Ng2DeviceDetectorModule in your app.module.ts

  import { NgModule } from '@angular/core';
  import { Ng2DeviceDetectorModule } from 'ng2-device-detector';
  ...
  @NgModule({
    declarations: [
      ...
      LoginComponent,
      SignupComponent
      ...
    ],
    imports: [
      CommonModule,
      FormsModule,
      Ng2DeviceDetectorModule.forRoot()
    ],
    providers:[
      AuthService
    ]
    ...
  })

In your component where you want to use the Device Service

  import { Component } from '@angular/core';
  ...
  import { Ng2DeviceService } from 'ng2-device-detector';
  ...
  @Component({
    selector: 'home',  // <home></home>
    styleUrls: [ './home.component.scss' ],
    templateUrl: './home.component.html',
    ...
  })

  export class HomeComponent {
    deviceInfo = null;
    ...
    constructor(..., private http: Http, private deviceService: Ng2DeviceService) {
      this.epicFunction();
    }
    ...
    epicFunction() {
      console.log('hello `Home` component');
      this.deviceInfo = this.deviceService.getDeviceInfo();
      console.log(this.deviceInfo);
    }
    ...
  }

Device service

Holds the following properties

  • browser
  • os
  • device
  • userAgent
  • os_version

Development

To generate all *.js, *.js.map and *.d.ts files:

  $ npm run tsc

To lint all *.ts files:

  $ npm run lint

To run unit tests

  $ npm run test

To build the library

  $ npm run build

Run the DEMO

Make sure you have @angular/cli installed

  $ npm install -g @angular/cli
  $ cd demo
  $ npm install
  $ ng serve

the demo will be up at localhost:4200

Credits

The library is inspired by and based on the work from ng-device-detector . Also used a typescript wrapper of the amazing work in ReTree for regex based needs and an Angular2 Library Creator boilerplate to get the work started fast. I.e. Generator Angular2 library.

License

MIT © Ahsan Ayaz

Change Log

#1.0.0

  • Renamed the Service from Device to Ng2DeviceService
  • Renamed the Module from Ng2DeviceDetector to Ng2DeviceDetectorModule
  • Import has changed from imports: [Ng2DeviceDetectorModule] to imports: [Ng2DeviceDetectorModule.forRoot()]