This commit is contained in:
David Štaleker
2025-07-18 05:33:16 +02:00
parent 401a367e5d
commit db0cc8d3de
14776 changed files with 9251484 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
var alwaysArray = function( somethingOrArray ) {
return arrayIsArray( somethingOrArray ) ? somethingOrArray : [ somethingOrArray ];
};

View File

@@ -0,0 +1,12 @@
var arrayForEach = function( array, callback ) {
var i, length;
if ( array.forEach ) {
return array.forEach( callback );
}
for ( i = 0, length = array.length; i < length; i++ ) {
callback( array[ i ], i, array );
}
};

View File

@@ -0,0 +1,6 @@
var arrayIsArray = Array.isArray || function( obj ) {
return Object.prototype.toString.call( obj ) === "[object Array]";
};

View File

@@ -0,0 +1,15 @@
var arraySome = function( array, callback ) {
var i, length;
if ( array.some ) {
return array.some( callback );
}
for ( i = 0, length = array.length; i < length; i++ ) {
if ( callback( array[ i ], i, array ) ) {
return true;
}
}
return false;
};

View File

@@ -0,0 +1,9 @@
/**
* Function inspired by jQuery Core, but reduced to our use case.
*/
var isPlainObject = function( obj ) {
return obj !== null && "" + obj === "[object Object]";
};

View File

@@ -0,0 +1,35 @@
var jsonMerge = (function() {
// Returns new deeply merged JSON.
//
// Eg.
// merge( { a: { b: 1, c: 2 } }, { a: { b: 3, d: 4 } } )
// -> { a: { b: 3, c: 2, d: 4 } }
//
// @arguments JSON's
//
var merge = function() {
var destination = {},
sources = [].slice.call( arguments, 0 );
arrayForEach( sources, function( source ) {
var prop;
for ( prop in source ) {
if ( prop in destination && typeof destination[ prop ] === "object" && !arrayIsArray( destination[ prop ] ) ) {
// Merge Objects
destination[ prop ] = merge( destination[ prop ], source[ prop ] );
} else {
// Set new values
destination[ prop ] = source[ prop ];
}
}
});
return destination;
};
return merge;
}());

View File

@@ -0,0 +1,17 @@
var objectKeys = function( object ) {
var i,
result = [];
if ( Object.keys ) {
return Object.keys( object );
}
for ( i in object ) {
result.push( i );
}
return result;
};