-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #198 from lightning-js/dev
Release 1.8.1
- Loading branch information
Showing
8 changed files
with
216 additions
and
24 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
"allowJs": true, | ||
"checkJs": true, | ||
"noEmit": true, | ||
"strict": true | ||
"strict": true, | ||
"noImplicitThis": true | ||
} | ||
} |
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,50 @@ | ||
/* | ||
* Copyright 2024 Comcast Cable Communications Management, LLC | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
const deepEqualArray = (array1, array2) => { | ||
if (array1 === array2) return true | ||
if (array1.length !== array2.length) return false | ||
|
||
let l = array1.length | ||
|
||
while (l--) { | ||
const value1 = array1[l] | ||
const value2 = array2[l] | ||
|
||
// values are arrays, deepEqual nested arrays | ||
if (Array.isArray(value1) && Array.isArray(value2)) { | ||
if (deepEqualArray(value1, value2) === false) return false | ||
} | ||
// values are objects, deepEqual nested objects | ||
else if ( | ||
typeof value1 === 'object' && | ||
value1 !== null && | ||
typeof value2 === 'object' && | ||
value2 !== null | ||
) { | ||
if (deepEqualArray(Object.entries(value1), Object.entries(value2)) === false) return false | ||
} | ||
// other type, do strict equal check | ||
else if (value1 !== value2) { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} | ||
|
||
export default deepEqualArray |
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,127 @@ | ||
/* | ||
* Copyright 2024 Comcast Cable Communications Management, LLC | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import test from 'tape' | ||
import deepEqual from './deepEqualArray.js' | ||
|
||
test('Type', (assert) => { | ||
const expected = 'function' | ||
const actual = typeof deepEqual | ||
|
||
assert.equal(actual, expected, 'deepEqual should be a function') | ||
assert.end() | ||
}) | ||
|
||
test('The same arrays', (assert) => { | ||
const val1 = ['hello', 'world'] | ||
|
||
assert.true( | ||
deepEqual(val1, val1), | ||
'deepEqual should return true if the values are the same reference' | ||
) | ||
assert.end() | ||
}) | ||
|
||
test('Equal simple arrays', (assert) => { | ||
const val1 = ['hello', 'world'] | ||
const val2 = ['hello', 'world'] | ||
|
||
assert.true(deepEqual(val1, val2), 'deepEqual should return true if simple arrays are equal') | ||
assert.end() | ||
}) | ||
|
||
test('Not equal simple arrays', (assert) => { | ||
const val1 = ['hello', 'world'] | ||
const val2 = ['world', 'hello'] | ||
|
||
assert.false( | ||
deepEqual(val1, val2), | ||
'deepEqual should return false if simple arrays are not equal' | ||
) | ||
assert.end() | ||
}) | ||
|
||
test('Not Equal simple arrays (different length)', (assert) => { | ||
const val1 = ['hello', 'world'] | ||
const val2 = ['hello', 'world', '!'] | ||
|
||
assert.false(deepEqual(val1, val2), 'deepEqual should return false if simple arrays are equal') | ||
assert.end() | ||
}) | ||
|
||
test('Equal nested arrays', (assert) => { | ||
const val1 = ['hello', ['world', '!']] | ||
const val2 = ['hello', ['world', '!']] | ||
|
||
assert.true(deepEqual(val1, val2), 'deepEqual should return true if nested arrays are equal') | ||
assert.end() | ||
}) | ||
|
||
test('Not equal nested arrays', (assert) => { | ||
const val1 = ['hello', ['world', '!']] | ||
const val2 = ['hello', ['world', '!', '?']] | ||
|
||
assert.false( | ||
deepEqual(val1, val2), | ||
'deepEqual should return false if nested arrays are not equal' | ||
) | ||
assert.end() | ||
}) | ||
|
||
test('Equal arrays with objects', (assert) => { | ||
const val1 = [{ foo: 'bar', bar: 'foo' }, { hello: 'world' }] | ||
const val2 = [{ foo: 'bar', bar: 'foo' }, { hello: 'world' }] | ||
|
||
assert.true( | ||
deepEqual(val1, val2), | ||
'deepEqual should return true if arrays with objects are equal' | ||
) | ||
assert.end() | ||
}) | ||
|
||
test('Not equal arrays with objects (keys', (assert) => { | ||
const val1 = [{ foo: 'bar', bar: 'foo' }, { test: 'bla' }] | ||
const val2 = [{ foo2: 'bar', bar2: 'foo' }, { test: 'bla' }] | ||
|
||
assert.false( | ||
deepEqual(val1, val2), | ||
'deepEqual should return false if arrays with objects are not equal' | ||
) | ||
assert.end() | ||
}) | ||
|
||
test('Equal arrays with mixed values', (assert) => { | ||
const val1 = ['foo', { foo: 'bar', bar: 'foo' }, ['hello', 'world', ['this', 'is', { level: 2 }]]] | ||
const val2 = ['foo', { foo: 'bar', bar: 'foo' }, ['hello', 'world', ['this', 'is', { level: 2 }]]] | ||
|
||
assert.true( | ||
deepEqual(val1, val2), | ||
'deepEqual should return true if arrays with mixed values are equal' | ||
) | ||
assert.end() | ||
}) | ||
|
||
test('Not Equal arrays with mixed values', (assert) => { | ||
const val1 = ['foo', { foo: 'bar', bar: 'foo' }, ['hello', 'world', ['this', 'is', { level: 2 }]]] | ||
const val2 = ['foo', { foo: 'bar', bar: 'foo' }, ['hello', 'world', ['this', 'is', { level: 3 }]]] | ||
|
||
assert.false( | ||
deepEqual(val1, val2), | ||
'deepEqual should return true if arrays with mixed values are not equal' | ||
) | ||
assert.end() | ||
}) |
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