@sellout/utils 0.0.1
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/.dist/CSV.d.ts +1 -0
- package/.dist/CSV.js +23 -0
- package/.dist/CSV.js.map +1 -0
- package/.dist/GoogleTimezoneAPI.d.ts +1 -0
- package/.dist/GoogleTimezoneAPI.js +26 -0
- package/.dist/GoogleTimezoneAPI.js.map +1 -0
- package/.dist/IPStack.d.ts +1 -0
- package/.dist/IPStack.js +34 -0
- package/.dist/IPStack.js.map +1 -0
- package/.dist/MongoConnectionManager.d.ts +9 -0
- package/.dist/MongoConnectionManager.js +52 -0
- package/.dist/MongoConnectionManager.js.map +1 -0
- package/.dist/env.d.ts +4 -0
- package/.dist/env.js +7 -0
- package/.dist/env.js.map +1 -0
- package/.dist/formatPhoneNumber.d.ts +1 -0
- package/.dist/formatPhoneNumber.js +23 -0
- package/.dist/formatPhoneNumber.js.map +1 -0
- package/.dist/price.d.ts +1 -0
- package/.dist/price.js +8 -0
- package/.dist/price.js.map +1 -0
- package/.dist/random.d.ts +1 -0
- package/.dist/random.js +7 -0
- package/.dist/random.js.map +1 -0
- package/.dist/time.d.ts +9 -0
- package/.dist/time.js +32 -0
- package/.dist/time.js.map +1 -0
- package/.dist/wait.d.ts +1 -0
- package/.dist/wait.js +9 -0
- package/.dist/wait.js.map +1 -0
- package/package.json +29 -0
- package/src/CSV.ts +22 -0
- package/src/GoogleTimezoneAPI.ts +15 -0
- package/src/IPStack.ts +24 -0
- package/src/env.ts +4 -0
- package/src/formatPhoneNumber.ts +22 -0
- package/src/price.ts +5 -0
- package/src/random.ts +3 -0
- package/src/time.ts +33 -0
- package/src/wait.ts +5 -0
- package/tsconfig.json +27 -0
- package/tslint.json +21 -0
package/.dist/CSV.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function fromJson(fields: string[], data: object): Promise<string>;
|
package/.dist/CSV.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const json2csv_1 = require("json2csv");
|
|
4
|
+
function fromJson(fields, data) {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
const json = JSON.stringify(data);
|
|
7
|
+
const opts = { fields };
|
|
8
|
+
const transformOpts = {};
|
|
9
|
+
const asyncParser = new json2csv_1.AsyncParser(opts, transformOpts);
|
|
10
|
+
let csv = '';
|
|
11
|
+
asyncParser.processor
|
|
12
|
+
.on('data', chunk => {
|
|
13
|
+
// console.log(chunk.toString());
|
|
14
|
+
csv += chunk.toString();
|
|
15
|
+
})
|
|
16
|
+
.on('end', () => resolve(csv))
|
|
17
|
+
.on('error', err => reject(err));
|
|
18
|
+
asyncParser.input.push(json);
|
|
19
|
+
asyncParser.input.push(null);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
exports.fromJson = fromJson;
|
|
23
|
+
//# sourceMappingURL=CSV.js.map
|
package/.dist/CSV.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CSV.js","sourceRoot":"","sources":["../src/CSV.ts"],"names":[],"mappings":";;AAAA,uCAAuC;AAEvC,SAAgB,QAAQ,CAAC,MAAgB,EAAE,IAAY;IACrD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAClC,MAAM,IAAI,GAAG,EAAE,MAAM,EAAE,CAAC;QACxB,MAAM,aAAa,GAAG,EAAE,CAAC;QACzB,MAAM,WAAW,GAAG,IAAI,sBAAW,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QAEzD,IAAI,GAAG,GAAG,EAAE,CAAC;QACb,WAAW,CAAC,SAAS;aAClB,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE;YAClB,iCAAiC;YACjC,GAAG,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QAC1B,CAAC,CAAC;aACD,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;aAC7B,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAEnC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7B,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC;AAnBD,4BAmBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function info(lat: any, lng: any): Promise<any>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const Time = require("./time");
|
|
13
|
+
const request = require("request-promise-native");
|
|
14
|
+
const env_1 = require("./env");
|
|
15
|
+
function info(lat, lng) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const baseUrl = 'https://maps.googleapis.com/maps/api/timezone/json';
|
|
18
|
+
const url = `${baseUrl}?location=${lat},${lng}×tamp=${Time.now()}&key=${env_1.GOOGLE_TIMEZONE_API_KEY}`;
|
|
19
|
+
const response = yield request.get(url, {
|
|
20
|
+
json: true
|
|
21
|
+
});
|
|
22
|
+
return response;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
exports.info = info;
|
|
26
|
+
//# sourceMappingURL=GoogleTimezoneAPI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GoogleTimezoneAPI.js","sourceRoot":"","sources":["../src/GoogleTimezoneAPI.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+BAA+B;AAC/B,kDAAkD;AAClD,+BAEe;AAEf,SAAsB,IAAI,CAAC,GAAG,EAAE,GAAG;;QACjC,MAAM,OAAO,GAAG,oDAAoD,CAAC;QACrE,MAAM,GAAG,GAAG,GAAG,OAAO,aAAa,GAAG,IAAI,GAAG,cAAc,IAAI,CAAC,GAAG,EAAE,QAAQ,6BAAuB,EAAE,CAAC;QACvG,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE;YACtC,IAAI,EAAE,IAAI;SACX,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC;IAClB,CAAC;CAAA;AAPD,oBAOC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function gecodeIPAddress(ipAddress: any): Promise<any>;
|
package/.dist/IPStack.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const request = require("request-promise-native");
|
|
13
|
+
const env_1 = require("./env");
|
|
14
|
+
function gecodeIPAddress(ipAddress) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
// Return mock data for load testing
|
|
17
|
+
if (env_1.LOAD_TEST_ENABLED) {
|
|
18
|
+
return {
|
|
19
|
+
city: 'Polson',
|
|
20
|
+
region_code: 'MT',
|
|
21
|
+
zip: '59860',
|
|
22
|
+
country_code: 'US',
|
|
23
|
+
latitude: 47.6932,
|
|
24
|
+
longitude: 114.1631
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const url = `http://api.ipstack.com/${ipAddress}?access_key=${env_1.IP_STACK_API_KEY}`;
|
|
28
|
+
return yield request.get(url, {
|
|
29
|
+
json: true
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
exports.gecodeIPAddress = gecodeIPAddress;
|
|
34
|
+
//# sourceMappingURL=IPStack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IPStack.js","sourceRoot":"","sources":["../src/IPStack.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,kDAAkD;AAClD,+BAGe;AAEf,SAAsB,eAAe,CAAC,SAAS;;QAC7C,oCAAoC;QACpC,IAAG,uBAAiB,EAAE;YACpB,OAAO;gBACL,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,IAAI;gBACjB,GAAG,EAAE,OAAO;gBACZ,YAAY,EAAE,IAAI;gBAClB,QAAQ,EAAE,OAAO;gBACjB,SAAS,EAAE,QAAQ;aACpB,CAAC;SACH;QAED,MAAM,GAAG,GAAG,0BAA0B,SAAS,eAAe,sBAAgB,EAAE,CAAC;QACjF,OAAO,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE;YAC5B,IAAI,EAAE,IAAI;SACX,CAAC,CAAC;IACL,CAAC;CAAA;AAjBD,0CAiBC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default class MongoConnectionManager {
|
|
2
|
+
connected: boolean;
|
|
3
|
+
mongoConnectionString: string;
|
|
4
|
+
isReplicaSet: boolean;
|
|
5
|
+
private mongoose;
|
|
6
|
+
private mongoConnectionStringInternal;
|
|
7
|
+
constructor(mongoose: any, mongoConnectionString: string, username?: string, password?: string);
|
|
8
|
+
connect(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const wait_1 = require("./wait");
|
|
13
|
+
class MongoConnectionManager {
|
|
14
|
+
constructor(mongoose, mongoConnectionString, username = '', password = '') {
|
|
15
|
+
const parsed = new URL(mongoConnectionString);
|
|
16
|
+
parsed.username = username;
|
|
17
|
+
parsed.password = password;
|
|
18
|
+
parsed.pathname = '/admin';
|
|
19
|
+
this.connected = false;
|
|
20
|
+
this.mongoConnectionStringInternal = parsed.toString();
|
|
21
|
+
this.isReplicaSet = parsed.protocol === 'mongodb+srv:';
|
|
22
|
+
// redact username/password from publicly available connection string
|
|
23
|
+
parsed.username = '__user__';
|
|
24
|
+
parsed.password = '__pass__';
|
|
25
|
+
this.mongoConnectionString = parsed.toString();
|
|
26
|
+
this.mongoose = mongoose;
|
|
27
|
+
}
|
|
28
|
+
connect() {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
while (!this.connected) {
|
|
31
|
+
console.log('Attempting to connect to Mongo...');
|
|
32
|
+
this.mongoose.connect(this.mongoConnectionStringInternal, {
|
|
33
|
+
ssl: false,
|
|
34
|
+
useUnifiedTopology: true,
|
|
35
|
+
useNewUrlParser: true,
|
|
36
|
+
})
|
|
37
|
+
.then(() => {
|
|
38
|
+
this.connected = true;
|
|
39
|
+
console.log(`Connected to MongoDB: ${this.mongoConnectionString}`);
|
|
40
|
+
})
|
|
41
|
+
.catch((e) => {
|
|
42
|
+
console.error(`There was an error connecting to MongoDB: ${this.mongoConnectionString}`);
|
|
43
|
+
console.error(e);
|
|
44
|
+
});
|
|
45
|
+
// wait five seconds before trying again
|
|
46
|
+
yield wait_1.default(5000);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.default = MongoConnectionManager;
|
|
52
|
+
//# sourceMappingURL=MongoConnectionManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongoConnectionManager.js","sourceRoot":"","sources":["../src/MongoConnectionManager.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,iCAA0B;AAE1B,MAAqB,sBAAsB;IAOzC,YAAY,QAAa,EAAE,qBAA6B,EAAE,WAAmB,EAAE,EAAE,WAAmB,EAAE;QACpG,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,qBAAqB,CAAC,CAAC;QAE9C,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAC3B,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAC3B,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAE3B,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QACvB,IAAI,CAAC,6BAA6B,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;QACvD,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,QAAQ,KAAK,cAAc,CAAC;QAEvD,qEAAqE;QACrE,MAAM,CAAC,QAAQ,GAAG,UAAU,CAAC;QAC7B,MAAM,CAAC,QAAQ,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,qBAAqB,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;QAC/C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAEY,OAAO;;YAClB,OAAM,CAAC,IAAI,CAAC,SAAS,EAAE;gBACrB,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;gBACjD,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,6BAA6B,EAAE;oBACxD,GAAG,EAAE,KAAK;oBACV,kBAAkB,EAAE,IAAI;oBACxB,eAAe,EAAE,IAAI;iBACtB,CAAC;qBACC,IAAI,CAAC,GAAG,EAAE;oBACT,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;oBACtB,OAAO,CAAC,GAAG,CAAC,yBAAyB,IAAI,CAAC,qBAAqB,EAAE,CAAC,CAAC;gBACrE,CAAC,CAAC;qBACD,KAAK,CAAC,CAAC,CAAM,EAAE,EAAE;oBAChB,OAAO,CAAC,KAAK,CAAC,6CAA6C,IAAI,CAAC,qBAAqB,EAAE,CAAC,CAAC;oBACzF,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBACnB,CAAC,CAAC,CAAC;gBAEL,wCAAwC;gBACxC,MAAM,cAAI,CAAC,IAAI,CAAC,CAAC;aAClB;QACH,CAAC;KAAA;CACF;AA9CD,yCA8CC"}
|
package/.dist/env.d.ts
ADDED
package/.dist/env.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GOOGLE_TIMEZONE_API_KEY = process.env.GOOGLE_TIMEZONE_API_KEY;
|
|
4
|
+
exports.LOAD_TEST_ENABLED = process.env.LOAD_TEST_ENABLED === '1';
|
|
5
|
+
exports.IP_STACK_API_KEY = process.env.IP_STACK_API_KEY;
|
|
6
|
+
exports.NODE_ENV = process.env.NODE_ENV || 'development';
|
|
7
|
+
//# sourceMappingURL=env.js.map
|
package/.dist/env.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":";;AAAa,QAAA,uBAAuB,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC;AAC9D,QAAA,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,KAAK,GAAG,CAAC;AAC1D,QAAA,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;AAChD,QAAA,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function formatPhoneNumber(phoneNumberString: string): string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function formatPhoneNumber(phoneNumberString) {
|
|
4
|
+
const cleaned = (`${phoneNumberString}`).replace(/\D/g, '');
|
|
5
|
+
let match = cleaned.match(/^(1|)?(\d{3})(\d{3})(\d{4})$/);
|
|
6
|
+
if (match) {
|
|
7
|
+
const intlCode = (match[1] ? '+1 ' : '');
|
|
8
|
+
return [intlCode, match[2], ' ', match[3], ' ', match[4]].join('');
|
|
9
|
+
}
|
|
10
|
+
match = cleaned.match(/^(1|)?(\d{3})(\d{3})$/);
|
|
11
|
+
if (match) {
|
|
12
|
+
const intlCode = (match[1] ? '+1 ' : '');
|
|
13
|
+
return [intlCode, match[2], ' ', match[3]].join('');
|
|
14
|
+
}
|
|
15
|
+
match = cleaned.match(/^(1|)?(\d{3})$/);
|
|
16
|
+
if (match) {
|
|
17
|
+
const intlCode = (match[1] ? '+1 ' : '');
|
|
18
|
+
return [intlCode, match[2]].join('');
|
|
19
|
+
}
|
|
20
|
+
return cleaned;
|
|
21
|
+
}
|
|
22
|
+
exports.default = formatPhoneNumber;
|
|
23
|
+
//# sourceMappingURL=formatPhoneNumber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatPhoneNumber.js","sourceRoot":"","sources":["../src/formatPhoneNumber.ts"],"names":[],"mappings":";;AAAA,SAAwB,iBAAiB,CAAC,iBAAyB;IACjE,MAAM,OAAO,GAAG,CAAC,GAAG,iBAAiB,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC5D,IAAI,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAC1D,IAAI,KAAK,EAAE;QACT,MAAM,QAAQ,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACzC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;KACpE;IAED,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC/C,IAAI,KAAK,EAAE;QACT,MAAM,QAAQ,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACzC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;KACrD;IAED,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IACxC,IAAI,KAAK,EAAE;QACT,MAAM,QAAQ,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACzC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;KACtC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AArBD,oCAqBC"}
|
package/.dist/price.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const output: (price: number) => string;
|
package/.dist/price.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.output = (price) => {
|
|
4
|
+
price = price / 100;
|
|
5
|
+
return price.toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
|
|
6
|
+
// return `$${price.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}`;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=price.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"price.js","sourceRoot":"","sources":["../src/price.ts"],"names":[],"mappings":";;AAAa,QAAA,MAAM,GAAG,CAAC,KAAa,EAAU,EAAE;IAC9C,KAAK,GAAG,KAAK,GAAG,GAAG,CAAC;IACpB,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;IAClE,uEAAuE;AACzE,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function generateOfLength(length: any): number;
|
package/.dist/random.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function generateOfLength(length) {
|
|
4
|
+
return Math.floor(Math.pow(10, length - 1) + Math.random() * 9 * Math.pow(10, length - 1));
|
|
5
|
+
}
|
|
6
|
+
exports.generateOfLength = generateOfLength;
|
|
7
|
+
//# sourceMappingURL=random.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.js","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":";;AAAA,SAAgB,gBAAgB,CAAC,MAAM;IACrC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;AAC7F,CAAC;AAFD,4CAEC"}
|
package/.dist/time.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const SECOND = 1000;
|
|
2
|
+
export declare const MINUTE: number;
|
|
3
|
+
export declare const HOUR: number;
|
|
4
|
+
export declare const DAY: number;
|
|
5
|
+
export declare const now: () => number;
|
|
6
|
+
export declare const date: (seconds?: number | undefined) => any;
|
|
7
|
+
export declare const fromDate: (millis: string | number) => number;
|
|
8
|
+
export declare const format: (secondsSinceEpoch: any, format?: string, timezone?: string) => any;
|
|
9
|
+
export declare const formatTimeOfDay: (secondsSinceEpoch: any, timezone?: string | undefined) => any;
|
package/.dist/time.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const moment = require("moment-timezone");
|
|
4
|
+
exports.SECOND = 1000;
|
|
5
|
+
exports.MINUTE = 60 * exports.SECOND;
|
|
6
|
+
exports.HOUR = 60 * exports.MINUTE;
|
|
7
|
+
exports.DAY = 24 * exports.HOUR;
|
|
8
|
+
exports.now = function () {
|
|
9
|
+
const millis = Date.now();
|
|
10
|
+
const seconds = millis / 1000;
|
|
11
|
+
return Math.floor(seconds);
|
|
12
|
+
};
|
|
13
|
+
exports.date = function (seconds) {
|
|
14
|
+
if (!seconds)
|
|
15
|
+
return new Date();
|
|
16
|
+
const millis = seconds * 1000;
|
|
17
|
+
return new Date(millis);
|
|
18
|
+
};
|
|
19
|
+
exports.fromDate = function (millis) {
|
|
20
|
+
return Math.floor(new Date(millis).getTime() / 1000);
|
|
21
|
+
};
|
|
22
|
+
// Use this one, it's better
|
|
23
|
+
exports.format = function (secondsSinceEpoch, format = 'M/DD/YYYY h:mma', timezone = 'America/Denver') {
|
|
24
|
+
if (!timezone)
|
|
25
|
+
timezone = 'America/Denver';
|
|
26
|
+
const millis = exports.date(secondsSinceEpoch);
|
|
27
|
+
return moment(millis).tz(timezone).format(format);
|
|
28
|
+
};
|
|
29
|
+
exports.formatTimeOfDay = function (secondsSinceEpoch, timezone) {
|
|
30
|
+
return exports.format(secondsSinceEpoch, 'h:mma', timezone);
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=time.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":";;AAAA,0CAA0C;AAE7B,QAAA,MAAM,GAAG,IAAI,CAAC;AACd,QAAA,MAAM,GAAG,EAAE,GAAG,cAAM,CAAC;AACrB,QAAA,IAAI,GAAG,EAAE,GAAG,cAAM,CAAC;AACnB,QAAA,GAAG,GAAG,EAAE,GAAG,YAAI,CAAC;AAEhB,QAAA,GAAG,GAAG;IACjB,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC1B,MAAM,OAAO,GAAG,MAAM,GAAG,IAAI,CAAC;IAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAC7B,CAAC,CAAC;AAEW,QAAA,IAAI,GAAG,UAAS,OAAgB;IAC3C,IAAG,CAAC,OAAO;QAAE,OAAO,IAAI,IAAI,EAAE,CAAC;IAC/B,MAAM,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;IAC9B,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC;AAC1B,CAAC,CAAA;AAEY,QAAA,QAAQ,GAAG,UAAS,MAAuB;IACtD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;AACvD,CAAC,CAAA;AAED,4BAA4B;AACf,QAAA,MAAM,GAAG,UAAS,iBAAiB,EAAE,MAAM,GAAG,iBAAiB,EAAE,WAAmB,gBAAgB;IAC/G,IAAG,CAAC,QAAQ;QAAE,QAAQ,GAAG,gBAAgB,CAAC;IAC1C,MAAM,MAAM,GAAG,YAAI,CAAC,iBAAiB,CAAC,CAAC;IACvC,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AACpD,CAAC,CAAA;AAEY,QAAA,eAAe,GAAG,UAAU,iBAAiB,EAAE,QAAiB;IAC3E,OAAO,cAAM,CAAC,iBAAiB,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;AACtD,CAAC,CAAA"}
|
package/.dist/wait.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function wait(timeoutMs: number, value?: any): Promise<any>;
|
package/.dist/wait.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function wait(timeoutMs, value = null) {
|
|
4
|
+
return new Promise((resolve) => {
|
|
5
|
+
setTimeout(() => resolve(value), timeoutMs);
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
exports.default = wait;
|
|
9
|
+
//# sourceMappingURL=wait.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wait.js","sourceRoot":"","sources":["../src/wait.ts"],"names":[],"mappings":";;AAAA,SAAwB,IAAI,CAAC,SAAiB,EAAE,QAAa,IAAI;IAC/D,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC;AAJD,uBAIC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sellout/utils",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Sellout.io utils",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "tsc --project .",
|
|
7
|
+
"start": "nodemon --watch src -e json,js,ts -x \"npm run build\""
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "www.github.com/sellout-tickets/sellout/commmon/utils"
|
|
12
|
+
},
|
|
13
|
+
"author": "samheutmaker@gmail.com",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@sellout/models": "^0.0.1",
|
|
17
|
+
"@sellout/service": "^0.0.1",
|
|
18
|
+
"json2csv": "^5.0.0",
|
|
19
|
+
"moment-timezone": "^0.5.28",
|
|
20
|
+
"request": "^2.88.2",
|
|
21
|
+
"request-promise-native": "^1.0.8"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^13.9.1",
|
|
25
|
+
"nodemon": "^2.0.2",
|
|
26
|
+
"typescript": "^3.8.3"
|
|
27
|
+
},
|
|
28
|
+
"gitHead": "5f577126fcc59699bc5447b62f0ee56aa4b9759b"
|
|
29
|
+
}
|
package/src/CSV.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AsyncParser } from 'json2csv';
|
|
2
|
+
|
|
3
|
+
export function fromJson(fields: string[], data: object): Promise<string> {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
const json = JSON.stringify(data);
|
|
6
|
+
const opts = { fields };
|
|
7
|
+
const transformOpts = {};
|
|
8
|
+
const asyncParser = new AsyncParser(opts, transformOpts);
|
|
9
|
+
|
|
10
|
+
let csv = '';
|
|
11
|
+
asyncParser.processor
|
|
12
|
+
.on('data', chunk => {
|
|
13
|
+
// console.log(chunk.toString());
|
|
14
|
+
csv += chunk.toString();
|
|
15
|
+
})
|
|
16
|
+
.on('end', () => resolve(csv))
|
|
17
|
+
.on('error', err => reject(err));
|
|
18
|
+
|
|
19
|
+
asyncParser.input.push(json);
|
|
20
|
+
asyncParser.input.push(null);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as Time from './time';
|
|
2
|
+
import * as request from 'request-promise-native';
|
|
3
|
+
import {
|
|
4
|
+
GOOGLE_TIMEZONE_API_KEY
|
|
5
|
+
} from './env';
|
|
6
|
+
|
|
7
|
+
export async function info(lat, lng): Promise<any> {
|
|
8
|
+
const baseUrl = 'https://maps.googleapis.com/maps/api/timezone/json';
|
|
9
|
+
const url = `${baseUrl}?location=${lat},${lng}×tamp=${Time.now()}&key=${GOOGLE_TIMEZONE_API_KEY}`;
|
|
10
|
+
const response = await request.get(url, {
|
|
11
|
+
json: true
|
|
12
|
+
});
|
|
13
|
+
return response;
|
|
14
|
+
}
|
|
15
|
+
|
package/src/IPStack.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as request from 'request-promise-native';
|
|
2
|
+
import {
|
|
3
|
+
IP_STACK_API_KEY,
|
|
4
|
+
LOAD_TEST_ENABLED,
|
|
5
|
+
} from "./env";
|
|
6
|
+
|
|
7
|
+
export async function gecodeIPAddress(ipAddress) {
|
|
8
|
+
// Return mock data for load testing
|
|
9
|
+
if(LOAD_TEST_ENABLED) {
|
|
10
|
+
return {
|
|
11
|
+
city: 'Polson',
|
|
12
|
+
region_code: 'MT',
|
|
13
|
+
zip: '59860',
|
|
14
|
+
country_code: 'US',
|
|
15
|
+
latitude: 47.6932,
|
|
16
|
+
longitude: 114.1631
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const url = `http://api.ipstack.com/${ipAddress}?access_key=${IP_STACK_API_KEY}`;
|
|
21
|
+
return await request.get(url, {
|
|
22
|
+
json: true
|
|
23
|
+
});
|
|
24
|
+
}
|
package/src/env.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export const GOOGLE_TIMEZONE_API_KEY = process.env.GOOGLE_TIMEZONE_API_KEY;
|
|
2
|
+
export const LOAD_TEST_ENABLED = process.env.LOAD_TEST_ENABLED === '1';
|
|
3
|
+
export const IP_STACK_API_KEY = process.env.IP_STACK_API_KEY;
|
|
4
|
+
export const NODE_ENV = process.env.NODE_ENV || 'development';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export default function formatPhoneNumber(phoneNumberString: string): string {
|
|
2
|
+
const cleaned = (`${phoneNumberString}`).replace(/\D/g, '');
|
|
3
|
+
let match = cleaned.match(/^(1|)?(\d{3})(\d{3})(\d{4})$/);
|
|
4
|
+
if (match) {
|
|
5
|
+
const intlCode = (match[1] ? '+1 ' : '');
|
|
6
|
+
return [intlCode, match[2], ' ', match[3], ' ', match[4]].join('');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
match = cleaned.match(/^(1|)?(\d{3})(\d{3})$/);
|
|
10
|
+
if (match) {
|
|
11
|
+
const intlCode = (match[1] ? '+1 ' : '');
|
|
12
|
+
return [intlCode, match[2], ' ', match[3]].join('');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
match = cleaned.match(/^(1|)?(\d{3})$/);
|
|
16
|
+
if (match) {
|
|
17
|
+
const intlCode = (match[1] ? '+1 ' : '');
|
|
18
|
+
return [intlCode, match[2]].join('');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return cleaned;
|
|
22
|
+
}
|
package/src/price.ts
ADDED
package/src/random.ts
ADDED
package/src/time.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as moment from 'moment-timezone';
|
|
2
|
+
|
|
3
|
+
export const SECOND = 1000;
|
|
4
|
+
export const MINUTE = 60 * SECOND;
|
|
5
|
+
export const HOUR = 60 * MINUTE;
|
|
6
|
+
export const DAY = 24 * HOUR;
|
|
7
|
+
|
|
8
|
+
export const now = function(): number {
|
|
9
|
+
const millis = Date.now();
|
|
10
|
+
const seconds = millis / 1000;
|
|
11
|
+
return Math.floor(seconds);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const date = function(seconds?: number): any {
|
|
15
|
+
if(!seconds) return new Date();
|
|
16
|
+
const millis = seconds * 1000;
|
|
17
|
+
return new Date(millis);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const fromDate = function(millis: number | string): number {
|
|
21
|
+
return Math.floor(new Date(millis).getTime() / 1000);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Use this one, it's better
|
|
25
|
+
export const format = function(secondsSinceEpoch, format = 'M/DD/YYYY h:mma', timezone: string = 'America/Denver' ) {
|
|
26
|
+
if(!timezone) timezone = 'America/Denver';
|
|
27
|
+
const millis = date(secondsSinceEpoch);
|
|
28
|
+
return moment(millis).tz(timezone).format(format);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const formatTimeOfDay = function (secondsSinceEpoch, timezone?: string) {
|
|
32
|
+
return format(secondsSinceEpoch, 'h:mma', timezone);
|
|
33
|
+
}
|
package/src/wait.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compileOnSave": true,
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": ".",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"target": "es6",
|
|
7
|
+
"module": "commonjs",
|
|
8
|
+
"outDir": "./.dist/",
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"strictNullChecks": true,
|
|
12
|
+
"noUnusedLocals": true,
|
|
13
|
+
"paths": {},
|
|
14
|
+
"types": [
|
|
15
|
+
"node",
|
|
16
|
+
]
|
|
17
|
+
},
|
|
18
|
+
"typeRoots": [
|
|
19
|
+
"node_modules/@types"
|
|
20
|
+
],
|
|
21
|
+
"include": [
|
|
22
|
+
"./src/**/*.ts"
|
|
23
|
+
],
|
|
24
|
+
"exclude": [
|
|
25
|
+
"node_modules"
|
|
26
|
+
]
|
|
27
|
+
}
|
package/tslint.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "tslint-config-airbnb",
|
|
3
|
+
"rules": {
|
|
4
|
+
"max-line-length": {
|
|
5
|
+
"options": [120]
|
|
6
|
+
},
|
|
7
|
+
"no-console": false,
|
|
8
|
+
"ban": [
|
|
9
|
+
true,
|
|
10
|
+
{
|
|
11
|
+
"name": ["Math", "random"],
|
|
12
|
+
"message": "Use a better RNG, perhaps UUID?"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"jsRules": {
|
|
17
|
+
"max-line-length": {
|
|
18
|
+
"options": [120]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|