Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions core/collections/shim-object.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";

require("/core/extras/object");
require("./shim-function");

module.exports = Object;
Expand All @@ -24,19 +25,6 @@ module.exports = Object;
*/
Object.empty = Object.freeze(Object.create(null));

/**
Returns whether the given value is an object, as opposed to a value.
Unboxed numbers, strings, true, false, undefined, and null are not
objects. Arrays are objects.

@function external:Object.isObject
@param {Any} value
@returns {Boolean} whether the given value is an object
*/
Object.isObject = function (object) {
return Object(object) === object;
};

/**
Returns the value of an any value, particularly objects that
implement <code>valueOf</code>.
Expand Down
21 changes: 0 additions & 21 deletions core/collections/test/spec/shim-object-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,6 @@ describe("ObjectShim-spec", function () {

});

describe("isObject", function () {

[
["null is not an object", null, false],
["numbers are not objects", 1, false],
["undefined is not an object", undefined, false],
["arrays are objects", [], true],
["object literals are objects", {}, true],
[
"pure objects (null prototype) are",
Object.create(null),
true
]
].forEach(function (test) {
it("should recognize that " + test[0], function () {
expect(Object.isObject(test[1])).toEqual(test[2]);
});
});

});

describe("getValueOf", function () {
var fakeNumber = Object.create({
valueOf: function () {
Expand Down
23 changes: 23 additions & 0 deletions core/extras/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,26 @@ Object.defineProperty(Function.prototype, "isClass", {
configurable: true
});


if (typeof Function.isFunction === "undefined") {
/**
* Function.isFunction() - Determines if a value is a function
*
* Adds a static method to the Function constructor that determines whether the passed
* value is a function. This method provides functionality similar to `Array.isArray()`
* but specifically for function types.
*
* This method detects all types of functions including regular functions, arrow functions,
* async functions, generator functions, class constructors, and built-in functions.
*
* Only adds the method if it doesn't already exist, ensuring
* compatibility with environments that may implement this method natively in the future.
*
* @function external:Function.isFunction
* @param {*} value - The value to test. Can be any JavaScript value.
* @returns {boolean} Returns `true` if the value is any type of function
*/
Function.isFunction = function (value) {
return typeof value === "function";
};
}
72 changes: 72 additions & 0 deletions core/extras/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,75 @@ if (Object.prototype.hasOwnProperty('isEmpty') === false) {
enumerable: false
});
}

if (typeof Object.isObject === "undefined") {
/**
* Object.isObject() - General plain object check with optional strict mode
*
* Determines whether the passed value is an object, with two modes of checking:
* - Default mode: Returns true for any non-null object (including arrays, dates, etc.)
* - Strict mode: Returns true only for plain objects using toString() method
*
* In strict mode, this matches objects created with {}, new Object(),
* Object.create(Object.prototype), and similar plain object patterns.
*
* @function external:Object.isObject
* @param {*} value - The value to test. Can be any JavaScript value.
* @param {boolean} [strict=false] - If true, performs strict plain object check using toString()
* @returns {boolean} Returns `true` if the value passes the object check, `false` otherwise
*
* @example
* // Default mode - any non-null object
* Object.isObject({}); // true
* Object.isObject([]); // true
* Object.isObject(new Date()); // true
* Object.isObject(null); // false
* Object.isObject("string"); // false
*
* @example
* // Strict mode - plain objects only
* Object.isObject({}, true); // true
* Object.isObject(new Object(), true); // true
* Object.isObject(Object.create(Object.prototype), true); // true
* Object.isObject([], true); // false
* Object.isObject(new Date(), true); // false
* Object.isObject(null, true); // false
*/
Object.isObject = function (value, strict = false) {
if (value === null || typeof value !== "object") return false;

if (strict) {
return Object.prototype.toString.call(value) === "[object Object]";
}

return true;
};
}

if (typeof Object.isPureObject === "undefined") {
/**
* Object.isPureObject() - Objects without custom prototype pollution
*
* Determines whether the passed value is a pure object by checking its prototype.
* Only accepts objects with Object.prototype or null as their direct prototype.
* This excludes objects created with custom constructors or Object.create() with
* custom prototypes.
*
* @function external:Object.isPureObject
* @param {*} value - The value to test. Can be any JavaScript value.
* @returns {boolean} Returns `true` if the value is a pure object, `false` otherwise
*
* @example
* Object.isPureObject({}); // true
* Object.isPureObject(new Object()); // true
* Object.isPureObject(Object.create(null)); // true
* Object.isPureObject(Object.create({})); // false
* Object.isPureObject(new Date()); // false
*/
Object.isPureObject = function (value) {
if (!Object.isObject(value)) return false;

return Object.getPrototypeOf(value) === Object.prototype ||
Object.getPrototypeOf(value) === null;
};
}
18 changes: 18 additions & 0 deletions core/extras/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,21 @@ if(typeof String.prototype.substringWithinRange !== "function") {

}

if (typeof String.isString === "undefined") {
/**
* String.isString() - Determines if a value is a string primitive or String object.
*
* Adds a static method to the String constructor that determines whether the passed
* value is a string primitive or String object instance. This method provides
* functionality similar to `Array.isArray()` but specifically for string types.
*
* Only adds the method if it doesn't already exist, ensuring
* compatibility with environments that may implement this method natively in the future.
* @function external:String.isString
* @param {*} value - The value to test. Can be any JavaScript value.
* @returns {boolean} Returns `true` if the value is a string primitive or String object
*/
String.isString = function (value) {
return typeof value === "string" || value instanceof String;
};
}
24 changes: 8 additions & 16 deletions core/mini-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,27 +181,19 @@ function isNullOrUndefined(value) {
return value === null || value === undefined;
}

function isString(str) {
return typeof str === 'string';
}

function isObject(obj) {
return typeof obj === 'object';
}

function urlParse(url, parseQueryString, slashesDenoteHost) {
if (url && isObject(url) && url instanceof Url) {
if (url && Object.isObject(url) && url instanceof Url) {
return url;
}

var u = new Url;
u.parse(url, parseQueryString, slashesDenoteHost);

return u;
}

Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
if (!isString(url)) {
if (!String.isString(url)) {
throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
}

Expand Down Expand Up @@ -471,14 +463,14 @@ function urlFormat(obj) {
// If it's an obj, this is a no-op.
// this way, you can call url_format() on strings
// to clean up potentially wonky urls.
if (isString(obj)) {
if (String.isString(obj)) {
obj = urlParse(obj);
}

if (!(obj instanceof Url)) {
return Url.prototype.format.call(obj);
} else {
return obj.format();
return obj.format();
}
}

Expand Down Expand Up @@ -508,7 +500,7 @@ Url.prototype.format = function() {
}

if (this.query &&
isObject(this.query) &&
Object.isObject(this.query) &&
Object.keys(this.query).length) {
query = encodeQuerystring(this.query);
}
Expand Down Expand Up @@ -563,7 +555,7 @@ function urlResolveObject(source, relative) {
}

Url.prototype.resolveObject = function(relative) {
if (isString(relative)) {
if (String.isString(relative)) {
var rel = new Url();
rel.parse(relative, false, true);
relative = rel;
Expand Down Expand Up @@ -871,4 +863,4 @@ Url.prototype.parseHost = function() {

exports.resolve = function(source, relative) {
return urlParse(source, false, true).resolve(relative);
};
};
5 changes: 3 additions & 2 deletions data/service/data-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6920,9 +6920,10 @@ DataService.addClassProperties({

_getOfflineOperationMethodName: {
value: function(type) {
var isString = typeof type === "string",
var isString = String.isString(type),
name = isString && this._offlineOperationMethodNames.get(type);
if (isString && !name) {

if (String.isString(type) && !name) {
name = "perform";
name += type[0].toUpperCase();
name += type.slice(1);
Expand Down