@8ms/helpers 1.3.9 → 1.3.11
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/google/bigQuery/loadData.js +2 -1
- package/google/storage/getClient.d.ts +8 -0
- package/google/storage/getClient.js +18 -0
- package/google/storage/initClient.js +6 -0
- package/package.json +1 -1
- package/string/getCapitalised.d.ts +10 -0
- package/string/{formatCapitalise.js → getCapitalised.js} +4 -3
- package/string/getClean.d.ts +18 -0
- package/string/getClean.js +65 -0
- package/string/getCleanFolder.d.ts +4 -3
- package/string/getCleanFolder.js +4 -2
- package/string/{getUnescaped.d.ts → getDecoded.d.ts} +3 -3
- package/string/{getUnescaped.js → getDecoded.js} +2 -2
- package/string/{toProperCase.d.ts → getProperCase.d.ts} +2 -2
- package/string/{toProperCase.js → getProperCase.js} +4 -6
- package/string/getWithoutAccents.d.ts +9 -0
- package/string/getWithoutAccents.js +16 -0
- package/string/{getStrippedTags.d.ts → getWithoutHtmlTags.d.ts} +3 -3
- package/string/{getStrippedTags.js → getWithoutHtmlTags.js} +2 -2
- package/string/getWithoutPunctuation.d.ts +9 -0
- package/string/getWithoutPunctuation.js +16 -0
- package/string/getWithoutUnderscores.d.ts +8 -0
- package/string/getWithoutUnderscores.js +14 -0
- package/string/getWithoutWhitespaces.d.ts +9 -0
- package/string/getWithoutWhitespaces.js +16 -0
- package/string/formatCapitalise.d.ts +0 -9
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const IsTableExists_1 = __importDefault(require("./IsTableExists"));
|
|
7
7
|
const getClient_1 = __importDefault(require("./getClient"));
|
|
8
|
+
const getClient_2 = __importDefault(require("../storage/getClient"));
|
|
8
9
|
/**
|
|
9
10
|
* Load data into a given table.
|
|
10
11
|
*/
|
|
@@ -18,7 +19,7 @@ const loadData = async ({ file, table }) => {
|
|
|
18
19
|
let bigqueryClient = (0, getClient_1.default)({
|
|
19
20
|
projectId: table.projectId
|
|
20
21
|
});
|
|
21
|
-
let storageClient = (0,
|
|
22
|
+
let storageClient = (0, getClient_2.default)({
|
|
22
23
|
projectId: file.projectId
|
|
23
24
|
});
|
|
24
25
|
await bigqueryClient
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Create a new client if the project id differs from the global.
|
|
5
|
+
*/
|
|
6
|
+
const getClient = ({ projectId }) => {
|
|
7
|
+
let client = global.googleStorageClient;
|
|
8
|
+
if (undefined !== projectId && projectId !== global.googleStorageDefault.projectId) {
|
|
9
|
+
const { Storage } = require('@google-cloud/storage');
|
|
10
|
+
client = new Storage({
|
|
11
|
+
credentials: global.googleStorageDefault.credentials,
|
|
12
|
+
location: "europe-west2",
|
|
13
|
+
projectId: projectId,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return client;
|
|
17
|
+
};
|
|
18
|
+
exports.default = getClient;
|
|
@@ -4,6 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const getConfig_1 = __importDefault(require("../getConfig"));
|
|
7
|
+
global.googleStorageDefault = {
|
|
8
|
+
credentials: null,
|
|
9
|
+
projectId: null,
|
|
10
|
+
};
|
|
7
11
|
global.googleStorageClient = null;
|
|
8
12
|
/**
|
|
9
13
|
* Initialise the Google Sheets instance using the separate service method.
|
|
@@ -14,6 +18,8 @@ const initClient = ({ parameter, projectId }) => {
|
|
|
14
18
|
if (!global.googleStorageClient) {
|
|
15
19
|
const { Storage } = require('@google-cloud/storage');
|
|
16
20
|
const formattedConfig = (0, getConfig_1.default)({ parameter });
|
|
21
|
+
global.googleStorageDefault.credentials = formattedConfig;
|
|
22
|
+
global.googleStorageDefault.projectId = projectId;
|
|
17
23
|
global.googleStorageClient = new Storage({
|
|
18
24
|
credentials: formattedConfig,
|
|
19
25
|
projectId: projectId,
|
package/package.json
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type GetCapitalised = {
|
|
2
|
+
input: string;
|
|
3
|
+
split?: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Convert a string into Capitalised Text.
|
|
7
|
+
* https://stackoverflow.com/a/196991/2664955
|
|
8
|
+
*/
|
|
9
|
+
declare const getCapitalised: ({ input, split }: GetCapitalised) => string;
|
|
10
|
+
export default getCapitalised;
|
|
@@ -4,13 +4,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
* Convert a string into Capitalised Text.
|
|
5
5
|
* https://stackoverflow.com/a/196991/2664955
|
|
6
6
|
*/
|
|
7
|
-
const
|
|
7
|
+
const getCapitalised = ({ input, split }) => {
|
|
8
|
+
const splitToken = split || '_';
|
|
8
9
|
return input
|
|
9
|
-
.replace(`/${
|
|
10
|
+
.replace(`/${splitToken}/g`, ' ')
|
|
10
11
|
.replace(/\w\S*/g, function (txt) {
|
|
11
12
|
return txt.charAt(0)
|
|
12
13
|
.toUpperCase() + txt.substr(1)
|
|
13
14
|
.toLowerCase();
|
|
14
15
|
});
|
|
15
16
|
};
|
|
16
|
-
exports.default =
|
|
17
|
+
exports.default = getCapitalised;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type GetClean = {
|
|
2
|
+
accents?: boolean;
|
|
3
|
+
decoded?: boolean;
|
|
4
|
+
htmlTags?: boolean;
|
|
5
|
+
input: any;
|
|
6
|
+
lowercase?: boolean;
|
|
7
|
+
propercase?: boolean;
|
|
8
|
+
punctuation?: boolean;
|
|
9
|
+
trim?: boolean;
|
|
10
|
+
underscores?: boolean;
|
|
11
|
+
uppercase?: boolean;
|
|
12
|
+
whitespace?: boolean;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Shorthand function to get a clean version of a string.
|
|
16
|
+
*/
|
|
17
|
+
declare const getCleanString: ({ accents, decoded, htmlTags, input, lowercase, propercase, punctuation, trim, underscores, uppercase, whitespace }: GetClean) => string;
|
|
18
|
+
export default getCleanString;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const getString_1 = __importDefault(require("./getString"));
|
|
7
|
+
const getWithoutHtmlTags_1 = __importDefault(require("./getWithoutHtmlTags"));
|
|
8
|
+
const getWithoutAccents_1 = __importDefault(require("./getWithoutAccents"));
|
|
9
|
+
const getProperCase_1 = __importDefault(require("./getProperCase"));
|
|
10
|
+
const getWithoutWhitespaces_1 = __importDefault(require("./getWithoutWhitespaces"));
|
|
11
|
+
const getWithoutPunctuation_1 = __importDefault(require("./getWithoutPunctuation"));
|
|
12
|
+
const getWithoutUnderscores_1 = __importDefault(require("./getWithoutUnderscores"));
|
|
13
|
+
const getDecoded_1 = __importDefault(require("./getDecoded"));
|
|
14
|
+
/**
|
|
15
|
+
* Shorthand function to get a clean version of a string.
|
|
16
|
+
*/
|
|
17
|
+
const getCleanString = ({ accents, decoded, htmlTags, input, lowercase, propercase, punctuation, trim, underscores, uppercase, whitespace }) => {
|
|
18
|
+
let response = (0, getString_1.default)({ input });
|
|
19
|
+
if (decoded) {
|
|
20
|
+
response = (0, getDecoded_1.default)({
|
|
21
|
+
input: response,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (accents) {
|
|
25
|
+
response = (0, getWithoutAccents_1.default)({
|
|
26
|
+
input: response
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (htmlTags) {
|
|
30
|
+
response = (0, getWithoutHtmlTags_1.default)({
|
|
31
|
+
input: response
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (underscores) {
|
|
35
|
+
response = (0, getWithoutUnderscores_1.default)({
|
|
36
|
+
input: response,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (punctuation) {
|
|
40
|
+
response = (0, getWithoutPunctuation_1.default)({
|
|
41
|
+
input: response
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (whitespace) {
|
|
45
|
+
response = (0, getWithoutWhitespaces_1.default)({
|
|
46
|
+
input: response
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (lowercase) {
|
|
50
|
+
response = response.toLowerCase();
|
|
51
|
+
}
|
|
52
|
+
if (propercase) {
|
|
53
|
+
response = (0, getProperCase_1.default)({
|
|
54
|
+
input: response
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (uppercase) {
|
|
58
|
+
response = response.toUpperCase();
|
|
59
|
+
}
|
|
60
|
+
if (trim) {
|
|
61
|
+
response = response.trim();
|
|
62
|
+
}
|
|
63
|
+
return response;
|
|
64
|
+
};
|
|
65
|
+
exports.default = getCleanString;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
type GetCleanFolder = {
|
|
2
|
+
input: string;
|
|
3
|
+
};
|
|
1
4
|
/**
|
|
2
5
|
* Take an input that may have a / before or after the input and return just the folder.
|
|
3
6
|
*/
|
|
4
|
-
declare const getCleanFolder: ({ input }:
|
|
5
|
-
input: string;
|
|
6
|
-
}) => string;
|
|
7
|
+
declare const getCleanFolder: ({ input }: GetCleanFolder) => string;
|
|
7
8
|
export default getCleanFolder;
|
package/string/getCleanFolder.js
CHANGED
|
@@ -7,6 +7,8 @@ const trim_1 = __importDefault(require("lodash/trim"));
|
|
|
7
7
|
/**
|
|
8
8
|
* Take an input that may have a / before or after the input and return just the folder.
|
|
9
9
|
*/
|
|
10
|
-
const getCleanFolder = ({ input }) =>
|
|
11
|
-
.
|
|
10
|
+
const getCleanFolder = ({ input }) => {
|
|
11
|
+
return (0, trim_1.default)(input, '/')
|
|
12
|
+
.trim();
|
|
13
|
+
};
|
|
12
14
|
exports.default = getCleanFolder;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type
|
|
1
|
+
type GetDecoded = {
|
|
2
2
|
input: any;
|
|
3
3
|
};
|
|
4
4
|
/**
|
|
@@ -6,5 +6,5 @@ type GetUnescaped = {
|
|
|
6
6
|
* E.g. there's => there's
|
|
7
7
|
* https://stackoverflow.com/a/42182294/2664955
|
|
8
8
|
*/
|
|
9
|
-
declare const
|
|
10
|
-
export default
|
|
9
|
+
declare const getDecoded: ({ input }: GetDecoded) => string;
|
|
10
|
+
export default getDecoded;
|
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
* E.g. there's => there's
|
|
6
6
|
* https://stackoverflow.com/a/42182294/2664955
|
|
7
7
|
*/
|
|
8
|
-
const
|
|
8
|
+
const getDecoded = ({ input }) => {
|
|
9
9
|
let el = document.createElement("textarea");
|
|
10
10
|
el.innerHTML = input;
|
|
11
11
|
return el.value;
|
|
12
12
|
};
|
|
13
|
-
exports.default =
|
|
13
|
+
exports.default = getDecoded;
|
|
@@ -7,12 +7,10 @@ const getString_1 = __importDefault(require("./getString"));
|
|
|
7
7
|
/**
|
|
8
8
|
* Return a string "With Proper Casing".
|
|
9
9
|
*/
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
.join(' ');
|
|
14
|
-
return clean.replace(/\w\S*/g, word => word.charAt(0)
|
|
10
|
+
const getProperCase = ({ input }) => {
|
|
11
|
+
const response = (0, getString_1.default)({ input });
|
|
12
|
+
return response.replace(/\w\S*/g, word => word.charAt(0)
|
|
15
13
|
.toUpperCase() + word.substr(1)
|
|
16
14
|
.toLowerCase());
|
|
17
15
|
};
|
|
18
|
-
exports.default =
|
|
16
|
+
exports.default = getProperCase;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const getString_1 = __importDefault(require("./getString"));
|
|
7
|
+
/**
|
|
8
|
+
* Remove the accents from a string.
|
|
9
|
+
* https://stackoverflow.com/a/37511463
|
|
10
|
+
*/
|
|
11
|
+
const getWithoutAccents = ({ input }) => {
|
|
12
|
+
return (0, getString_1.default)({ input })
|
|
13
|
+
.normalize("NFD")
|
|
14
|
+
.replace(/[\u0300-\u036f]/g, "");
|
|
15
|
+
};
|
|
16
|
+
exports.default = getWithoutAccents;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
type
|
|
1
|
+
type GetWithoutHtmlTags = {
|
|
2
2
|
input: any;
|
|
3
3
|
};
|
|
4
4
|
/**
|
|
5
5
|
* Removes all HTML tags from an input.
|
|
6
6
|
* https://css-tricks.com/snippets/javascript/strip-html-tags-in-javascript/
|
|
7
7
|
*/
|
|
8
|
-
declare const
|
|
9
|
-
export default
|
|
8
|
+
declare const getWithoutHtmlTags: ({ input }: GetWithoutHtmlTags) => string;
|
|
9
|
+
export default getWithoutHtmlTags;
|
|
@@ -8,11 +8,11 @@ const getString_1 = __importDefault(require("./getString"));
|
|
|
8
8
|
* Removes all HTML tags from an input.
|
|
9
9
|
* https://css-tricks.com/snippets/javascript/strip-html-tags-in-javascript/
|
|
10
10
|
*/
|
|
11
|
-
const
|
|
11
|
+
const getWithoutHtmlTags = ({ input }) => {
|
|
12
12
|
const regexPattern = /(<([^>]+)>)/gi;
|
|
13
13
|
const inputString = (0, getString_1.default)({
|
|
14
14
|
input,
|
|
15
15
|
});
|
|
16
16
|
return inputString.replace(regexPattern, '');
|
|
17
17
|
};
|
|
18
|
-
exports.default =
|
|
18
|
+
exports.default = getWithoutHtmlTags;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type GetWithoutPunctuation = {
|
|
2
|
+
input: string;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* Remove all punctuation from a string and replace with a space.
|
|
6
|
+
* https://stackoverflow.com/a/25575009
|
|
7
|
+
*/
|
|
8
|
+
declare const getWithoutPunctuation: ({ input }: GetWithoutPunctuation) => string;
|
|
9
|
+
export default getWithoutPunctuation;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const getString_1 = __importDefault(require("./getString"));
|
|
7
|
+
/**
|
|
8
|
+
* Remove all punctuation from a string and replace with a space.
|
|
9
|
+
* https://stackoverflow.com/a/25575009
|
|
10
|
+
*/
|
|
11
|
+
const getWithoutPunctuation = ({ input }) => {
|
|
12
|
+
return (0, getString_1.default)({ input })
|
|
13
|
+
.replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]/g, '')
|
|
14
|
+
.replace(/\s+/g, ' ');
|
|
15
|
+
};
|
|
16
|
+
exports.default = getWithoutPunctuation;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const getString_1 = __importDefault(require("./getString"));
|
|
7
|
+
/**
|
|
8
|
+
* Replace all underscores with a space.
|
|
9
|
+
*/
|
|
10
|
+
const getWithoutUnderscores = ({ input }) => {
|
|
11
|
+
return (0, getString_1.default)({ input })
|
|
12
|
+
.replace('_', ' ');
|
|
13
|
+
};
|
|
14
|
+
exports.default = getWithoutUnderscores;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type GetWithoutWhitespaces = {
|
|
2
|
+
input: string;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* Remove all new lines, tabs multiple spaces, with a single space.
|
|
6
|
+
* https://stackoverflow.com/a/45029224
|
|
7
|
+
*/
|
|
8
|
+
declare const getWithoutWhitespaces: ({ input }: GetWithoutWhitespaces) => string;
|
|
9
|
+
export default getWithoutWhitespaces;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const getString_1 = __importDefault(require("./getString"));
|
|
7
|
+
/**
|
|
8
|
+
* Remove all new lines, tabs multiple spaces, with a single space.
|
|
9
|
+
* https://stackoverflow.com/a/45029224
|
|
10
|
+
*/
|
|
11
|
+
const getWithoutWhitespaces = ({ input }) => {
|
|
12
|
+
return (0, getString_1.default)({ input })
|
|
13
|
+
.replace(/\s+/g, ' ')
|
|
14
|
+
.trim();
|
|
15
|
+
};
|
|
16
|
+
exports.default = getWithoutWhitespaces;
|