@ibiliaze/stringman 1.2.1 → 2.0.0

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/dist/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
1
  export declare const superTrim: (stringData: any) => any;
2
2
  export declare const megaTrim: (stringData: any) => any;
3
3
  export declare const dp: (int: any, i: any) => number;
4
+ export declare const getCloudinaryPublicId: (url: string) => string;
5
+ export declare const query: (q: Record<string, any>) => string;
6
+ export declare const select: <T>(keys: (keyof T)[]) => string;
package/dist/index.js CHANGED
@@ -1,9 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dp = exports.megaTrim = exports.superTrim = void 0;
4
- const superTrim = (stringData) => stringData.replace(/\s\s+/g, " ").trim();
3
+ exports.select = exports.query = exports.getCloudinaryPublicId = exports.dp = exports.megaTrim = exports.superTrim = void 0;
4
+ const superTrim = stringData => stringData.replace(/\s\s+/g, ' ').trim();
5
5
  exports.superTrim = superTrim;
6
- const megaTrim = (stringData) => stringData.replace(/\s\s+/g, "");
6
+ const megaTrim = stringData => stringData.replace(/\s\s+/g, '');
7
7
  exports.megaTrim = megaTrim;
8
- const dp = (int, i) => (typeof int === "number" ? +int.toFixed(i) : 0);
8
+ const dp = (int, i) => (typeof int === 'number' ? +int.toFixed(i) : 0);
9
9
  exports.dp = dp;
10
+ const getCloudinaryPublicId = (url) => {
11
+ try {
12
+ const public_id_with_extension = url.replace(/^https?:\/\/res\.cloudinary\.com\/[^/]+\/image\/upload\/v\d+\//, '');
13
+ // Decode URL encoding (e.g., %20 → space)
14
+ const public_id = decodeURIComponent(public_id_with_extension.replace(/\.[^.]+$/, ''));
15
+ return public_id;
16
+ }
17
+ catch (e) {
18
+ return '';
19
+ }
20
+ };
21
+ exports.getCloudinaryPublicId = getCloudinaryPublicId;
22
+ const query = (q) => {
23
+ try {
24
+ const filter = ['', null, undefined, 'null', 'undefined'];
25
+ const filtered = Object.entries(q).filter(([key, value]) => !filter.includes(key) && !filter.includes(value));
26
+ const query = new URLSearchParams(filtered).toString();
27
+ return query ? `?${query}` : '';
28
+ }
29
+ catch (e) {
30
+ console.error(e);
31
+ return '';
32
+ }
33
+ };
34
+ exports.query = query;
35
+ const select = (keys) => {
36
+ return keys.join(',');
37
+ };
38
+ exports.select = select;
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@ibiliaze/stringman",
3
- "version": "1.2.1",
3
+ "version": "2.0.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
9
  "pub": "npm publish --access public",
10
- "git": "git add .; git commit -m 'changes'; git tag -a v1.2.1 -m 'v1.2.1'; git push origin v1.2.1; git push"
10
+ "git": "git add .; git commit -m 'changes'; git tag -a v2.0.0 -m 'v2.0.0'; git push origin v2.0.0; git push",
11
+ "push": "npm run build; npm run git; npm run pub"
11
12
  },
12
13
  "author": "Ibi Hasanli",
13
14
  "license": "ISC",
package/src/index.ts CHANGED
@@ -1,3 +1,33 @@
1
- export const superTrim = (stringData) => stringData.replace(/\s\s+/g, " ").trim();
2
- export const megaTrim = (stringData) => stringData.replace(/\s\s+/g, "");
3
- export const dp = (int, i) => (typeof int === "number" ? +int.toFixed(i) : 0);
1
+ export const superTrim = stringData => stringData.replace(/\s\s+/g, ' ').trim();
2
+ export const megaTrim = stringData => stringData.replace(/\s\s+/g, '');
3
+ export const dp = (int, i) => (typeof int === 'number' ? +int.toFixed(i) : 0);
4
+ export const getCloudinaryPublicId = (url: string): string => {
5
+ try {
6
+ const public_id_with_extension = url.replace(/^https?:\/\/res\.cloudinary\.com\/[^/]+\/image\/upload\/v\d+\//, '');
7
+
8
+ // Decode URL encoding (e.g., %20 → space)
9
+ const public_id = decodeURIComponent(public_id_with_extension.replace(/\.[^.]+$/, ''));
10
+
11
+ return public_id;
12
+ } catch (e) {
13
+ return '';
14
+ }
15
+ };
16
+ export const query = (q: Record<string, any>): string => {
17
+ try {
18
+ const filter = ['', null, undefined, 'null', 'undefined'];
19
+
20
+ const filtered = Object.entries(q).filter(([key, value]) => !filter.includes(key) && !filter.includes(value));
21
+
22
+ const query = new URLSearchParams(filtered as [string, string][]).toString();
23
+
24
+ return query ? `?${query}` : '';
25
+ } catch (e) {
26
+ console.error(e);
27
+ return '';
28
+ }
29
+ };
30
+
31
+ export const select = <T>(keys: (keyof T)[]): string => {
32
+ return keys.join(',');
33
+ };
package/tsconfig.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "outDir": "dist",
4
4
  "declaration": true,
5
5
  "module": "commonjs",
6
- "target": "es6"
6
+ "target": "es2024"
7
7
  },
8
8
  "include": ["src/**/*"]
9
9
  }