@churchapps/apphelper 0.1.9 → 0.1.10

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;YACtB,cAAI,CAAC,MAAM,CAAC,EAAC,GAAG,EAAE,GAAG,EAAC,CAAC,CAAC,CAAC,wDAAwD;SAClF;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;YAChB,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;oBACd,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;oBAC7B,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;iBACxB;gBACD,MAAM,cAAc,GAAG,aAAa,CAAC,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;gBAChE,aAAa,GAAG,cAAc,CAAC;YACjC,CAAC,CAAC,CAAC;SACJ;QAED,OAAO,aAAa,CAAC;IACvB,CAAC;CAEF;AAnCD,gCAmCC"}
@@ -16,4 +16,5 @@ export { UniqueIdHelper } from "./UniqueIdHelper";
16
16
  export { createEmotionCache } from "./createEmotionCache";
17
17
  export { DonationHelper } from "./DonationHelper";
18
18
  export { AppearanceInterface, AppearanceHelper } from "./AppearanceHelper";
19
+ export { SlugHelper } from "./SlugHelper";
19
20
  //# 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,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,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,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.AppearanceHelper = exports.DonationHelper = exports.createEmotionCache = exports.UniqueIdHelper = exports.UserHelper = exports.Themes = exports.SocketHelper = exports.PersonHelper = exports.FileHelper = exports.EventHelper = exports.ErrorHelper = exports.DateHelper = exports.CurrencyHelper = exports.CommonEnvironmentHelper = exports.ArrayHelper = exports.ApiHelper = exports.AnalyticsHelper = void 0;
17
+ exports.SlugHelper = exports.AppearanceHelper = exports.DonationHelper = exports.createEmotionCache = exports.UniqueIdHelper = exports.UserHelper = exports.Themes = exports.SocketHelper = exports.PersonHelper = exports.FileHelper = exports.EventHelper = exports.ErrorHelper = exports.DateHelper = exports.CurrencyHelper = exports.CommonEnvironmentHelper = exports.ArrayHelper = exports.ApiHelper = exports.AnalyticsHelper = void 0;
18
18
  __exportStar(require("@churchapps/helpers"), exports);
19
19
  var AnalyticsHelper_1 = require("./AnalyticsHelper");
20
20
  Object.defineProperty(exports, "AnalyticsHelper", { enumerable: true, get: function () { return AnalyticsHelper_1.AnalyticsHelper; } });
@@ -50,4 +50,6 @@ var DonationHelper_1 = require("./DonationHelper");
50
50
  Object.defineProperty(exports, "DonationHelper", { enumerable: true, get: function () { return DonationHelper_1.DonationHelper; } });
51
51
  var AppearanceHelper_1 = require("./AppearanceHelper");
52
52
  Object.defineProperty(exports, "AppearanceHelper", { enumerable: true, get: function () { return AppearanceHelper_1.AppearanceHelper; } });
53
+ var SlugHelper_1 = require("./SlugHelper");
54
+ Object.defineProperty(exports, "SlugHelper", { enumerable: true, get: function () { return SlugHelper_1.SlugHelper; } });
53
55
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AACpB,qEAAoE;AAA3D,kIAAA,uBAAuB,OAAA;AAChC,mDAAiD;AAAxC,gHAAA,cAAc,OAAA;AACvB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AACpB,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AACpB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,+CAA6C;AAApC,4GAAA,YAAY,OAAA;AACrB,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,mCAAiC;AAAxB,gGAAA,MAAM,OAAA;AACf,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AAC3B,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,uDAA2E;AAA7C,oHAAA,gBAAgB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AACpB,qEAAoE;AAA3D,kIAAA,uBAAuB,OAAA;AAChC,mDAAiD;AAAxC,gHAAA,cAAc,OAAA;AACvB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AACpB,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AACpB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,+CAA6C;AAApC,4GAAA,YAAY,OAAA;AACrB,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,mCAAiC;AAAxB,gGAAA,MAAM,OAAA;AACf,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AAC3B,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,uDAA2E;AAA7C,oHAAA,gBAAgB,OAAA;AAC9C,2CAA0C;AAAjC,wGAAA,UAAU,OAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@churchapps/apphelper",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "Library of helper functions for React and NextJS ChurchApps",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -67,7 +67,8 @@
67
67
  "react-google-charts": "^3.0.15",
68
68
  "react-google-recaptcha": "^3.1.0",
69
69
  "react-to-print": "^2.14.13",
70
- "rrule": "^2.7.2"
70
+ "rrule": "^2.7.2",
71
+ "slug": "^8.2.3"
71
72
  },
72
73
  "devDependencies": {
73
74
  "@types/node": "^20.5.9",
@@ -75,6 +76,7 @@
75
76
  "@types/react-csv": "^1.1.3",
76
77
  "@types/react-dom": "^18.2.7",
77
78
  "@types/react-google-recaptcha": "^2.1.5",
79
+ "@types/slug": "^5.0.7",
78
80
  "copyfiles": "^2.4.1",
79
81
  "eslint-config-react-app": "^7.0.1",
80
82
  "eslint-plugin-react": "^7.33.2",
@@ -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
+ }
@@ -16,3 +16,4 @@ export { UniqueIdHelper } from "./UniqueIdHelper";
16
16
  export { createEmotionCache } from "./createEmotionCache";
17
17
  export { DonationHelper } from "./DonationHelper";
18
18
  export { AppearanceInterface, AppearanceHelper } from "./AppearanceHelper";
19
+ export { SlugHelper } from "./SlugHelper";