mp-js-api 0.0.18 → 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.
@@ -1,5 +1,7 @@
1
1
  export declare function stringifyURLParams<T = any>(mpOptions?: Record<string, T>): string;
2
2
  export declare function escapeSql(str: string): string;
3
+ export declare function escapeApostrophe<T = string>(str: string): T;
4
+ export declare function escapeApostrophes<T>(obj: T): T;
3
5
  export declare function toCamelCase(str: string, { capitalIds }?: {
4
6
  capitalIds?: boolean;
5
7
  }): string;
@@ -1 +1 @@
1
- {"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../src/utils/converters.ts"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,GAAG,EAAE,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAM,UAS5E;AAGD,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,UA2BpC;AAID,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,UAAkB,EAAE,GAAE;IAAE,UAAU,CAAC,EAAE,OAAO,CAAC;CAAM,UAQ7F;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,UAAkB,EAAE,YAAmB,EAAE,GAAE;IAAE,UAAU,CAAC,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,OAAO,CAAC;CAAM,UAKjJ;AAGD,wBAAgB,aAAa,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,UAAkB,EAAE,EAAE;IAAE,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAC;CAAE,OAkB5H;AAED,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,UAAU,UAAO,GAAG,CAAC,CAE1F;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AE,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,UAAU,UAAO,GAAG,CAAC,CAE1F"}
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stringifyURLParams = stringifyURLParams;
4
4
  exports.escapeSql = escapeSql;
5
+ exports.escapeApostrophe = escapeApostrophe;
6
+ exports.escapeApostrophes = escapeApostrophes;
5
7
  exports.toCamelCase = toCamelCase;
6
8
  exports.toCapitalSnakeCase = toCapitalSnakeCase;
7
9
  exports.caseConverter = caseConverter;
@@ -46,6 +48,28 @@ function escapeSql(str) {
46
48
  }
47
49
  });
48
50
  }
51
+ function escapeApostrophe(str) {
52
+ return str.replace(/%|(?<=\w)'(?=\w)/g, function (char) {
53
+ switch (char) {
54
+ case "'":
55
+ return "''";
56
+ default:
57
+ return char;
58
+ }
59
+ });
60
+ }
61
+ function escapeApostrophes(obj) {
62
+ if (obj !== null && typeof obj === 'object') {
63
+ for (const key in obj) {
64
+ if (obj.hasOwnProperty(key)) {
65
+ const value = obj[key];
66
+ obj[key] = escapeApostrophe(value);
67
+ }
68
+ }
69
+ return obj;
70
+ }
71
+ return obj; // Return value if it's neither an array nor an object
72
+ }
49
73
  function toCamelCase(str, { capitalIds = false } = {}) {
50
74
  str = str.replace('-', '');
51
75
  str = str.toLowerCase();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mp-js-api",
3
- "version": "0.0.18",
3
+ "version": "0.0.19",
4
4
  "description": "Node MinistryPlatform API",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -39,19 +39,46 @@ export function escapeSql(str: string) {
39
39
  });
40
40
  }
41
41
 
42
+ export function escapeApostrophe<T = string>(str: string): T {
43
+ return str.replace(/%|(?<=\w)'(?=\w)/g, function (char) {
44
+ switch (char) {
45
+ case "'":
46
+ return "''";
47
+ default:
48
+ return char;
49
+ }
50
+ }) as T;
51
+ }
42
52
 
53
+ export function escapeApostrophes<T>(obj: T) {
43
54
 
44
- export function toCamelCase(str: string, { capitalIds = false }: { capitalIds?: boolean; }= {}) {
45
- str = str.replace('-', '')
55
+ if (obj !== null && typeof obj === 'object') {
56
+ for (const key in obj) {
57
+ if (obj.hasOwnProperty(key)) {
58
+ const value = obj[key];
59
+ obj[key] = escapeApostrophe<typeof value>(value as string);
60
+ }
61
+ }
62
+ return obj;
63
+ }
64
+
65
+ return obj; // Return value if it's neither an array nor an object
66
+ }
67
+
68
+
69
+
70
+
71
+ export function toCamelCase(str: string, { capitalIds = false }: { capitalIds?: boolean; } = {}) {
72
+ str = str.replace('-', '');
46
73
  str = str.toLowerCase();
47
- // str = str.replace(/^_?[A-Z]{1,3}/, match => match.toLowerCase()); // Don't convert if start with ID, HS, SMS, etc
48
- str = str.replace(/(?<!^_|^)[^a-zA-Z0-9_][^\W_]/g, match => match?.toUpperCase()); // capitalize after non word char
74
+ // str = str.replace(/^_?[A-Z]{1,3}/, match => match.toLowerCase()); // Don't convert if start with ID, HS, SMS, etc
75
+ str = str.replace(/(?<!^_|^)[^a-zA-Z0-9_][^\W_]/g, match => match?.toUpperCase()); // capitalize after non word char
49
76
  str = str.replace(/(?<=^_|^__)[^\W_]/g, match => match.at(-1)?.toLowerCase() || ''); // keep underscore if first char
50
77
  str = str.replace(/(?<!^_|^)_[^\W_]/g, match => match.charAt(1).toUpperCase()); // remove non-word char if not first char
51
78
  return capitalIds ? str.replace(/id$/i, 'ID') : str;
52
79
  }
53
80
 
54
- export function toCapitalSnakeCase(str: string, { capitalIds = false, capitalSnake = true }: { capitalIds?: boolean, capitalSnake?: boolean; }= {}) {
81
+ export function toCapitalSnakeCase(str: string, { capitalIds = false, capitalSnake = true }: { capitalIds?: boolean, capitalSnake?: boolean; } = {}) {
55
82
  str = str.replace(/(?<=^_|^__)[^\W_]/, match => match.at(0)?.toUpperCase() || '');
56
83
  str = str.replace(/(?<!_|\/)(ID|[A-Z]|\d)/g, match => `_${match}`);
57
84
  str = capitalSnake ? str.charAt(0).toUpperCase() + str.slice(1) : str;
@@ -86,4 +113,3 @@ export function convertToCamelCase<T = any, R = any>(obj: Partial<T>, capitalIds
86
113
  export function convertToSnakeCase<T = any, R = any>(obj: Partial<T>, capitalIds = true): R {
87
114
  return caseConverter(obj, { type: 'toSnake', capitalIds });
88
115
  }
89
-