@fallencodes/seyfert-utils 1.2.7 → 1.2.8

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.
@@ -13,5 +13,6 @@ export declare function replacer(_key: string, value: any): any;
13
13
  export declare function numberToHex(color: number): string;
14
14
  export declare function apiRoleColorsToArray(apiColors: APIRoleColors | ObjectToLower<APIRoleColors>): number[];
15
15
  export declare function getValueFromPath<T extends Record<string, any>>(object: T, path: string): unknown | undefined;
16
+ export declare function truncateStringArray(array: string[], maxLength?: number, separator?: string): string[];
16
17
  export {};
17
18
  //# sourceMappingURL=utilities.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,wBAAgB,CAAC,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEzC;AAGD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE/C;AAGD,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAEnD;AAGD,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAI3D;AAGD,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,GAAE,MAAY,GAAG,MAAM,CAI9E;AAED,KAAK,QAAQ,GACX,SAAS,GACT,WAAW,GACX,kBAAkB,GAClB,oBAAoB,GACpB,aAAa,GACb,eAAe,CAAA;AAGjB,wBAAgB,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,GAAG,sBAAsB,EAAE,IAAI,GAAE,QAAoB,GAAG,MAAM,C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AW,GAAG,sBAAsB,EAAE,IAAI,GAAE,QAAoB,GAAG,MAAM,CAW1G;AAGD,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,OAG/C;AAGD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,OAIhD;AAGD,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,UAExC;AAGD,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,aAAa,GAAG,aAAa,CAAC,aAAa,CAAC,GAAG,MAAM,EAAE,CAUtG;AAID,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAE5G;AAGD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,SAAS,GAAE,MAAa,EAAE,SAAS,GAAE,MAAa,YActG"}
@@ -89,3 +89,19 @@ export function getValueFromPath(object, path) {
89
89
  return path.split('.').reduce((acc, key) => ((acc && (key in acc)) ? acc[key] : undefined), object);
90
90
  }
91
91
  ;
92
+ /* Truncates an array of strings to a specific character length. */
93
+ export function truncateStringArray(array, maxLength = 1000, separator = ', ') {
94
+ const string = array.join(separator);
95
+ const stringLength = length(string);
96
+ if (stringLength <= maxLength)
97
+ return array;
98
+ const truncated = string.slice(0, maxLength);
99
+ const lastSep = truncated.lastIndexOf(separator);
100
+ if (lastSep === -1)
101
+ return [];
102
+ const newArray = truncated.slice(0, lastSep).split(separator);
103
+ const removedItems = array.length - newArray.length;
104
+ newArray.push(`${removedItems} more...`);
105
+ return newArray;
106
+ }
107
+ ;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fallencodes/seyfert-utils",
3
3
  "type": "module",
4
- "version": "1.2.7",
4
+ "version": "1.2.8",
5
5
  "license": "MIT",
6
6
  "description": "A collection of various utility/helper code I use in my Seyfert projects.",
7
7
  "main": "build/index.js",