Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'is-typedarray' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
export function convert_dates(value) {
// check if the array of value contains Date objects, if so
// dates are serialized using the timestamp only, some parts of the code
// use the Data objects, detect that and convert.
// also, we set the .type property of TypedArray, to keep track of it being a
// date array
if(isTypedArray(value))
return value;
const convert_to_date = function(x) {
const ar: any = new Float64Array(x.map(Number));
ar.type = 'date';
return ar;
}
if(value[0] instanceof Array && value[0][0] instanceof Date)
value = value.map(convert_to_date);
else if(value[0] instanceof Date)
value = convert_to_date(value);
return value;
}
export function deepCopy(obj) {
// This makes a deep copy of JSON-parsable objects
// (no cycling or recombining)
// Backbone model attributes must be JSON parsable. Hence there is
// no need for a fancier logic, and it is surprisingly efficient.
if(isTypedArray(obj))
return obj.slice()
else if(_.isArray(obj)) {
return obj.map(x => deepCopy(x))
} else if(_.isNumber(obj) || _.isString(obj)) {
return obj;
} else if(_.isDate(obj)) {
return new Date(obj.getTime());
} else {
const newobj = {}
for(let key in obj) {
if(obj.hasOwnProperty(key)) {
newobj[key] = deepCopy(obj[key])
}
}
return newobj;
}
function serialize_array_or_json(data, manager) {
if(data == null)
return null;
if(_.isNumber(data)) {
return data; // return numbers directly
} else if(_.isArray(data)) {
return data.map((ar) => serialize_array_or_json(ar, manager))
} else if(isTypedArray(data)) {
return serialize_typed_array(data, manager)
}
}
context(({position, rotation, scale}) => {
ok(position, "Position context variable is defined.")
ok(isTypedArray(position), "Position context variable is an array.")
ok(3 == position.length, "Position context variable is an array with 3 components.")
ok(false == hasDiff(position, expected.position), "Position context variable has correct value from initial state.")
ok(scale, "Scale context variable is defined.")
ok(isTypedArray(scale), "Scale context variable is an array.")
ok(3 == scale.length, "Scale context variable is an array with 3 components.")
ok(false == hasDiff(scale, expected.scale), "Scale context variable has correct value from initial state.")
ok(rotation, "Rotation context variable is defined.")
ok(isTypedArray(rotation), "Rotation context variable is an array.")
ok(4 == rotation.length, "Rotation context variable is an array with 3 components.")
ok(false == hasDiff(rotation, expected.rotation), "Rotation context variable has correct value from initial state.")
})
end()
trs(({position, rotation, scale}) => {
ok(position, "Position context variable is defined.")
ok(isTypedArray(position), "Position context variable is an array.")
ok(3 == position.length, "Position context variable is an array with 3 components.")
ok(false == hasDiff(position, defaults.position), "Position context variable has correct default value.")
ok(scale, "Scale context variable is defined.")
ok(isTypedArray(scale), "Scale context variable is an array.")
ok(3 == scale.length, "Scale context variable is an array with 3 components.")
ok(false == hasDiff(scale, defaults.scale), "Scale context variable has correct default value.")
ok(rotation, "Rotation context variable is defined.")
ok(isTypedArray(rotation), "Rotation context variable is an array.")
ok(4 == rotation.length, "Rotation context variable is an array with 3 components.")
ok(false == hasDiff(rotation, defaults.rotation), "Rotation context variable has correct default value.")
})
end()
context(({localMatrix, transformMatrix}) => {
ok(localMatrix, "Local matrix context variable is defined.")
ok(isTypedArray(localMatrix) || localMatrix instanceof Float32Array, "Local matrix context variable is an array.")
ok(16 == localMatrix.length, "Local matrix context variable is an array with 16 components.")
ok(transformMatrix, "Transform matrix context variable is defined.")
ok(isTypedArray(transformMatrix) || transformMatrix instanceof Float32Array, "Transform context variable is an array.")
ok(16 == transformMatrix.length, "Transform matrix context variable is an array with 16 components.")
})
end()
context(({position, rotation, scale}) => {
ok(position, "Position context variable is defined.")
ok(isTypedArray(position), "Position context variable is an array.")
ok(3 == position.length, "Position context variable is an array with 3 components.")
ok(false == hasDiff(position, defaults.position), "Position context variable has correct default value.")
ok(scale, "Scale context variable is defined.")
ok(isTypedArray(scale), "Scale context variable is an array.")
ok(3 == scale.length, "Scale context variable is an array with 3 components.")
ok(false == hasDiff(scale, defaults.scale), "Scale context variable has correct default value.")
ok(rotation, "Rotation context variable is defined.")
ok(isTypedArray(rotation), "Rotation context variable is an array.")
ok(4 == rotation.length, "Rotation context variable is an array with 3 components.")
ok(false == hasDiff(rotation, defaults.rotation), "Rotation context variable has correct default value.")
})
end()
trs(expected, ({position, rotation, scale}) => {
ok(position, "Position context variable is defined.")
ok(isTypedArray(position), "Position context variable is an array.")
ok(3 == position.length, "Position context variable is an array with 3 components.")
ok(false == hasDiff(position, expected.position), "Position context variable has correct value from input arguments.")
ok(scale, "Scale context variable is defined.")
ok(isTypedArray(scale), "Scale context variable is an array.")
ok(3 == scale.length, "Scale context variable is an array with 3 components.")
ok(false == hasDiff(scale, expected.scale), "Scale context variable has correct value from input arguments.")
ok(rotation, "Rotation context variable is defined.")
ok(isTypedArray(rotation), "Rotation context variable is an array.")
ok(4 == rotation.length, "Rotation context variable is an array with 3 components.")
ok(false == hasDiff(rotation, expected.rotation), "Rotation context variable has correct value from input arguments.")
})
end()
({ok, end}) => {
const {scale} = defaults
ok('scale' in defaults, "Exists in defaults object.")
ok(isTypedArray(scale), "Is an array.")
ok(3 == scale.length, "Has 3 components.")
ok(false == hasDiff(scale, [1,1,1]), "Is identity scale vector.")
end()
})
function setContentLength () {
if (isTypedArray(self.body)) {
self.body = new Buffer(self.body)
}
if (!self.hasHeader('content-length')) {
var length
if (typeof self.body === 'string') {
length = Buffer.byteLength(self.body)
}
else if (Array.isArray(self.body)) {
length = self.body.reduce(function (a, b) {return a + b.length}, 0)
}
else {
length = self.body.length
}
if (length) {