io.appium.settings 7.0.7 → 7.0.9

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.
@@ -2,86 +2,21 @@
2
2
  * The code below has been adopted from https://www.npmjs.com/package/utf7
3
3
  */
4
4
 
5
- /**
6
- * @param {number} length
7
- * @returns {Buffer}
8
- */
9
- function allocateAsciiBuffer(length) {
10
- return Buffer.alloc(length, 'ascii');
11
- }
12
-
13
- /**
14
- * @param {string} str
15
- * @returns {string}
16
- */
17
- function _encode(str) {
18
- const b = allocateAsciiBuffer(str.length * 2);
19
- for (let i = 0, bi = 0; i < str.length; i++) {
20
- // Note that we can't simply convert a UTF-8 string to Base64 because
21
- // UTF-8 uses a different encoding. In modified UTF-7, all characters
22
- // are represented by their two byte Unicode ID.
23
- const c = str.charCodeAt(i);
24
- // Upper 8 bits shifted into lower 8 bits so that they fit into 1 byte.
25
- b[bi++] = c >> 8;
26
- // Lower 8 bits. Cut off the upper 8 bits so that they fit into 1 byte.
27
- b[bi++] = c & 0xFF;
28
- }
29
- // Modified Base64 uses , instead of / and omits trailing =.
30
- return b.toString('base64').replace(/=+$/, '');
31
- }
32
-
33
- /**
34
- * @param {string} str
35
- * @returns {Buffer}
36
- */
37
- function allocateBase64Buffer(str) {
38
- return Buffer.from(str, 'base64');
39
- }
40
-
41
- /**
42
- * @param {string} str
43
- * @returns {string}
44
- */
45
- function _decode(str) {
46
- const b = allocateBase64Buffer(str);
47
- const r = [];
48
- for (let i = 0; i < b.length;) {
49
- // Calculate charcode from two adjacent bytes.
50
- r.push(String.fromCharCode(b[i++] << 8 | b[i++]));
51
- }
52
- return r.join('');
53
- }
54
-
55
- /**
56
- * Escape RegEx from http://simonwillison.net/2006/Jan/20/escape/
57
- *
58
- * @param {string} chars
59
- * @returns {string}
60
- */
61
- function escape(chars) {
62
- return chars.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
63
- }
64
-
65
5
  // Character classes defined by RFC 2152.
66
6
  const setD = 'A-Za-z0-9' + escape(`'(),-./:?`);
67
7
  const setO = escape(`!"#$%&*;<=>@[]^_'{|}`);
68
8
  const setW = escape(` \r\n\t`);
69
9
 
70
10
  // Stores compiled regexes for various replacement pattern.
71
- /** @type {Record<string, RegExp>} */
72
- const regexes = {};
11
+ const regexes: Record<string, RegExp> = {};
73
12
  const regexAll = new RegExp(`[^${setW}${setD}${setO}]+`, 'g');
74
13
 
75
- export const imap = {};
76
-
77
14
  /**
78
15
  * RFC 2152 UTF-7 encoding.
79
16
  *
80
- * @param {string} str
81
- * @param {string?} mask
82
- * @returns {string}
17
+ * @param mask Optional mask characters to exclude from encoding
83
18
  */
84
- export const encode = function encode(str, mask = null) {
19
+ export const encode = function encode(str: string, mask: string | null = null): string {
85
20
  // Generate a RegExp object from the string of mask characters.
86
21
  if (!mask) {
87
22
  mask = '';
@@ -99,11 +34,10 @@ export const encode = function encode(str, mask = null) {
99
34
 
100
35
  /**
101
36
  * RFC 2152 UTF-7 encoding with all optionals.
102
- *
103
- * @param {string} str
104
- * @returns {string}
37
+ * Encodes all non-ASCII characters, including those that would normally
38
+ * be represented directly in standard UTF-7 encoding.
105
39
  */
106
- export function encodeAll(str) {
40
+ export function encodeAll(str: string): string {
107
41
  // We replace subsequent disallowed chars with their escape sequence.
108
42
  return str.replace(regexAll, (chunk) =>
109
43
  // + is represented by an empty sequence +-, otherwise call encode().
@@ -111,44 +45,91 @@ export function encodeAll(str) {
111
45
  );
112
46
  }
113
47
 
114
- /**
115
- * RFC 3501, section 5.1.3 UTF-7 encoding.
116
- *
117
- * @param {string} str
118
- * @returns {string}
119
- */
120
- imap.encode = function encode(str) {
121
- // All printable ASCII chars except for & must be represented by themselves.
122
- // We replace subsequent non-representable chars with their escape sequence.
123
- return str.replace(/&/g, '&-').replace(/[^\x20-\x7e]+/g, (chunk) => {
124
- // & is represented by an empty sequence &-, otherwise call encode().
125
- chunk = (chunk === '&' ? '' : _encode(chunk)).replace(/\//g, ',');
126
- return `&${chunk}-`;
127
- });
128
- };
129
-
130
48
  /**
131
49
  * RFC 2152 UTF-7 decoding.
132
- *
133
- * @param {string} str
134
- * @returns {string}
135
50
  */
136
- export const decode = function decode(str) {
51
+ export const decode = function decode(str: string): string {
137
52
  return str.replace(/\+([A-Za-z0-9/]*)-?/gi, (_, chunk) =>
138
53
  // &- represents &.
139
54
  chunk === '' ? '+' : _decode(chunk)
140
55
  );
141
56
  };
142
57
 
58
+ export const imap = {
59
+ /**
60
+ * RFC 3501, section 5.1.3 UTF-7 encoding.
61
+ */
62
+ encode(str: string): string {
63
+ // All printable ASCII chars except for & must be represented by themselves.
64
+ // We replace subsequent non-representable chars with their escape sequence.
65
+ return str.replace(/&/g, '&-').replace(/[^\x20-\x7e]+/g, (chunk) => {
66
+ // & is represented by an empty sequence &-, otherwise call encode().
67
+ chunk = (chunk === '&' ? '' : _encode(chunk)).replace(/\//g, ',');
68
+ return `&${chunk}-`;
69
+ });
70
+ },
71
+
72
+ /**
73
+ * RFC 3501, section 5.1.3 UTF-7 decoding.
74
+ */
75
+ decode(str: string): string {
76
+ return str.replace(/&([^-]*)-/g, (_, chunk) =>
77
+ // &- represents &.
78
+ chunk === '' ? '&' : _decode(chunk.replace(/,/g, '/'))
79
+ );
80
+ },
81
+ };
82
+
143
83
  /**
144
- * RFC 3501, section 5.1.3 UTF-7 decoding.
145
- *
146
- * @param {string} str
147
- * @returns {string}
84
+ * Allocates an ASCII buffer of the specified length.
148
85
  */
149
- imap.decode = function decode(str) {
150
- return str.replace(/&([^-]*)-/g, (_, chunk) =>
151
- // &- represents &.
152
- chunk === '' ? '&' : _decode(chunk.replace(/,/g, '/'))
153
- );
154
- };
86
+ function allocateAsciiBuffer(length: number): Buffer {
87
+ return Buffer.alloc(length, 'ascii');
88
+ }
89
+
90
+ /**
91
+ * Encodes a string using modified UTF-7 encoding.
92
+ */
93
+ function _encode(str: string): string {
94
+ const b = allocateAsciiBuffer(str.length * 2);
95
+ for (let i = 0, bi = 0; i < str.length; i++) {
96
+ // Note that we can't simply convert a UTF-8 string to Base64 because
97
+ // UTF-8 uses a different encoding. In modified UTF-7, all characters
98
+ // are represented by their two byte Unicode ID.
99
+ const c = str.charCodeAt(i);
100
+ // Upper 8 bits shifted into lower 8 bits so that they fit into 1 byte.
101
+ b[bi++] = c >> 8;
102
+ // Lower 8 bits. Cut off the upper 8 bits so that they fit into 1 byte.
103
+ b[bi++] = c & 0xFF;
104
+ }
105
+ // Modified Base64 uses , instead of / and omits trailing =.
106
+ return b.toString('base64').replace(/=+$/, '');
107
+ }
108
+
109
+ /**
110
+ * Allocates a buffer from a base64 string.
111
+ */
112
+ function allocateBase64Buffer(str: string): Buffer {
113
+ return Buffer.from(str, 'base64');
114
+ }
115
+
116
+ /**
117
+ * Decodes a string using modified UTF-7 encoding.
118
+ */
119
+ function _decode(str: string): string {
120
+ const b = allocateBase64Buffer(str);
121
+ const r: string[] = [];
122
+ for (let i = 0; i < b.length;) {
123
+ // Calculate charcode from two adjacent bytes.
124
+ r.push(String.fromCharCode(b[i++] << 8 | b[i++]));
125
+ }
126
+ return r.join('');
127
+ }
128
+
129
+ /**
130
+ * Escapes special regex characters.
131
+ * From http://simonwillison.net/2006/Jan/20/escape/
132
+ */
133
+ function escape(chars: string): string {
134
+ return chars.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
135
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "io.appium.settings",
3
- "version": "7.0.7",
3
+ "version": "7.0.9",
4
4
  "description": "App for dealing with Android settings",
5
5
  "main": "./build/lib/index.js",
6
6
  "types": "./build/lib/index.d.ts",
@@ -50,7 +50,7 @@
50
50
  "bluebird": "^3.5.1",
51
51
  "lodash": "^4.2.1",
52
52
  "semver": "^7.5.4",
53
- "teen_process": "^3.0.0"
53
+ "teen_process": "^4.0.4"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@appium/eslint-config-appium-ts": "^2.0.0-rc.1",
@@ -65,7 +65,6 @@
65
65
  "@types/mocha": "^10.0.10",
66
66
  "@types/node": "^25.0.0",
67
67
  "@types/sinon": "^21.0.0",
68
- "@types/teen_process": "^2.0.2",
69
68
  "appium-adb": "^14.0.0",
70
69
  "chai": "^6.0.0",
71
70
  "chai-as-promised": "^8.0.0",