nativescript-dna-deviceinfo
Advanced tools
+1
-1
| { | ||
| "name": "nativescript-dna-deviceinfo", | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "description": "NativeScript plugin to acquire device information.", | ||
@@ -5,0 +5,0 @@ "main": "deviceinfo", |
+37
-0
@@ -114,4 +114,41 @@ | ||
| ## APIs in Action | ||
| ```javascript | ||
| 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) |
30028
6.01%154
31.62%