swiftyper-node 1.0.6 → 1.0.7
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.
- package/README.md +73 -73
- package/lib/Error.js +77 -77
- package/lib/SwiftyperMethod.js +21 -21
- package/lib/SwiftyperResource.js +338 -338
- package/lib/makeRequest.js +103 -103
- package/lib/resources/Business.js +23 -23
- package/lib/resources/EmailUtil.js +13 -0
- package/lib/resources/Fbt.js +13 -13
- package/lib/resources/Phrase.js +23 -23
- package/lib/resources/Places.js +58 -58
- package/lib/resources/Translation.js +38 -38
- package/lib/resources.js +10 -9
- package/lib/swiftyper.js +159 -159
- package/lib/utils.js +272 -272
- package/package.json +36 -36
package/lib/utils.js
CHANGED
|
@@ -1,272 +1,272 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const qs = require('qs');
|
|
4
|
-
|
|
5
|
-
const hasOwn = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
6
|
-
|
|
7
|
-
const OPTIONS_KEYS = ['maxNetworkRetries', 'timeout'];
|
|
8
|
-
|
|
9
|
-
const DEPRECATED_OPTIONS = {};
|
|
10
|
-
|
|
11
|
-
const DEPRECATED_OPTIONS_KEYS = Object.keys(DEPRECATED_OPTIONS);
|
|
12
|
-
|
|
13
|
-
const utils = (module.exports = {
|
|
14
|
-
isOptionsHash(o) {
|
|
15
|
-
return (
|
|
16
|
-
o &&
|
|
17
|
-
typeof o === 'object' &&
|
|
18
|
-
(OPTIONS_KEYS.some((prop) => hasOwn(o, prop)) ||
|
|
19
|
-
DEPRECATED_OPTIONS_KEYS.some((prop) => hasOwn(o, prop)))
|
|
20
|
-
);
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Stringifies an Object, accommodating nested objects
|
|
25
|
-
* (forming the conventional key 'parent[child]=value')
|
|
26
|
-
*/
|
|
27
|
-
stringifyRequestData: (data) => {
|
|
28
|
-
return qs
|
|
29
|
-
.stringify(data, {
|
|
30
|
-
serializeDate: (d) => Math.floor(d.getTime() / 1000),
|
|
31
|
-
})
|
|
32
|
-
.replace(/%5B/g, '[')
|
|
33
|
-
.replace(/%5D/g, ']');
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Outputs a new function with interpolated object property values.
|
|
38
|
-
* Use like so:
|
|
39
|
-
* const fn = makeURLInterpolator('some/url/{param1}/{param2}');
|
|
40
|
-
* fn({ param1: 123, param2: 456 }); // => 'some/url/123/456'
|
|
41
|
-
*/
|
|
42
|
-
makeURLInterpolator: (() => {
|
|
43
|
-
const rc = {
|
|
44
|
-
'\n': '\\n',
|
|
45
|
-
'"': '\\"',
|
|
46
|
-
'\u2028': '\\u2028',
|
|
47
|
-
'\u2029': '\\u2029',
|
|
48
|
-
};
|
|
49
|
-
return (str) => {
|
|
50
|
-
const cleanString = str.replace(/["\n\r\u2028\u2029]/g, ($0) => rc[$0]);
|
|
51
|
-
return (outputs) => {
|
|
52
|
-
return cleanString.replace(/\{([\s\S]+?)\}/g, ($0, $1) =>
|
|
53
|
-
encodeURIComponent(outputs[$1] || '')
|
|
54
|
-
);
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
})(),
|
|
58
|
-
|
|
59
|
-
extractUrlParams: (path) => {
|
|
60
|
-
const params = path.match(/\{\w+\}/g);
|
|
61
|
-
if (!params) {
|
|
62
|
-
return [];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return params.map((param) => param.replace(/[{}]/g, ''));
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Return the data argument from a list of arguments
|
|
70
|
-
*
|
|
71
|
-
* @param {object[]} args
|
|
72
|
-
* @returns {object}
|
|
73
|
-
*/
|
|
74
|
-
getDataFromArgs(args) {
|
|
75
|
-
if (!Array.isArray(args) || !args[0] || typeof args[0] !== 'object') {
|
|
76
|
-
return {};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (!utils.isOptionsHash(args[0])) {
|
|
80
|
-
return args.shift();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const argKeys = Object.keys(args[0]);
|
|
84
|
-
|
|
85
|
-
const optionKeysInArgs = argKeys.filter((key) =>
|
|
86
|
-
OPTIONS_KEYS.includes(key)
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
if (
|
|
90
|
-
optionKeysInArgs.length > 0 &&
|
|
91
|
-
optionKeysInArgs.length !== argKeys.length
|
|
92
|
-
) {
|
|
93
|
-
emitWarning(
|
|
94
|
-
`Options found in arguments (${optionKeysInArgs.join(
|
|
95
|
-
', '
|
|
96
|
-
)}). Did you mean to pass an options object? See https://github.com/swiftyper-sk/swiftyper-node/wiki/Passing-Options.`
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return {};
|
|
101
|
-
},
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Return the options hash from a list of arguments
|
|
105
|
-
*/
|
|
106
|
-
getOptionsFromArgs: (args) => {
|
|
107
|
-
const opts = {
|
|
108
|
-
auth: null,
|
|
109
|
-
headers: {},
|
|
110
|
-
settings: {},
|
|
111
|
-
};
|
|
112
|
-
if (args.length > 0) {
|
|
113
|
-
const arg = args[args.length - 1];
|
|
114
|
-
if (typeof arg === 'string') {
|
|
115
|
-
opts.auth = args.pop();
|
|
116
|
-
} else if (utils.isOptionsHash(arg)) {
|
|
117
|
-
const params = {...args.pop()};
|
|
118
|
-
|
|
119
|
-
const extraKeys = Object.keys(params).filter(
|
|
120
|
-
(key) => !OPTIONS_KEYS.includes(key)
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
if (extraKeys.length) {
|
|
124
|
-
const nonDeprecated = extraKeys.filter((key) => {
|
|
125
|
-
if (!DEPRECATED_OPTIONS[key]) {
|
|
126
|
-
return true;
|
|
127
|
-
}
|
|
128
|
-
const newParam = DEPRECATED_OPTIONS[key];
|
|
129
|
-
if (params[newParam]) {
|
|
130
|
-
throw Error(
|
|
131
|
-
`Both '${newParam}' and '${key}' were provided; please remove '${key}', which is deprecated.`
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* TODO turn this into a hard error in a future major version (once we have fixed our docs).
|
|
136
|
-
*/
|
|
137
|
-
emitWarning(`'${key}' is deprecated; use '${newParam}' instead.`);
|
|
138
|
-
params[newParam] = params[key];
|
|
139
|
-
});
|
|
140
|
-
if (nonDeprecated.length) {
|
|
141
|
-
emitWarning(
|
|
142
|
-
`Invalid options found (${extraKeys.join(', ')}); ignoring.`
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (Number.isInteger(params.maxNetworkRetries)) {
|
|
148
|
-
opts.settings.maxNetworkRetries = params.maxNetworkRetries;
|
|
149
|
-
}
|
|
150
|
-
if (Number.isInteger(params.timeout)) {
|
|
151
|
-
opts.settings.timeout = params.timeout;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return opts;
|
|
156
|
-
},
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Provide simple "Class" extension mechanism
|
|
160
|
-
*/
|
|
161
|
-
protoExtend(sub) {
|
|
162
|
-
const Super = this;
|
|
163
|
-
const Constructor = hasOwn(sub, 'constructor')
|
|
164
|
-
? sub.constructor
|
|
165
|
-
: function (...args) {
|
|
166
|
-
Super.apply(this, args);
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
Object.assign(Constructor, Super);
|
|
170
|
-
Constructor.prototype = Object.create(Super.prototype);
|
|
171
|
-
Object.assign(Constructor.prototype, sub);
|
|
172
|
-
|
|
173
|
-
return Constructor;
|
|
174
|
-
},
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Remove empty values from an object
|
|
178
|
-
*/
|
|
179
|
-
removeNullish: (obj) => {
|
|
180
|
-
if (typeof obj !== 'object') {
|
|
181
|
-
throw new Error('Argument must be an object');
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return Object.keys(obj).reduce((result, key) => {
|
|
185
|
-
if (obj[key] != null) {
|
|
186
|
-
result[key] = obj[key];
|
|
187
|
-
}
|
|
188
|
-
return result;
|
|
189
|
-
}, {});
|
|
190
|
-
},
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Normalize standard HTTP Headers:
|
|
194
|
-
* {'foo-bar': 'hi'}
|
|
195
|
-
* becomes
|
|
196
|
-
* {'Foo-Bar': 'hi'}
|
|
197
|
-
*/
|
|
198
|
-
normalizeHeaders: (obj) => {
|
|
199
|
-
if (!(obj && typeof obj === 'object')) {
|
|
200
|
-
return obj;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return Object.keys(obj).reduce((result, header) => {
|
|
204
|
-
result[utils.normalizeHeader(header)] = obj[header];
|
|
205
|
-
return result;
|
|
206
|
-
}, {});
|
|
207
|
-
},
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Stolen from https://github.com/marten-de-vries/header-case-normalizer/blob/master/index.js#L36-L41
|
|
211
|
-
* without the exceptions which are irrelevant to us.
|
|
212
|
-
*/
|
|
213
|
-
normalizeHeader: (header) => {
|
|
214
|
-
return header
|
|
215
|
-
.split('-')
|
|
216
|
-
.map(
|
|
217
|
-
(text) => text.charAt(0).toUpperCase() + text.substr(1).toLowerCase()
|
|
218
|
-
)
|
|
219
|
-
.join('-');
|
|
220
|
-
},
|
|
221
|
-
|
|
222
|
-
callbackifyPromiseWithTimeout: (promise, callback) => {
|
|
223
|
-
if (callback) {
|
|
224
|
-
// Ensure callback is called outside of promise stack.
|
|
225
|
-
return promise.then(
|
|
226
|
-
(res) => {
|
|
227
|
-
setTimeout(() => {
|
|
228
|
-
callback(null, res);
|
|
229
|
-
}, 0);
|
|
230
|
-
},
|
|
231
|
-
(err) => {
|
|
232
|
-
setTimeout(() => {
|
|
233
|
-
callback(err, null);
|
|
234
|
-
}, 0);
|
|
235
|
-
}
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
return promise;
|
|
240
|
-
},
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Allow for special capitalization cases
|
|
244
|
-
*/
|
|
245
|
-
pascalToCamelCase: (name) => {
|
|
246
|
-
return name[0].toLowerCase() + name.substring(1);
|
|
247
|
-
},
|
|
248
|
-
|
|
249
|
-
emitWarning,
|
|
250
|
-
|
|
251
|
-
validateInteger: (name, n, defaultVal) => {
|
|
252
|
-
if (!Number.isInteger(n)) {
|
|
253
|
-
if (defaultVal !== undefined) {
|
|
254
|
-
return defaultVal;
|
|
255
|
-
} else {
|
|
256
|
-
throw new Error(`${name} must be an integer`);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
return n;
|
|
261
|
-
},
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
function emitWarning(warning) {
|
|
265
|
-
if (typeof process.emitWarning !== 'function') {
|
|
266
|
-
return console.warn(
|
|
267
|
-
`Swiftyper: ${warning}`
|
|
268
|
-
); /* eslint-disable-line no-console */
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
return process.emitWarning(warning, 'Swiftyper');
|
|
272
|
-
}
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const qs = require('qs');
|
|
4
|
+
|
|
5
|
+
const hasOwn = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
6
|
+
|
|
7
|
+
const OPTIONS_KEYS = ['maxNetworkRetries', 'timeout'];
|
|
8
|
+
|
|
9
|
+
const DEPRECATED_OPTIONS = {};
|
|
10
|
+
|
|
11
|
+
const DEPRECATED_OPTIONS_KEYS = Object.keys(DEPRECATED_OPTIONS);
|
|
12
|
+
|
|
13
|
+
const utils = (module.exports = {
|
|
14
|
+
isOptionsHash(o) {
|
|
15
|
+
return (
|
|
16
|
+
o &&
|
|
17
|
+
typeof o === 'object' &&
|
|
18
|
+
(OPTIONS_KEYS.some((prop) => hasOwn(o, prop)) ||
|
|
19
|
+
DEPRECATED_OPTIONS_KEYS.some((prop) => hasOwn(o, prop)))
|
|
20
|
+
);
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Stringifies an Object, accommodating nested objects
|
|
25
|
+
* (forming the conventional key 'parent[child]=value')
|
|
26
|
+
*/
|
|
27
|
+
stringifyRequestData: (data) => {
|
|
28
|
+
return qs
|
|
29
|
+
.stringify(data, {
|
|
30
|
+
serializeDate: (d) => Math.floor(d.getTime() / 1000),
|
|
31
|
+
})
|
|
32
|
+
.replace(/%5B/g, '[')
|
|
33
|
+
.replace(/%5D/g, ']');
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Outputs a new function with interpolated object property values.
|
|
38
|
+
* Use like so:
|
|
39
|
+
* const fn = makeURLInterpolator('some/url/{param1}/{param2}');
|
|
40
|
+
* fn({ param1: 123, param2: 456 }); // => 'some/url/123/456'
|
|
41
|
+
*/
|
|
42
|
+
makeURLInterpolator: (() => {
|
|
43
|
+
const rc = {
|
|
44
|
+
'\n': '\\n',
|
|
45
|
+
'"': '\\"',
|
|
46
|
+
'\u2028': '\\u2028',
|
|
47
|
+
'\u2029': '\\u2029',
|
|
48
|
+
};
|
|
49
|
+
return (str) => {
|
|
50
|
+
const cleanString = str.replace(/["\n\r\u2028\u2029]/g, ($0) => rc[$0]);
|
|
51
|
+
return (outputs) => {
|
|
52
|
+
return cleanString.replace(/\{([\s\S]+?)\}/g, ($0, $1) =>
|
|
53
|
+
encodeURIComponent(outputs[$1] || '')
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
})(),
|
|
58
|
+
|
|
59
|
+
extractUrlParams: (path) => {
|
|
60
|
+
const params = path.match(/\{\w+\}/g);
|
|
61
|
+
if (!params) {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return params.map((param) => param.replace(/[{}]/g, ''));
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Return the data argument from a list of arguments
|
|
70
|
+
*
|
|
71
|
+
* @param {object[]} args
|
|
72
|
+
* @returns {object}
|
|
73
|
+
*/
|
|
74
|
+
getDataFromArgs(args) {
|
|
75
|
+
if (!Array.isArray(args) || !args[0] || typeof args[0] !== 'object') {
|
|
76
|
+
return {};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (!utils.isOptionsHash(args[0])) {
|
|
80
|
+
return args.shift();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const argKeys = Object.keys(args[0]);
|
|
84
|
+
|
|
85
|
+
const optionKeysInArgs = argKeys.filter((key) =>
|
|
86
|
+
OPTIONS_KEYS.includes(key)
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
if (
|
|
90
|
+
optionKeysInArgs.length > 0 &&
|
|
91
|
+
optionKeysInArgs.length !== argKeys.length
|
|
92
|
+
) {
|
|
93
|
+
emitWarning(
|
|
94
|
+
`Options found in arguments (${optionKeysInArgs.join(
|
|
95
|
+
', '
|
|
96
|
+
)}). Did you mean to pass an options object? See https://github.com/swiftyper-sk/swiftyper-node/wiki/Passing-Options.`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return {};
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Return the options hash from a list of arguments
|
|
105
|
+
*/
|
|
106
|
+
getOptionsFromArgs: (args) => {
|
|
107
|
+
const opts = {
|
|
108
|
+
auth: null,
|
|
109
|
+
headers: {},
|
|
110
|
+
settings: {},
|
|
111
|
+
};
|
|
112
|
+
if (args.length > 0) {
|
|
113
|
+
const arg = args[args.length - 1];
|
|
114
|
+
if (typeof arg === 'string') {
|
|
115
|
+
opts.auth = args.pop();
|
|
116
|
+
} else if (utils.isOptionsHash(arg)) {
|
|
117
|
+
const params = {...args.pop()};
|
|
118
|
+
|
|
119
|
+
const extraKeys = Object.keys(params).filter(
|
|
120
|
+
(key) => !OPTIONS_KEYS.includes(key)
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
if (extraKeys.length) {
|
|
124
|
+
const nonDeprecated = extraKeys.filter((key) => {
|
|
125
|
+
if (!DEPRECATED_OPTIONS[key]) {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
const newParam = DEPRECATED_OPTIONS[key];
|
|
129
|
+
if (params[newParam]) {
|
|
130
|
+
throw Error(
|
|
131
|
+
`Both '${newParam}' and '${key}' were provided; please remove '${key}', which is deprecated.`
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* TODO turn this into a hard error in a future major version (once we have fixed our docs).
|
|
136
|
+
*/
|
|
137
|
+
emitWarning(`'${key}' is deprecated; use '${newParam}' instead.`);
|
|
138
|
+
params[newParam] = params[key];
|
|
139
|
+
});
|
|
140
|
+
if (nonDeprecated.length) {
|
|
141
|
+
emitWarning(
|
|
142
|
+
`Invalid options found (${extraKeys.join(', ')}); ignoring.`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (Number.isInteger(params.maxNetworkRetries)) {
|
|
148
|
+
opts.settings.maxNetworkRetries = params.maxNetworkRetries;
|
|
149
|
+
}
|
|
150
|
+
if (Number.isInteger(params.timeout)) {
|
|
151
|
+
opts.settings.timeout = params.timeout;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return opts;
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Provide simple "Class" extension mechanism
|
|
160
|
+
*/
|
|
161
|
+
protoExtend(sub) {
|
|
162
|
+
const Super = this;
|
|
163
|
+
const Constructor = hasOwn(sub, 'constructor')
|
|
164
|
+
? sub.constructor
|
|
165
|
+
: function (...args) {
|
|
166
|
+
Super.apply(this, args);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
Object.assign(Constructor, Super);
|
|
170
|
+
Constructor.prototype = Object.create(Super.prototype);
|
|
171
|
+
Object.assign(Constructor.prototype, sub);
|
|
172
|
+
|
|
173
|
+
return Constructor;
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Remove empty values from an object
|
|
178
|
+
*/
|
|
179
|
+
removeNullish: (obj) => {
|
|
180
|
+
if (typeof obj !== 'object') {
|
|
181
|
+
throw new Error('Argument must be an object');
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return Object.keys(obj).reduce((result, key) => {
|
|
185
|
+
if (obj[key] != null) {
|
|
186
|
+
result[key] = obj[key];
|
|
187
|
+
}
|
|
188
|
+
return result;
|
|
189
|
+
}, {});
|
|
190
|
+
},
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Normalize standard HTTP Headers:
|
|
194
|
+
* {'foo-bar': 'hi'}
|
|
195
|
+
* becomes
|
|
196
|
+
* {'Foo-Bar': 'hi'}
|
|
197
|
+
*/
|
|
198
|
+
normalizeHeaders: (obj) => {
|
|
199
|
+
if (!(obj && typeof obj === 'object')) {
|
|
200
|
+
return obj;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return Object.keys(obj).reduce((result, header) => {
|
|
204
|
+
result[utils.normalizeHeader(header)] = obj[header];
|
|
205
|
+
return result;
|
|
206
|
+
}, {});
|
|
207
|
+
},
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Stolen from https://github.com/marten-de-vries/header-case-normalizer/blob/master/index.js#L36-L41
|
|
211
|
+
* without the exceptions which are irrelevant to us.
|
|
212
|
+
*/
|
|
213
|
+
normalizeHeader: (header) => {
|
|
214
|
+
return header
|
|
215
|
+
.split('-')
|
|
216
|
+
.map(
|
|
217
|
+
(text) => text.charAt(0).toUpperCase() + text.substr(1).toLowerCase()
|
|
218
|
+
)
|
|
219
|
+
.join('-');
|
|
220
|
+
},
|
|
221
|
+
|
|
222
|
+
callbackifyPromiseWithTimeout: (promise, callback) => {
|
|
223
|
+
if (callback) {
|
|
224
|
+
// Ensure callback is called outside of promise stack.
|
|
225
|
+
return promise.then(
|
|
226
|
+
(res) => {
|
|
227
|
+
setTimeout(() => {
|
|
228
|
+
callback(null, res);
|
|
229
|
+
}, 0);
|
|
230
|
+
},
|
|
231
|
+
(err) => {
|
|
232
|
+
setTimeout(() => {
|
|
233
|
+
callback(err, null);
|
|
234
|
+
}, 0);
|
|
235
|
+
}
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return promise;
|
|
240
|
+
},
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Allow for special capitalization cases
|
|
244
|
+
*/
|
|
245
|
+
pascalToCamelCase: (name) => {
|
|
246
|
+
return name[0].toLowerCase() + name.substring(1);
|
|
247
|
+
},
|
|
248
|
+
|
|
249
|
+
emitWarning,
|
|
250
|
+
|
|
251
|
+
validateInteger: (name, n, defaultVal) => {
|
|
252
|
+
if (!Number.isInteger(n)) {
|
|
253
|
+
if (defaultVal !== undefined) {
|
|
254
|
+
return defaultVal;
|
|
255
|
+
} else {
|
|
256
|
+
throw new Error(`${name} must be an integer`);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return n;
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
function emitWarning(warning) {
|
|
265
|
+
if (typeof process.emitWarning !== 'function') {
|
|
266
|
+
return console.warn(
|
|
267
|
+
`Swiftyper: ${warning}`
|
|
268
|
+
); /* eslint-disable-line no-console */
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return process.emitWarning(warning, 'Swiftyper');
|
|
272
|
+
}
|
package/package.json
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "swiftyper-node",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Swiftyper API",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"swiftyper",
|
|
7
|
-
"api"
|
|
8
|
-
],
|
|
9
|
-
"homepage": "https://github.com/swiftyper-sk/swiftyper-node",
|
|
10
|
-
"author": "Swiftyper <support@swiftyper.sk> (https://swiftyper.sk/)",
|
|
11
|
-
"repository": {
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "git://github.com/swiftyper-sk/swiftyper-node.git"
|
|
14
|
-
},
|
|
15
|
-
"bugs:": "https://github.com/swiftyper-sk/swiftyper-node/issues",
|
|
16
|
-
"engines": {
|
|
17
|
-
"node": "^8.1 || >=10.*"
|
|
18
|
-
},
|
|
19
|
-
"main": "lib/swiftyper.js",
|
|
20
|
-
"devDependencies": {
|
|
21
|
-
"@typescript-eslint/eslint-plugin": "^2.13.0",
|
|
22
|
-
"@typescript-eslint/parser": "^2.13.0",
|
|
23
|
-
"eslint": "^6.8.0",
|
|
24
|
-
"eslint-config-prettier": "^4.1.0",
|
|
25
|
-
"eslint-plugin-prettier": "^3.0.1",
|
|
26
|
-
"typescript": "^3.7.2"
|
|
27
|
-
},
|
|
28
|
-
"dependencies": {
|
|
29
|
-
"@types/node": ">=8.1.0",
|
|
30
|
-
"qs": "^6.6.0"
|
|
31
|
-
},
|
|
32
|
-
"license": "MIT",
|
|
33
|
-
"scripts": {
|
|
34
|
-
"lint": "eslint --ext .js,.jsx,.ts ."
|
|
35
|
-
}
|
|
36
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "swiftyper-node",
|
|
3
|
+
"version": "1.0.7",
|
|
4
|
+
"description": "Swiftyper API",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"swiftyper",
|
|
7
|
+
"api"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://github.com/swiftyper-sk/swiftyper-node",
|
|
10
|
+
"author": "Swiftyper <support@swiftyper.sk> (https://swiftyper.sk/)",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git://github.com/swiftyper-sk/swiftyper-node.git"
|
|
14
|
+
},
|
|
15
|
+
"bugs:": "https://github.com/swiftyper-sk/swiftyper-node/issues",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": "^8.1 || >=10.*"
|
|
18
|
+
},
|
|
19
|
+
"main": "lib/swiftyper.js",
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@typescript-eslint/eslint-plugin": "^2.13.0",
|
|
22
|
+
"@typescript-eslint/parser": "^2.13.0",
|
|
23
|
+
"eslint": "^6.8.0",
|
|
24
|
+
"eslint-config-prettier": "^4.1.0",
|
|
25
|
+
"eslint-plugin-prettier": "^3.0.1",
|
|
26
|
+
"typescript": "^3.7.2"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@types/node": ">=8.1.0",
|
|
30
|
+
"qs": "^6.6.0"
|
|
31
|
+
},
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"scripts": {
|
|
34
|
+
"lint": "eslint --ext .js,.jsx,.ts ."
|
|
35
|
+
}
|
|
36
|
+
}
|