Skip to content

Commit

Permalink
Fix spec
Browse files Browse the repository at this point in the history
  • Loading branch information
feonit committed Mar 11, 2019
1 parent 43213e1 commit ee2a760
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 3 deletions.
8 changes: 7 additions & 1 deletion spec/helpers/helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import isEqual from './../../node_modules/lodash-es/isEqual.js'
export let isEqual;

try {
isEqual = _.isEqual
} catch (error) {
isEqual = require('../../node_modules/lodash/isEqual.js')
}

export const jsonParseStringify = (data)=>{
return JSON.parse(JSON.stringify(data))
Expand Down
2 changes: 1 addition & 1 deletion spec/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="../node_modules/lodash/lodash.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
<link data-require="[email protected]" data-semver="2.4.1" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.css" />
<script data-require="[email protected]" data-semver="2.4.1" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.js"></script>
<script data-require="[email protected]" data-semver="2.4.1" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine-html.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion src/Cube.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Tuple from './Tuple.js'
import Space from './Space.js'
import Cell from './Cell.js'
import { DEFAULT_FACT_ID_PROP } from './const.js'
import isPlainObject from "./../node_modules/lodash-es/isPlainObject.js"
import isPlainObject from "./isPlainObject.js"
import {NotFoundFactId} from "./errors.js";

/**
Expand Down
83 changes: 83 additions & 0 deletions src/isPlainObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
const toString = Object.prototype.toString

/**
* Gets the `toStringTag` of `value`.
*
* @private
* @param {*} value The value to query.
* @returns {string} Returns the `toStringTag`.
*/
function getTag(value) {
if (value == null) {
return value === undefined ? '[object Undefined]' : '[object Null]'
}
return toString.call(value)
}

/**
* Checks if `value` is object-like. A value is object-like if it's not `null`
* and has a `typeof` result of "object".
*
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
* @example
*
* isObjectLike({})
* // => true
*
* isObjectLike([1, 2, 3])
* // => true
*
* isObjectLike(Function)
* // => false
*
* isObjectLike(null)
* // => false
*/
function isObjectLike(value) {
return typeof value == 'object' && value !== null
}

/**
* Checks if `value` is a plain object, that is, an object created by the
* `Object` constructor or one with a `[[Prototype]]` of `null`.
*
* @since 0.8.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
* @example
*
* function Foo() {
* this.a = 1
* }
*
* isPlainObject(new Foo)
* // => false
*
* isPlainObject([1, 2, 3])
* // => false
*
* isPlainObject({ 'x': 0, 'y': 0 })
* // => true
*
* isPlainObject(Object.create(null))
* // => true
*/
function isPlainObject(value) {
if (!isObjectLike(value) || getTag(value) != '[object Object]') {
return false
}
if (Object.getPrototypeOf(value) === null) {
return true
}
let proto = value
while (Object.getPrototypeOf(proto) !== null) {
proto = Object.getPrototypeOf(proto)
}
return Object.getPrototypeOf(value) === proto
}

export default isPlainObject

0 comments on commit ee2a760

Please sign in to comment.