1- //=========================================================================================================
2- // Copy
3- //=========================================================================================================
41/**
5- * @internal
6- * Creates a fresh copy of an Array/Object
2+ * Creates a fresh (deep) copy of the specified value.
73 * https://www.samanthaming.com/tidbits/70-3-ways-to-clone-objects/
8- * @param value - Array/Object that gets copied
4+ *
5+ * @public
6+ * @param value - Value to be copied.
97 */
108export function copy < T = any > ( value : T ) : T {
119 // Extra checking 'value == null' because 'typeof null === object'
1210 if ( value == null || typeof value !== 'object' ) return value ;
1311
1412 // Ignore everything that is no object or array but has the type of an object (e.g. classes)
15- const valConstructorName = Object . getPrototypeOf (
16- value
17- ) . constructor . name . toLowerCase ( ) ;
13+ const valConstructorName =
14+ Object . getPrototypeOf ( value ) . constructor . name . toLowerCase ( ) ;
1815 if ( valConstructorName !== 'object' && valConstructorName !== 'array' )
1916 return value ;
2017
@@ -27,15 +24,13 @@ export function copy<T = any>(value: T): T {
2724 return newObject as T ;
2825}
2926
30- //=========================================================================================================
31- // Is Valid Object
32- //=========================================================================================================
3327/**
34- * @internal
35- * Checks if passed value is a valid Object
28+ * Checks whether the specified value is a valid object.
3629 * https://stackoverflow.com/questions/12996871/why-does-typeof-array-with-objects-return-object-and-not-array
37- * @param value - Value that is tested for its correctness
38- * @param considerArray - Whether Arrays should be considered as object
30+ *
31+ * @public
32+ * @param value - Value
33+ * @param considerArray - Whether to considered an array as an object.
3934 */
4035export function isValidObject ( value : any , considerArray = false ) : boolean {
4136 function isHTMLElement ( obj : any ) {
@@ -59,12 +54,10 @@ export function isValidObject(value: any, considerArray = false): boolean {
5954 ) ;
6055}
6156
62- //=========================================================================================================
63- // Includes Array
64- //=========================================================================================================
6557/**
66- * @internal
67- * Check if array1 contains all elements of array2
58+ * Checks whether 'array1' contains all elements of 'array2'.
59+ *
60+ * @public
6861 * @param array1 - Array 1
6962 * @param array2 - Array 2
7063 */
@@ -75,13 +68,11 @@ export function includesArray<DataType = any>(
7568 return array2 . every ( ( element ) => array1 . includes ( element ) ) ;
7669}
7770
78- //=========================================================================================================
79- // Normalize Array
80- //=========================================================================================================
8171/**
82- * @internal
83- * Transforms Item/s to an Item Array
84- * @param items - Item/s that gets transformed to an Array
72+ * Transforms Item/s into an array of Items.
73+ *
74+ * @public
75+ * @param items - Item/s to be transformed into an array of Items.
8576 * @param config - Config
8677 */
8778export function normalizeArray < DataType = any > (
@@ -95,25 +86,21 @@ export function normalizeArray<DataType = any>(
9586 return Array . isArray ( items ) ? items : [ items as DataType ] ;
9687}
9788
98- //=========================================================================================================
99- // Is Function
100- //=========================================================================================================
10189/**
102- * @internal
103- * Checks if value is a function
104- * @param value - Value that gets tested if its a function
90+ * Checks whether the specified function is a function.
91+ *
92+ * @public
93+ * @param value - Value to be checked
10594 */
10695export function isFunction ( value : any ) : boolean {
10796 return typeof value === 'function' ;
10897}
10998
110- //=========================================================================================================
111- // Is Async Function
112- //=========================================================================================================
11399/**
114- * @internal
115- * Checks if value is an async function
116- * @param value - Value that gets tested if its an async function
100+ * Checks whether the specified function is an async function.
101+ *
102+ * @public
103+ * @param value - Value to be checked.
117104 */
118105export function isAsyncFunction ( value : any ) : boolean {
119106 const valueString = value . toString ( ) ;
@@ -124,13 +111,11 @@ export function isAsyncFunction(value: any): boolean {
124111 ) ;
125112}
126113
127- //=========================================================================================================
128- // Is Json String
129- //=========================================================================================================
130114/**
131- * @internal
132- * Checks if value is valid JsonString
133- * @param value - Value that gets checked
115+ * Checks whether the specified value is a valid JSON string
116+ *
117+ * @public
118+ * @param value - Value to be checked.
134119 */
135120export function isJsonString ( value : any ) : boolean {
136121 if ( typeof value !== 'string' ) return false ;
@@ -142,15 +127,13 @@ export function isJsonString(value: any): boolean {
142127 return true ;
143128}
144129
145- //=========================================================================================================
146- // Define Config
147- //=========================================================================================================
148130/**
149- * @internal
150- * Merges default values/properties into config object
151- * @param config - Config object that receives default values
152- * @param defaults - Default values object that gets merged into config object
153- * @param overwriteUndefinedProperties - If undefined Properties in config gets overwritten by the default value
131+ * Merges the default values object ('defaults') into the configuration object ('config').
132+ *
133+ * @public
134+ * @param config - Configuration object to merge the default values in.
135+ * @param defaults - Default values object to be merged into the configuration object.
136+ * @param overwriteUndefinedProperties - Whether to overwrite 'undefined' set properties with default values.
154137 */
155138export function defineConfig < ConfigInterface = Object > (
156139 config : ConfigInterface ,
@@ -174,24 +157,22 @@ export function defineConfig<ConfigInterface = Object>(
174157 return shallowCopiedConfig ;
175158}
176159
177- //=========================================================================================================
178- // Flat Merge
179- //=========================================================================================================
180- /**
181- * @internal
182- * @param addNewProperties - Adds new properties to source Object
183- */
184160export interface FlatMergeConfigInterface {
161+ /**
162+ *
163+ * Whether to add new properties (properties that doesn't exist in the source object yet) to the source object.
164+ * @default true
165+ */
185166 addNewProperties ?: boolean ;
186167}
187168
188169/**
189- * @internal
190- * Merges items into object, be aware that the merge will only happen at the top level of the object.
191- * Initially it adds new properties of the changes object into the source object.
170+ * Merges the 'changes' object into the 'source' object at top level.
171+ *
172+ * @public
192173 * @param source - Source object
193- * @param changes - Changes that get merged into the source object
194- * @param config - Config
174+ * @param changes - Changes object to be merged into the source object
175+ * @param config - Configuration object
195176 */
196177export function flatMerge < DataType = Object > (
197178 source : DataType ,
@@ -219,14 +200,12 @@ export function flatMerge<DataType = Object>(
219200 return _source ;
220201}
221202
222- //=========================================================================================================
223- // Equals
224- //=========================================================================================================
225203/**
226- * @internal
227- * Check if two values are equal
228- * @param value1 - First Value
229- * @param value2 - Second Value
204+ * Checks whether the two specified values are equivalent.
205+ *
206+ * @public
207+ * @param value1 - First value.
208+ * @param value2 - Second value.
230209 */
231210export function equal ( value1 : any , value2 : any ) : boolean {
232211 return (
@@ -239,46 +218,44 @@ export function equal(value1: any, value2: any): boolean {
239218 ) ;
240219}
241220
242- //=========================================================================================================
243- // Not Equals
244- //=========================================================================================================
245221/**
246- * @internal
247- * Checks if two values aren't equal
248- * @param value1 - First Value
249- * @param value2 - Second Value
222+ * Checks whether the two specified values are NOT equivalent.
223+ *
224+ * @public
225+ * @param value1 - First value.
226+ * @param value2 - Second value.
250227 */
251228export function notEqual ( value1 : any , value2 : any ) : boolean {
252229 return ! equal ( value1 , value2 ) ;
253230}
254231
255- //=========================================================================================================
256- // Generate Id
257- //=========================================================================================================
258232/**
259- * @internal
260- * Generates random Id
261- * @param length - Length of generated Id
233+ * Generates a randomized id based on alphabetic and numeric characters.
234+ *
235+ * @public
236+ * @param length - Length of the to generate id (default = 5).
237+ * @param characters - Characters to generate the id from (default = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789').
262238 */
263- export function generateId ( length ?: number ) : string {
264- const characters =
265- 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' ;
239+ export function generateId (
240+ length : number = 5 ,
241+ characters : string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
242+ ) : string {
266243 const charactersLength = characters . length ;
267244 let result = '' ;
268- if ( ! length ) length = 5 ;
269245 for ( let i = 0 ; i < length ; i ++ ) {
270246 result += characters . charAt ( Math . floor ( Math . random ( ) * charactersLength ) ) ;
271247 }
272248 return result ;
273249}
274250
275- //=========================================================================================================
276- // Create Array From Object
277- //=========================================================================================================
278251/**
279- * @internal
280- * Transforms Object to Array
281- * @param object - Object that gets transformed
252+ * Transforms the specified object into an array.
253+ *
254+ * Example:
255+ * {"1": 'jeff', 2: 'frank'} -> [{key: "1", instance: 'jeff'}, {key: 2, instance: 'frank'}]
256+ *
257+ * @public
258+ * @param object - Object to be transformed to an array.
282259 */
283260export function createArrayFromObject < P = any > ( object : {
284261 [ key : string ] : P ;
@@ -293,13 +270,11 @@ export function createArrayFromObject<P = any>(object: {
293270 return array ;
294271}
295272
296- //=========================================================================================================
297- // Clone
298- //=========================================================================================================
299273/**
300- * @internal
301- * Clones a Class
302- * @param instance - Instance of Class you want to clone
274+ * Clones the specified class.
275+ *
276+ * @public
277+ * @param instance - Class to be cloned.
303278 */
304279export function clone < T = any > ( instance : T ) : T {
305280 // Clone Class
@@ -312,14 +287,12 @@ export function clone<T = any>(instance: T): T {
312287 return objectClone ;
313288}
314289
315- //=========================================================================================================
316- // Remove Properties
317- //=========================================================================================================
318290/**
319- * @internal
320- * Removes properties from Object
321- * @param object - Object from which the properties get removed
322- * @param properties - Properties that get removed from the object
291+ * Removes specified properties from the defined object.
292+ *
293+ * @public
294+ * @param object - Object to remove the specified properties from.
295+ * @param properties - Property keys to be removed from the specified object.
323296 */
324297export function removeProperties < T = Object > (
325298 object : T ,
0 commit comments