@8ms/helpers 1.3.10 → 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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "1.3.10",
4
+ "version": "1.3.11",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
@@ -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 formatCapitalise = ({ input, split } = { input: '', split: '_' }) => {
7
+ const getCapitalised = ({ input, split }) => {
8
+ const splitToken = split || '_';
8
9
  return input
9
- .replace(`/${split}/g`, ' ')
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 = formatCapitalise;
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;
@@ -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 }) => (0, trim_1.default)(input, '/')
11
- .trim();
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 GetUnescaped = {
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 getUnescaped: ({ input }: GetUnescaped) => string;
10
- export default getUnescaped;
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 getUnescaped = ({ input }) => {
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 = getUnescaped;
13
+ exports.default = getDecoded;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Return a string "With Proper Casing".
3
3
  */
4
- declare const toProperCase: ({ input }: {
4
+ declare const getProperCase: ({ input }: {
5
5
  input: any;
6
6
  }) => string;
7
- export default toProperCase;
7
+ export default getProperCase;
@@ -7,12 +7,10 @@ const getString_1 = __importDefault(require("./getString"));
7
7
  /**
8
8
  * Return a string "With Proper Casing".
9
9
  */
10
- const toProperCase = ({ input }) => {
11
- const preparedInput = (0, getString_1.default)({ input });
12
- const clean = preparedInput.split('_')
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 = toProperCase;
16
+ exports.default = getProperCase;
@@ -0,0 +1,9 @@
1
+ type GetWithoutAccents = {
2
+ input: string;
3
+ };
4
+ /**
5
+ * Remove the accents from a string.
6
+ * https://stackoverflow.com/a/37511463
7
+ */
8
+ declare const getWithoutAccents: ({ input }: GetWithoutAccents) => string;
9
+ export default getWithoutAccents;
@@ -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 GetStrippedTags = {
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 getStrippedTags: ({ input }: GetStrippedTags) => string;
9
- export default getStrippedTags;
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 getStrippedTags = ({ input }) => {
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 = getStrippedTags;
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,8 @@
1
+ type GetWithoutUnderscores = {
2
+ input: string;
3
+ };
4
+ /**
5
+ * Replace all underscores with a space.
6
+ */
7
+ declare const getWithoutUnderscores: ({ input }: GetWithoutUnderscores) => string;
8
+ export default getWithoutUnderscores;
@@ -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;
@@ -1,9 +0,0 @@
1
- /**
2
- * Convert a string into Capitalised Text.
3
- * https://stackoverflow.com/a/196991/2664955
4
- */
5
- declare const formatCapitalise: ({ input, split }?: {
6
- input: string;
7
- split: string;
8
- }) => string;
9
- export default formatCapitalise;