noibu-react-native 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,41 @@
1
+ /** @module Object */
2
+ type Func = (...args: any[]) => any;
3
+ /**
4
+ * Replaces an attribute value found in an object with another value
5
+ * sourceObject: source object whose attribute will get replaced
6
+ * attributeName: the attribute key whose value will be replace
7
+ * processingFunction: function that accepts the original value
8
+ * and returns the newValue
9
+ * @param {} sourceObject
10
+ * @param {} attributeName
11
+ * @param {} processingFunction
12
+ */
13
+ export declare const replace: <A extends { [k in K]: Func; }, K extends keyof A>(sourceObject: A, attributeName: K, processingFunction: (arg: A[K]) => A[K]) => void;
14
+ /**
15
+ * unwraps wrapped property, so we can use it without side effects
16
+ * @param anything
17
+ */
18
+ export declare function unwrapNoibuWrapped<T>(anything: {
19
+ __noibu_original__?: T;
20
+ } & T): NonNullable<T>;
21
+ /**
22
+ * Checks whether the prototype's property is writeable. If it is not,
23
+ * checks whether the property can be made writeable. If it can, it is
24
+ * set to writeable.
25
+ * @param {object} proto
26
+ * @param {string} property
27
+ * @returns {boolean} Whether the property on the prototype is (or is now) writeable
28
+ */
29
+ export declare const propWriteableOrMadeWriteable: (proto: object, property: never) => boolean;
30
+ /**
31
+ * Iterates object recursively and calls visit function
32
+ * for each property allowing to override its value
33
+ * @param {Object} instance An object to iterate through
34
+ * @param {Function} visit A callback function that is called for each property
35
+ * There are 3 arguments: current object, current property and its value
36
+ * @param {{depth: number}} limit Use limit config object to set depth of the recursion
37
+ */
38
+ export declare const iterateObjectRecursively: (instance: Record<any, any>, visit: (i: Record<any, any>, p: any, v: any) => any, limit?: {
39
+ depth: number;
40
+ }) => void;
41
+ export {};
@@ -10,39 +10,43 @@
10
10
  * @param {} processingFunction
11
11
  */
12
12
  const replace = (sourceObject, attributeName, processingFunction) => {
13
- if (!(attributeName in sourceObject)) {
14
- return;
15
- }
16
-
17
- const originalAttribute = sourceObject[attributeName];
18
- const newValue = processingFunction(originalAttribute);
19
-
20
- if (typeof newValue === 'function') {
21
- try {
22
- newValue.prototype = newValue.prototype || {};
23
- Object.defineProperties(newValue, {
24
- __noibu__: {
25
- enumerable: false,
26
- value: true,
27
- },
28
- __noibu_original__: {
29
- enumerable: false,
30
- value: originalAttribute,
31
- },
32
- __noibu_wrapped__: {
33
- enumerable: false,
34
- value: newValue,
35
- },
36
- });
37
- } catch (err) {
38
- // silent fail
13
+ if (!(attributeName in sourceObject)) {
14
+ return;
39
15
  }
40
- }
41
-
42
- // eslint-disable-next-line no-param-reassign
43
- sourceObject[attributeName] = newValue;
16
+ const originalAttribute = sourceObject[attributeName];
17
+ const newValue = processingFunction(originalAttribute);
18
+ if (typeof newValue === 'function') {
19
+ try {
20
+ newValue.prototype = newValue.prototype || {};
21
+ Object.defineProperties(newValue, {
22
+ __noibu__: {
23
+ enumerable: false,
24
+ value: true,
25
+ },
26
+ __noibu_original__: {
27
+ enumerable: false,
28
+ value: originalAttribute,
29
+ },
30
+ __noibu_wrapped__: {
31
+ enumerable: false,
32
+ value: newValue,
33
+ },
34
+ });
35
+ }
36
+ catch (err) {
37
+ // silent fail
38
+ }
39
+ }
40
+ // eslint-disable-next-line no-param-reassign
41
+ sourceObject[attributeName] = newValue;
44
42
  };
45
-
43
+ /**
44
+ * unwraps wrapped property, so we can use it without side effects
45
+ * @param anything
46
+ */
47
+ function unwrapNoibuWrapped(anything) {
48
+ return anything.__noibu_original__ || anything;
49
+ }
46
50
  /**
47
51
  * Checks whether the prototype's property is writeable. If it is not,
48
52
  * checks whether the property can be made writeable. If it can, it is
@@ -52,50 +56,29 @@ const replace = (sourceObject, attributeName, processingFunction) => {
52
56
  * @returns {boolean} Whether the property on the prototype is (or is now) writeable
53
57
  */
54
58
  const propWriteableOrMadeWriteable = (proto, property) => {
55
- if (
56
- !proto ||
57
- !proto.hasOwnProperty ||
58
- !Object.prototype.hasOwnProperty.call(proto, property)
59
- ) {
60
- return false;
61
- }
62
-
63
- // Getting the properties that this the prototype
64
- // has under the open property
65
- const propDescriptor = Object.getOwnPropertyDescriptor(proto, property);
66
-
67
- // Checking if the open property is read-only
68
- if (!propDescriptor.writable) {
69
- // Checking if we can write to it
70
- if (propDescriptor.configurable) {
71
- // Making it writable to wrap it
72
- Object.defineProperty(proto, property, {
73
- writable: true,
74
- });
75
- } else {
76
- return false;
59
+ if (!proto ||
60
+ !proto.hasOwnProperty ||
61
+ !Object.prototype.hasOwnProperty.call(proto, property)) {
62
+ return false;
77
63
  }
78
- }
79
- return true;
80
- };
81
-
82
- /**
83
- * Replaces the behaviour of Object.fromEntries() as it is not supported on all browsers
84
- * @param {Iterable} entries The iterable to parse into an object
85
- * @returns An object containing the same key/values as the iterable passed
86
- */
87
- const safeFromEntries = entries => {
88
- if (!entries || !entries[Symbol.iterator]) {
89
- throw new Error('Object.fromEntries() requires a single iterable argument');
90
- }
91
- const obj = {};
92
- // eslint-disable-next-line no-restricted-syntax
93
- for (const [key, value] of entries) {
94
- obj[key] = value;
95
- }
96
- return obj;
64
+ // Getting the properties that this the prototype
65
+ // has under the open property
66
+ const propDescriptor = Object.getOwnPropertyDescriptor(proto, property);
67
+ // Checking if the open property is read-only
68
+ if (!propDescriptor?.writable) {
69
+ // Checking if we can write to it
70
+ if (propDescriptor?.configurable) {
71
+ // Making it writable to wrap it
72
+ Object.defineProperty(proto, property, {
73
+ writable: true,
74
+ });
75
+ }
76
+ else {
77
+ return false;
78
+ }
79
+ }
80
+ return true;
97
81
  };
98
-
99
82
  /**
100
83
  * Iterates object recursively and calls visit function
101
84
  * for each property allowing to override its value
@@ -104,41 +87,35 @@ const safeFromEntries = entries => {
104
87
  * There are 3 arguments: current object, current property and its value
105
88
  * @param {{depth: number}} limit Use limit config object to set depth of the recursion
106
89
  */
107
- const iterateObjectRecursively = (
108
- instance,
109
- visit,
110
- limit = { depth: 5 },
111
- ) => {
112
- /* eslint-disable no-shadow, no-restricted-syntax, no-param-reassign, guard-for-in */
113
- /**
114
- * internal recursive function
115
- * @param {Object} instance Current object
116
- * @param {Number} depth Current depth
117
- */
118
- const iterate = (instance, depth) => {
119
- // stop to go deeper if it is deep enough already
120
- if (depth > limit.depth) return;
121
- for (const property in instance) {
122
- try {
123
- // call visit function and assign its result if not undefined
124
- const newValue = visit(instance, property, instance[property]);
125
- if (newValue !== undefined) {
126
- instance[property] = newValue;
127
- }
128
- // go one level deeper if it is an object
129
- if (
130
- instance[property] !== null &&
131
- typeof instance[property] === 'object'
132
- ) {
133
- iterate(instance[property], depth + 1);
90
+ const iterateObjectRecursively = (instance, visit, limit = { depth: 5 }) => {
91
+ /* eslint-disable no-shadow, no-restricted-syntax, no-param-reassign, guard-for-in */
92
+ /**
93
+ * internal recursive function
94
+ * @param {Object} inst Current object
95
+ * @param {Number} depth Current depth
96
+ */
97
+ const iterate = (inst, depth) => {
98
+ // stop to go deeper if it is deep enough already
99
+ if (depth > limit.depth)
100
+ return;
101
+ for (const property in inst) {
102
+ try {
103
+ // call visit function and assign its result if not undefined
104
+ const newValue = visit(inst, property, inst[property]);
105
+ if (newValue !== undefined) {
106
+ inst[property] = newValue;
107
+ }
108
+ // go one level deeper if it is an object
109
+ if (inst[property] !== null && typeof inst[property] === 'object') {
110
+ iterate(inst[property], depth + 1);
111
+ }
112
+ }
113
+ catch (e) {
114
+ // just continue to the next property
115
+ }
134
116
  }
135
- } catch (e) {
136
- // just continue to the next property
137
- }
138
- }
139
- };
140
-
141
- iterate(instance, 1);
117
+ };
118
+ iterate(instance, 1);
142
119
  };
143
120
 
144
- export { iterateObjectRecursively, propWriteableOrMadeWriteable, replace, safeFromEntries };
121
+ export { iterateObjectRecursively, propWriteableOrMadeWriteable, replace, unwrapNoibuWrapped };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Wrapper function for window.performance.now() to ensure
3
+ * it's available before calling it. If it's not available,
4
+ * we return Date.now() instead.
5
+ */
6
+ export declare function safePerformanceNow(): any;
@@ -1,14 +1,13 @@
1
1
  import { timestampWrapper } from './date.js';
2
2
 
3
3
  /** @module Performance */
4
-
5
4
  /**
6
5
  * Wrapper function for window.performance.now() to ensure
7
6
  * it's available before calling it. If it's not available,
8
7
  * we return Date.now() instead.
9
8
  */
10
9
  function safePerformanceNow() {
11
- return timestampWrapper(Date.now());
10
+ return timestampWrapper(Date.now());
12
11
  }
13
12
 
14
13
  export { safePerformanceNow };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "noibu-react-native",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "targetNjsVersion": "1.0.104",
5
5
  "description": "React-Native SDK for NoibuJS to collect errors in React-Native applications",
6
6
  "main": "dist/entry/index.js",
@@ -1,9 +0,0 @@
1
- var blacklisedDomains = {
2
- 'input.noibu.com': true,
3
- 'input.staging.noibu.com': true,
4
- 'vf.noibu.com': true,
5
- 'vf.staging.noibu.com': true,
6
- 'cdn.noibu.com': true,
7
- };
8
-
9
- export { blacklisedDomains as default };