asv-hlps 1.4.67 → 1.4.68

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.
@@ -28,8 +28,9 @@ export default interface User extends Address {
28
28
  foto?: string;
29
29
  clp?: string;
30
30
  periodBill?: string;
31
- limitAmountSaleByMonth?: number;
32
- limitAmountSaleIsActive?: boolean;
31
+ limitSaleAmount?: number;
32
+ maxLimitSaleAmount?: number;
33
+ hasLimitSaleAmount?: boolean;
33
34
  hasBillSafe?: boolean;
34
35
  gender?: Gender;
35
36
  titr?: UserTitr;
@@ -124,6 +124,33 @@ export declare const checkEveryOnArrayByProp: (tobs: any[], property: string) =>
124
124
  export declare const pathName: (location: any) => any;
125
125
  export declare const nthIndexOf: (str: string, charToFind: string, nthPosition?: number) => number;
126
126
  export declare const partOfStringBetweenTwoSpeChar: (str: string, position1: number, position2: number, char?: string) => string;
127
+ /**
128
+ * Groups an array of objects by a specified property (supports nested properties using dot notation).
129
+ *
130
+ * @param tobs - The array of objects to group
131
+ * @param prop - The property name to group by (supports nested properties like "user.name")
132
+ * @param groupKey - The key name for the grouped value in the result (default: "tob")
133
+ * @param groupArrayKey - The key name for the array of grouped items in the result (default: "arr")
134
+ * @returns An array of objects where each object contains the group key and an array of items belonging to that group
135
+ *
136
+ * @example
137
+ * const data = [
138
+ * { id: 1, category: 'A', value: 10 },
139
+ * { id: 2, category: 'B', value: 20 },
140
+ * { id: 3, category: 'A', value: 30 }
141
+ * ];
142
+ *
143
+ * groupedByProp(data, 'category');
144
+ * // Returns:
145
+ * // [
146
+ * // { tob: 'A', arr: [{ id: 1, category: 'A', value: 10 }, { id: 3, category: 'A', value: 30 }] },
147
+ * // { tob: 'B', arr: [{ id: 2, category: 'B', value: 20 }] }
148
+ * // ]
149
+ *
150
+ * // With nested properties:
151
+ * groupedByProp(data, 'user.role');
152
+ */
127
153
  export declare const groupedByProp: (tobs: object[], prop: string, groupKey?: string, groupArrayKey?: string) => {
128
154
  [x: string]: unknown;
129
155
  }[];
156
+ export declare const getNestedValue: (obj: any, path: string) => any;
package/lib/cjs/utils.js CHANGED
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.dateNth = exports.dateNthMonth = exports.dateNthDay = exports.dateNthWeek = exports.getNbOfDaysBetweenTwoDates = exports.displayDateRangeFr = exports.reformatDates = exports.firstDayOfDate = exports.dateToString = exports.dateDiff = exports.dateFormatter = exports.replaceSpacesWith = exports.replaceAllIn = exports.toPlural = exports.sesStorageGet = exports.sesStorageSet = exports.genSequenceRef = exports.removeSpecialCharsAndSpaces = exports.refGenerator = exports.removeAMPM = exports.removeBackSlashOccurences = exports.stringifyFormatter = exports.removeString = exports.diffArraysByProp = exports.diffArraysByFunc = exports.deepClone = exports.findFirstSequenceMissing = exports.fillNumWithZero = exports.findSequencesMissing = exports.removeAccent = exports.sequencesToNumbers = exports.notInSequence = exports.currencyFormatterCfa = exports.currencyFormatter = exports.checkAuth = exports.wakeUp = exports.sleep = exports.limitTo = exports.titleCase = exports.toObjectDate = exports.duplicateObjectsGrouped = exports.duplicateObjects = exports.removeDuplicateValues = exports.removeDuplicateObjects = exports.getRandomColor = exports.calPercent = exports.percentOf = exports.genDateMinutesStep = exports.formatDateFirstDayFr = exports.isEmpty = void 0;
7
- exports.groupedByProp = exports.partOfStringBetweenTwoSpeChar = exports.nthIndexOf = exports.pathName = exports.checkEveryOnArrayByProp = exports.checkObjInArray = exports.arraySome = exports.winMaxHeight = exports.toggleProp = exports.roundLastNDigits = exports.removeParamKeyName = exports.countryIsoToFlag = exports.monthStringName = exports.returnBool = exports.formatAmountToString = exports.reduceTimes = exports.reduceSum = exports.sumAmount = exports.fillEndWithZero = exports.fillStartWithZero = exports.absFromSequence = exports.returnDates = exports.displayFrDatePeriode = exports.getArrayOfRandomColor = exports.randomHslColor = exports.randomHexColor = exports.genRandomNumberArray = exports.randomRgbColor = exports.randomInteger = exports.insertAtInArray = exports.isBirthday = exports.padEndWithZero = exports.padStartWithZero = exports.formatMonthYearToLocaleString = exports.calculPercent = exports.validEmail = exports.convertToCfa = exports.packAndUnit = exports.unCheckedAll = exports.inputChecked = exports.arrayMultiChecked = exports.getPeriodDateColor = exports.getColorAccordingToDate = exports.genRandomColour = exports.formatNgbDate = void 0;
7
+ exports.getNestedValue = exports.groupedByProp = exports.partOfStringBetweenTwoSpeChar = exports.nthIndexOf = exports.pathName = exports.checkEveryOnArrayByProp = exports.checkObjInArray = exports.arraySome = exports.winMaxHeight = exports.toggleProp = exports.roundLastNDigits = exports.removeParamKeyName = exports.countryIsoToFlag = exports.monthStringName = exports.returnBool = exports.formatAmountToString = exports.reduceTimes = exports.reduceSum = exports.sumAmount = exports.fillEndWithZero = exports.fillStartWithZero = exports.absFromSequence = exports.returnDates = exports.displayFrDatePeriode = exports.getArrayOfRandomColor = exports.randomHslColor = exports.randomHexColor = exports.genRandomNumberArray = exports.randomRgbColor = exports.randomInteger = exports.insertAtInArray = exports.isBirthday = exports.padEndWithZero = exports.padStartWithZero = exports.formatMonthYearToLocaleString = exports.calculPercent = exports.validEmail = exports.convertToCfa = exports.packAndUnit = exports.unCheckedAll = exports.inputChecked = exports.arrayMultiChecked = exports.getPeriodDateColor = exports.getColorAccordingToDate = exports.genRandomColour = exports.formatNgbDate = void 0;
8
8
  const dayjs_1 = __importDefault(require("dayjs"));
9
9
  const dayOfYear_1 = __importDefault(require("dayjs/plugin/dayOfYear"));
10
10
  const isSameOrBefore_1 = __importDefault(require("dayjs/plugin/isSameOrBefore"));
@@ -874,9 +874,40 @@ const partOfStringBetweenTwoSpeChar = (str, position1, position2, char = "/") =>
874
874
  return str.substring(firstSlashPosition + 1, secondSlashPosition);
875
875
  };
876
876
  exports.partOfStringBetweenTwoSpeChar = partOfStringBetweenTwoSpeChar;
877
+ /**
878
+ * Groups an array of objects by a specified property (supports nested properties using dot notation).
879
+ *
880
+ * @param tobs - The array of objects to group
881
+ * @param prop - The property name to group by (supports nested properties like "user.name")
882
+ * @param groupKey - The key name for the grouped value in the result (default: "tob")
883
+ * @param groupArrayKey - The key name for the array of grouped items in the result (default: "arr")
884
+ * @returns An array of objects where each object contains the group key and an array of items belonging to that group
885
+ *
886
+ * @example
887
+ * const data = [
888
+ * { id: 1, category: 'A', value: 10 },
889
+ * { id: 2, category: 'B', value: 20 },
890
+ * { id: 3, category: 'A', value: 30 }
891
+ * ];
892
+ *
893
+ * groupedByProp(data, 'category');
894
+ * // Returns:
895
+ * // [
896
+ * // { tob: 'A', arr: [{ id: 1, category: 'A', value: 10 }, { id: 3, category: 'A', value: 30 }] },
897
+ * // { tob: 'B', arr: [{ id: 2, category: 'B', value: 20 }] }
898
+ * // ]
899
+ *
900
+ * // With nested properties:
901
+ * groupedByProp(data, 'user.role');
902
+ */
877
903
  const groupedByProp = (tobs, prop, groupKey = "tob", groupArrayKey = "arr") => {
878
904
  const groupedObj = tobs.reduce((prev, curr) => {
879
- prev[curr[prop]] = [...(prev[curr[prop]] || []), curr];
905
+ // const key = lodash.get(curr, prop);
906
+ const key = (0, exports.getNestedValue)(curr, prop);
907
+ if (!prev[key]) {
908
+ prev[key] = [];
909
+ }
910
+ prev[key].push(curr);
880
911
  return prev;
881
912
  }, {});
882
913
  return Object.entries(groupedObj).map(([key, arr]) => ({
@@ -885,3 +916,7 @@ const groupedByProp = (tobs, prop, groupKey = "tob", groupArrayKey = "arr") => {
885
916
  }));
886
917
  };
887
918
  exports.groupedByProp = groupedByProp;
919
+ const getNestedValue = (obj, path) => {
920
+ return path.split(".").reduce((current, prop) => current === null || current === void 0 ? void 0 : current[prop], obj);
921
+ };
922
+ exports.getNestedValue = getNestedValue;
@@ -28,8 +28,9 @@ export default interface User extends Address {
28
28
  foto?: string;
29
29
  clp?: string;
30
30
  periodBill?: string;
31
- limitAmountSaleByMonth?: number;
32
- limitAmountSaleIsActive?: boolean;
31
+ limitSaleAmount?: number;
32
+ maxLimitSaleAmount?: number;
33
+ hasLimitSaleAmount?: boolean;
33
34
  hasBillSafe?: boolean;
34
35
  gender?: Gender;
35
36
  titr?: UserTitr;
@@ -124,6 +124,33 @@ export declare const checkEveryOnArrayByProp: (tobs: any[], property: string) =>
124
124
  export declare const pathName: (location: any) => any;
125
125
  export declare const nthIndexOf: (str: string, charToFind: string, nthPosition?: number) => number;
126
126
  export declare const partOfStringBetweenTwoSpeChar: (str: string, position1: number, position2: number, char?: string) => string;
127
+ /**
128
+ * Groups an array of objects by a specified property (supports nested properties using dot notation).
129
+ *
130
+ * @param tobs - The array of objects to group
131
+ * @param prop - The property name to group by (supports nested properties like "user.name")
132
+ * @param groupKey - The key name for the grouped value in the result (default: "tob")
133
+ * @param groupArrayKey - The key name for the array of grouped items in the result (default: "arr")
134
+ * @returns An array of objects where each object contains the group key and an array of items belonging to that group
135
+ *
136
+ * @example
137
+ * const data = [
138
+ * { id: 1, category: 'A', value: 10 },
139
+ * { id: 2, category: 'B', value: 20 },
140
+ * { id: 3, category: 'A', value: 30 }
141
+ * ];
142
+ *
143
+ * groupedByProp(data, 'category');
144
+ * // Returns:
145
+ * // [
146
+ * // { tob: 'A', arr: [{ id: 1, category: 'A', value: 10 }, { id: 3, category: 'A', value: 30 }] },
147
+ * // { tob: 'B', arr: [{ id: 2, category: 'B', value: 20 }] }
148
+ * // ]
149
+ *
150
+ * // With nested properties:
151
+ * groupedByProp(data, 'user.role');
152
+ */
127
153
  export declare const groupedByProp: (tobs: object[], prop: string, groupKey?: string, groupArrayKey?: string) => {
128
154
  [x: string]: unknown;
129
155
  }[];
156
+ export declare const getNestedValue: (obj: any, path: string) => any;
package/lib/esm/utils.js CHANGED
@@ -773,9 +773,40 @@ export const partOfStringBetweenTwoSpeChar = (str, position1, position2, char =
773
773
  const secondSlashPosition = nthIndexOf(str, char, position2);
774
774
  return str.substring(firstSlashPosition + 1, secondSlashPosition);
775
775
  };
776
+ /**
777
+ * Groups an array of objects by a specified property (supports nested properties using dot notation).
778
+ *
779
+ * @param tobs - The array of objects to group
780
+ * @param prop - The property name to group by (supports nested properties like "user.name")
781
+ * @param groupKey - The key name for the grouped value in the result (default: "tob")
782
+ * @param groupArrayKey - The key name for the array of grouped items in the result (default: "arr")
783
+ * @returns An array of objects where each object contains the group key and an array of items belonging to that group
784
+ *
785
+ * @example
786
+ * const data = [
787
+ * { id: 1, category: 'A', value: 10 },
788
+ * { id: 2, category: 'B', value: 20 },
789
+ * { id: 3, category: 'A', value: 30 }
790
+ * ];
791
+ *
792
+ * groupedByProp(data, 'category');
793
+ * // Returns:
794
+ * // [
795
+ * // { tob: 'A', arr: [{ id: 1, category: 'A', value: 10 }, { id: 3, category: 'A', value: 30 }] },
796
+ * // { tob: 'B', arr: [{ id: 2, category: 'B', value: 20 }] }
797
+ * // ]
798
+ *
799
+ * // With nested properties:
800
+ * groupedByProp(data, 'user.role');
801
+ */
776
802
  export const groupedByProp = (tobs, prop, groupKey = "tob", groupArrayKey = "arr") => {
777
803
  const groupedObj = tobs.reduce((prev, curr) => {
778
- prev[curr[prop]] = [...(prev[curr[prop]] || []), curr];
804
+ // const key = lodash.get(curr, prop);
805
+ const key = getNestedValue(curr, prop);
806
+ if (!prev[key]) {
807
+ prev[key] = [];
808
+ }
809
+ prev[key].push(curr);
779
810
  return prev;
780
811
  }, {});
781
812
  return Object.entries(groupedObj).map(([key, arr]) => ({
@@ -783,3 +814,6 @@ export const groupedByProp = (tobs, prop, groupKey = "tob", groupArrayKey = "arr
783
814
  [groupArrayKey]: arr,
784
815
  }));
785
816
  };
817
+ export const getNestedValue = (obj, path) => {
818
+ return path.split(".").reduce((current, prop) => current === null || current === void 0 ? void 0 : current[prop], obj);
819
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asv-hlps",
3
- "version": "1.4.67",
3
+ "version": "1.4.68",
4
4
  "description": "helpers",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./lib/esm/index.js",