-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement $jsonArray() dialect (#108)
* implement $jsonArray() dialect * use jsonArray() for selecting values * validate $jsonArray dialect * serialize array of objects * update tests * 2.9.2
- Loading branch information
1 parent
c918edf
commit ec4b7c2
Showing
8 changed files
with
246 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import isPlainObject from 'lodash/isPlainObject'; | ||
import isObjectLike from 'lodash/isObjectLike'; | ||
import isNative from 'lodash/isNative'; | ||
|
||
const objectToString = Function.prototype.toString.call(Object); | ||
|
||
function isObjectDeep(any) { | ||
// check if it is a plain object | ||
let result = isPlainObject(any); | ||
if (result) { | ||
return result; | ||
} | ||
// check if it's object | ||
if (isObjectLike(any) === false) { | ||
return false; | ||
} | ||
// get prototype | ||
let proto = Object.getPrototypeOf(any); | ||
// if prototype exists, try to validate prototype recursively | ||
while(proto != null) { | ||
// get constructor | ||
const Ctor = Object.prototype.hasOwnProperty.call(proto, 'constructor') | ||
&& proto.constructor; | ||
// check if constructor is native object constructor | ||
result = (typeof Ctor == 'function') && (Ctor instanceof Ctor) | ||
&& Function.prototype.toString.call(Ctor) === objectToString; | ||
// if constructor is not object constructor and belongs to a native class | ||
if (result === false && isNative(Ctor) === true) { | ||
// return false | ||
return false; | ||
} | ||
// otherwise. get parent prototype and continue | ||
proto = Object.getPrototypeOf(proto); | ||
} | ||
// finally, return result | ||
return result; | ||
} | ||
|
||
export { | ||
isObjectDeep | ||
} |