Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nativescript-dna-deviceinfo

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nativescript-dna-deviceinfo

NativeScript plugin to acquire device information.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
600
decreased by-9.5%
Maintainers
1
Weekly downloads
 
Created
Source

NativeScript DNA Device Info

nativescript-dna-deviceinfo

NativeScript plugin to acquire device info.

Features

  • Cross-platform APIs for Android and iOS.
  • Offers APIs to obtain device related info.

Installation

From the command prompt, go to your app's root folder and execute:

tns plugin add nativescript-dna-deviceinfo

This command automatically installs the necessary files, as well as stores nativescript-dna-deviceinfo as a dependency in your project's package.json file.

Import / require

Various device related utility APIs are accessible from the DeviceInfo class. To import the class, use one of the following forms:

TypeScript:

import { DeviceInfo } from 'nativescript-dna-deviceinfo';

JavaScript:

const nativescript_dna_deviceinfo = require("nativescript-dna-deviceinfo");
const DeviceInfo = nativescript_dna_deviceinfo.DeviceInfo;

APIs

- totalMemory

Retrieves total memory(RAM) size in bytes.

- freeMemory

Retrieves available free memory(RAM) size in bytes.

- totalStorageSpace

Retrieves total storage(internal) space in bytes.

- freeStorageSpace

Retrieves free storage(internal) space in bytes.

- deviceId

Retrieves device ID.

- deviceName

Retrieves the device name.

- deviceLocale

Retrieves the device configured locale.

- deviceCountry

Retrieves the device country.

- timezone

Retrieves the device time zone.

- userAgent

Retrieves the device user agent.

- appName

Retrieves the app name.

- appVersion

Retrieves the app version.

- bundleId

Retrieves the app bundle id.

- bundleNumber

Retrieves the app bundle number.

- systemManufacturer

Retrieves the device manufacturer.

- isTablet

Returns 'true' if the device is tablet, otherwise 'false'.

- is24Hour

Returns 'true' if the device configured to 24-hour clock, otherwise 'false'.

- isEmulator

Returns 'true' if the app is running on emulator, otherwise 'false'.

APIs in Action

  printDeviceInfo() { 
    console.log("Free memory: ", formatBytes(DeviceInfo.freeMemory()));
    console.log("Total memory: ", formatBytes(DeviceInfo.totalMemory()));
    console.log("Total storage space: ", formatBytes(DeviceInfo.totalStorageSpace()));
    console.log("Free storage space: ",formatBytes(DeviceInfo.freeStorageSpace()));
    console.log("Device id: ", DeviceInfo.deviceId());
    console.log("Device name: ",  DeviceInfo.deviceName());
    console.log("Device locale: ", DeviceInfo.deviceLocale());
    console.log("Device country: ", DeviceInfo.deviceCountry());
    console.log("Device timezone: ", DeviceInfo.timezone());
    console.log("Device user agent: ", DeviceInfo.userAgent());
    console.log("App name: ", DeviceInfo.appName());
    console.log("App version: ", DeviceInfo.appVersion());
    console.log("App bundle id: ", DeviceInfo.bundleId());
    console.log("App bundle number: ", DeviceInfo.bundleNumber());
    console.log("System manufacturer: ",  DeviceInfo.systemManufacturer());
    console.log("Is tablet: ", DeviceInfo.isTablet());
    console.log("Is 24 hour: ", DeviceInfo.is24Hour());
    console.log("Is emulator: ", DeviceInfo.isEmulator());
  }

  formatBytes(bytes, decimals) {
    if (bytes === 0) return '0 GB'
    if (isNaN(parseInt(bytes))) return bytes
    if (typeof bytes === 'string') bytes = parseInt(bytes)
    if (bytes === 0) return '0';
    const k = 1000;
    const dm = decimals + 1 || 3;
    const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
    const i = Math.floor(Math.log(bytes) / Math.log(k));
    return `${parseFloat((bytes / k ** i).toFixed(dm))} ${sizes[i]}`;
  }

License

MIT license (see LICENSE file)

Keywords

FAQs

Package last updated on 01 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc