@churchapps/apihelper 0.0.17 → 0.0.19

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.
@@ -0,0 +1,5 @@
1
+ export declare class SlugHelper {
2
+ static slugifyString(string: string, type: "urlPath" | "urlSlug", removeCharacters?: string[]): string;
3
+ static numerifySlug(slug: string): string;
4
+ }
5
+ //# sourceMappingURL=SlugHelper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SlugHelper.d.ts","sourceRoot":"","sources":["../../src/helpers/SlugHelper.ts"],"names":[],"mappings":"AAEA,qBAAa,UAAU;IAErB,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,SAAS,EAAE,gBAAgB,CAAC,EAAE,MAAM,EAAE;IAY7F,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM;CAqBjC"}
@@ -0,0 +1,40 @@
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
+ exports.SlugHelper = void 0;
7
+ const slug_1 = __importDefault(require("slug"));
8
+ class SlugHelper {
9
+ static slugifyString(string, type, removeCharacters) {
10
+ const charactersToRemove = removeCharacters ? removeCharacters : ["for", "and", "nor", "but", "or", "yet", "so", "the", "a", "an"];
11
+ const characStr = charactersToRemove.join("|");
12
+ if (type === "urlPath") {
13
+ slug_1.default.extend({ '/': '/' }); //To keep '/' in the url since it's a special character.
14
+ }
15
+ const initialSlug = (0, slug_1.default)(string, { remove: new RegExp('\\b(' + characStr + ')\\b', 'gi') });
16
+ const verfiedSlug = this.numerifySlug(initialSlug);
17
+ return verfiedSlug;
18
+ }
19
+ //remove multiple numbers in sequence
20
+ static numerifySlug(slug) {
21
+ let initialString = slug;
22
+ const regex = /\d+(?:-\d+)+|\d+/g;
23
+ const matchedArray = initialString.match(regex);
24
+ if (matchedArray) {
25
+ matchedArray.forEach((data) => {
26
+ const length = data.length;
27
+ let splitResult = data;
28
+ if (length > 1) {
29
+ const array = data.split("");
30
+ splitResult = array[0];
31
+ }
32
+ const replacedString = initialString.replace(data, splitResult);
33
+ initialString = replacedString;
34
+ });
35
+ }
36
+ return initialString;
37
+ }
38
+ }
39
+ exports.SlugHelper = SlugHelper;
40
+ //# sourceMappingURL=SlugHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SlugHelper.js","sourceRoot":"","sources":["../../src/helpers/SlugHelper.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAExB,MAAa,UAAU;IAErB,MAAM,CAAC,aAAa,CAAC,MAAc,EAAE,IAA2B,EAAE,gBAA2B;QAC3F,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;QACnI,MAAM,SAAS,GAAG,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC/C,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,cAAI,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,wDAAwD;QACrF,CAAC;QACD,MAAM,WAAW,GAAG,IAAA,cAAI,EAAC,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,MAAM,CAAC,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;QAC5F,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QACnD,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,qCAAqC;IACrC,MAAM,CAAC,YAAY,CAAC,IAAY;QAC9B,IAAI,aAAa,GAAG,IAAI,CAAC;QACzB,MAAM,KAAK,GAAG,mBAAmB,CAAC;QAClC,MAAM,YAAY,GAAG,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAEhD,IAAI,YAAY,EAAE,CAAC;YACjB,YAAY,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;gBAC5B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;gBAC3B,IAAI,WAAW,GAAG,IAAI,CAAC;gBACvB,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;oBACf,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;oBAC7B,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;gBACzB,CAAC;gBACD,MAAM,cAAc,GAAG,aAAa,CAAC,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;gBAChE,aAAa,GAAG,cAAc,CAAC;YACjC,CAAC,CAAC,CAAC;QACL,CAAC;QAED,OAAO,aAAa,CAAC;IACvB,CAAC;CAEF;AAnCD,gCAmCC"}
@@ -12,4 +12,5 @@ export * from "./BasePermissions";
12
12
  export * from "./EmailHelper";
13
13
  export * from "./MySqlHelper";
14
14
  export * from "./Pool";
15
+ export * from "./SlugHelper";
15
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,MAAM,CAAC;AACrB,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,MAAM,CAAC;AACrB,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC"}
@@ -28,4 +28,5 @@ __exportStar(require("./BasePermissions"), exports);
28
28
  __exportStar(require("./EmailHelper"), exports);
29
29
  __exportStar(require("./MySqlHelper"), exports);
30
30
  __exportStar(require("./Pool"), exports);
31
+ __exportStar(require("./SlugHelper"), exports);
31
32
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,8CAA4B;AAC5B,uCAAqB;AACrB,8CAA4B;AAC5B,qDAAmC;AACnC,oDAAkC;AAClC,sDAAoC;AACpC,+CAA6B;AAC7B,kDAAgC;AAChC,8CAA4B;AAC5B,oDAAkC;AAClC,gDAA8B;AAC9B,gDAA8B;AAC9B,yCAAsB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,8CAA4B;AAC5B,uCAAqB;AACrB,8CAA4B;AAC5B,qDAAmC;AACnC,oDAAkC;AAClC,sDAAoC;AACpC,+CAA6B;AAC7B,kDAAgC;AAChC,8CAA4B;AAC5B,oDAAkC;AAClC,gDAA8B;AAC9B,gDAA8B;AAC9B,yCAAuB;AACvB,+CAA6B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@churchapps/apihelper",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "description": "Library of helper functions not specific to any one ChurchApps project or framework.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -45,6 +45,7 @@
45
45
  "nodemailer-direct-transport": "^3.3.2",
46
46
  "react-ga4": "^2.1.0",
47
47
  "rrule": "^2.7.2",
48
+ "slug": "^10.0.0",
48
49
  "winston": "^3.10.0",
49
50
  "winston-cloudwatch": "^6.2.0"
50
51
  },
@@ -57,6 +58,7 @@
57
58
  "@types/node": "^20.5.6",
58
59
  "@types/nodemailer": "^6.4.4",
59
60
  "@types/nodemailer-direct-transport": "^1.0.32",
61
+ "@types/slug": "^5.0.9",
60
62
  "copyfiles": "^2.4.1",
61
63
  "npm-run-all": "^4.1.5",
62
64
  "rimraf": "^5.0.1",
@@ -0,0 +1,38 @@
1
+ import slug from "slug";
2
+
3
+ export class SlugHelper {
4
+
5
+ static slugifyString(string: string, type: "urlPath" | "urlSlug", removeCharacters?: string[]) {
6
+ const charactersToRemove = removeCharacters ? removeCharacters : ["for", "and", "nor", "but", "or", "yet", "so", "the", "a", "an"];
7
+ const characStr = charactersToRemove.join("|");
8
+ if (type === "urlPath") {
9
+ slug.extend({ '/': '/' }); //To keep '/' in the url since it's a special character.
10
+ }
11
+ const initialSlug = slug(string, { remove: new RegExp('\\b(' + characStr + ')\\b', 'gi') });
12
+ const verfiedSlug = this.numerifySlug(initialSlug);
13
+ return verfiedSlug;
14
+ }
15
+
16
+ //remove multiple numbers in sequence
17
+ static numerifySlug(slug: string) {
18
+ let initialString = slug;
19
+ const regex = /\d+(?:-\d+)+|\d+/g;
20
+ const matchedArray = initialString.match(regex);
21
+
22
+ if (matchedArray) {
23
+ matchedArray.forEach((data) => {
24
+ const length = data.length;
25
+ let splitResult = data;
26
+ if (length > 1) {
27
+ const array = data.split("");
28
+ splitResult = array[0];
29
+ }
30
+ const replacedString = initialString.replace(data, splitResult);
31
+ initialString = replacedString;
32
+ });
33
+ }
34
+
35
+ return initialString;
36
+ }
37
+
38
+ }
@@ -11,4 +11,5 @@ export * from "./OmitEmpty";
11
11
  export * from "./BasePermissions";
12
12
  export * from "./EmailHelper";
13
13
  export * from "./MySqlHelper";
14
- export * from "./Pool"
14
+ export * from "./Pool";
15
+ export * from "./SlugHelper";