MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / getNumber

Function getNumber

packages/core/application-settings/index.android.ts:50–72  ·  view source on GitHub ↗
(key: string, defaultValue?: number)

Source from the content-addressed store, hash-verified

48}
49
50export function getNumber(key: string, defaultValue?: number): number {
51 if (!verify(key)) {
52 return;
53 }
54 if (hasKey(key)) {
55 let val;
56
57 // TODO: Remove this migration step in a future release
58 try {
59 val = sharedPreferences.getLong(key, long(0));
60 } catch (err) {
61 // If value is old, it might have been stored as a float so we store it anew as a long value to avoid errors
62 const oldVal = sharedPreferences.getFloat(key, float(0.0));
63 setNumber(key, oldVal);
64
65 val = sharedPreferences.getLong(key, long(0));
66 }
67 // SharedPreferences has no getter or setter for double so we retrieve value as a long and convert it to double
68 return java.lang.Double.longBitsToDouble(val);
69 }
70
71 return defaultValue;
72}
73
74// setters
75export function setBoolean(key: string, value: boolean): void {

Callers

nothing calls this directly

Calls 3

verifyFunction · 0.85
hasKeyFunction · 0.70
setNumberFunction · 0.70

Tested by

no test coverage detected