topkat-utils 1.0.5 → 1.0.6

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.
Files changed (2) hide show
  1. package/README.md +232 -2
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,2 +1,232 @@
1
- # utils
2
- Validation utils
1
+ # TOPKAT-UTILS
2
+
3
+ Here are my utils for nodeJs - ReactJs - MongoDB stack. It's strength is that it has a straight functional naming and is fast and lightweight. It includes a logger with color handling, data validation utils, date utils, mongoDb utils. Check the list above for the function list:
4
+
5
+ ``` javascript
6
+ const topkatUtils = {
7
+ round,
8
+ random,
9
+ cln, // clean string for print. Eg: undefined, null, NaN => '-'
10
+ pad, // simple padStart for numbers
11
+ // ALIASES
12
+ int,
13
+ /** return the number or the closest number of the range
14
+ * * nb min max => returns
15
+ * * 7 5 10 => 7 // in the range
16
+ * * 2 5 10 => 5 // below the min value
17
+ * * 99 5 10 => 10// above the max value
18
+ */
19
+ minMax, //
20
+ /** Generate random unique tokens (minLength 8 if unique)
21
+ * @param {Number} length default: 20
22
+ * @param {Boolean} unique default: true. Generate a real unique token base on the date. min length will be min 8 in this case
23
+ * @param {string} mode one of ['alphanumeric', 'hexadecimal']
24
+ * NOTE: to generate a mongoDB Random Id, use the params: 24, true, 'hexadecimal'
25
+ */
26
+ generateToken,
27
+ moyenne,
28
+ // average between array of values. Eg: [5, 15] => 10
29
+ average,
30
+ // sum values in an array
31
+ sumArray,
32
+ // sort an array of urls (useful for expressJs or react router. It avoid generic route home/ to take precedence over a more specific route like home/dshboard1)
33
+ sortUrlsByDeepnessInArrayOrObject,
34
+ // like nodeJs path.join() but for urls
35
+ urlPathJoin,
36
+ // miniTemplater(`Hello {{template}}`, {template: 'John'}) => `Hello John`
37
+ miniTemplater,
38
+ // is number between
39
+ isBetween,
40
+ simpleObjectMaskOrSelect,
41
+ ENV,
42
+ parseBool,
43
+
44
+ registerConfig,
45
+ configFn,
46
+ findByAddress,
47
+ objForceWrite,
48
+ objForceWriteIfNotSet,
49
+
50
+
51
+
52
+ strAsArray,
53
+ asArray,
54
+ compareArrays,
55
+ getArrayInCommon,
56
+ getArrayDiff,
57
+ getNotInArrayA,
58
+ noDuplicateFilter,
59
+ arrayToObjectSorted,
60
+ pushIfNotExist,
61
+ isNotEmptyArray,
62
+ randomItemInArray,
63
+ //allias
64
+ arrayUniqueValue,
65
+
66
+
67
+ deepClone,
68
+ cloneObject,
69
+ JSONstringyParse,
70
+ has,
71
+ isObject,
72
+ mergeDeep,
73
+ flattenObject,
74
+ unflattenObject,
75
+ recursiveGenericFunction,
76
+ recursiveGenericFunctionSync,
77
+ findByAddressAll,
78
+ objFilterUndefined,
79
+ readOnly,
80
+ reassignForbidden,
81
+ readOnlyForAll,
82
+ mergeDeepOverrideArrays,
83
+ mergeDeepConfigurable,
84
+ objFilterUndefinedRecursive,
85
+ removeUndefinedKeys, // alias
86
+ sortObjKeyAccordingToValue,
87
+ ensureObjectProp,
88
+ filterKeys,
89
+ deleteByAddress,
90
+ ensureIsArrayAndPush,
91
+ removeCircularJSONstringify,
92
+
93
+ isset,
94
+ cleanStackTrace,
95
+ shuffleArray,
96
+ randomizeArray: shuffleArray,
97
+ round2,
98
+
99
+ camelCase,
100
+ snakeCase,
101
+ kebabCase,
102
+ dashCase: kebabCase,
103
+ underscoreCase: snakeCase,
104
+ titleCase,
105
+ pascalCase,
106
+ lowerCase,
107
+ upperCase,
108
+ capitalize1st,
109
+ camelCaseToWords,
110
+
111
+ firstMatch,
112
+ allMatches,
113
+ getValuesBetweenSeparator,
114
+ getValuesBetweenStrings,
115
+ escapeRegexp,
116
+
117
+ validator,
118
+ required: validator, // alias for readability
119
+ validatorReturnErrArray,
120
+ isValid,
121
+ isType,
122
+ isDateObject,
123
+ issetOr,
124
+ isEmptyOrNotSet,
125
+ errIfNotSet,
126
+ err500IfNotSet,
127
+ errIfEmptyOrNotSet,
128
+ err500IfEmptyOrNotSet,
129
+ errXXXIfNotSet,
130
+ isEmpty,
131
+ checkAllObjectValuesAreEmpty,
132
+ checkCtxIntegrity,
133
+ // ALIASES
134
+ orIsset: issetOr,
135
+
136
+ // DATE
137
+ getDateAsInt12,
138
+ humanReadableTimestamp,
139
+ getDateAsInt,
140
+ getDateAsObject,
141
+ isDateIntOrStringValid,
142
+ isDateIsoOrObjectValid,
143
+ dateStringToArray,
144
+ dateArrayFormatted: dateArray,
145
+ dateFormatted,
146
+ dateSlash: dateFormatted,
147
+ dateOffset,
148
+ getTimeAsInt,
149
+ getIntAsTime,
150
+ isTimeStringValid,
151
+ // isDateObject <= see validator.js
152
+ getDuration,
153
+ doDateOverlap,
154
+ getDatesForDaysArrayBetweenTwoDates,
155
+ getEndTimeFromDurationAndStartTime,
156
+ getDate12FromDateAndTime,
157
+ getMonthAsInt,
158
+ isSunday,
159
+ isMonday,
160
+ isTuesday,
161
+ isWednesday,
162
+ isThursday,
163
+ isFriday,
164
+ isSaturday,
165
+ isWeekend,
166
+ nextMonday,
167
+ nextTuesday,
168
+ nextWednesday,
169
+ nextThursday,
170
+ nextFriday,
171
+ nextSaturday,
172
+ nextSunday,
173
+ addMinutes,
174
+ addHours,
175
+ addDays,
176
+ addMonths,
177
+ addYears,
178
+ getYear,
179
+ getDayOfMonth,
180
+ getHours,
181
+ getMinutes,
182
+ firstDayOfMonth,
183
+ lastDayOfMonth,
184
+ eachDayOfInterval,
185
+ eachMonthOfInterval,
186
+ differenceInMilliseconds,
187
+ differenceInSeconds,
188
+ differenceInMinutes,
189
+ differenceInHours,
190
+ differenceInDays,
191
+ differenceInWeeks,
192
+ differenceInMonths,
193
+ getClosestExistingDateOfMonth,
194
+ getNextMonthlyDate,
195
+ getHolidayReferenceYear,
196
+ getFirstDayOfHolidayReferenceYear,
197
+ getLastDayOfHolidayReferenceYear,
198
+ // ALIASES
199
+ getDateAsArrayFormatted: dateArray,
200
+ getDateAsArray: dateStringToArray,
201
+ convertDateAsInt: getDateAsInt,
202
+ convertDateAsObject: getDateAsObject,
203
+
204
+ // LOGGER
205
+ C,
206
+ cliProgressBar,
207
+ cliLoadingSpinner,
208
+ outputLogs: logger,
209
+
210
+ // STRING
211
+ convertAccentedCharacters,
212
+
213
+ // TIMEOUT
214
+ executeInDelayedLoop,
215
+ timeout,
216
+ runAsync,
217
+ waitUntilTrue,
218
+
219
+ // TRANSACTION
220
+ transaction,
221
+ waitForTransaction,
222
+ getId,
223
+ mergeMixins,
224
+
225
+ // MONGO
226
+ mongoFilterMerger,
227
+ mongoPush,
228
+ tryCatch,
229
+ }
230
+ ```
231
+
232
+ Please contact me if you need further informations ( issue on github :) )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "topkat-utils",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "description": "UTILS BIG TIME",