-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new
isDocumentFragment
& isShadowRoot
functions
- Loading branch information
Showing
6 changed files
with
292 additions
and
0 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
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,21 @@ | ||
import instanceOf from './utils/instanceOf'; | ||
|
||
/** | ||
* Determines whether the given value is a DocumentFragment. | ||
* | ||
* @example | ||
* ```js | ||
* isDocumentFragment({}); // false | ||
* isDocumentFragment(Document); // false | ||
* isDocumentFragment(Window); // false | ||
* isDocumentFragment(document.getRootNode()); // false | ||
* isDocumentFragment(document.body); // false | ||
* isDocumentFragment(document.querySelector('html')); // false | ||
* isDocumentFragment(document.createElement('img')); // false | ||
* isDocumentFragment(new DocumentFragment()); // true | ||
* isDocumentFragment(document.createDocumentFragment()); // true | ||
* ``` | ||
*/ | ||
export default function isDocumentFragment(value: unknown): value is ShadowRoot { | ||
return instanceOf(value, DocumentFragment); | ||
} |
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,20 @@ | ||
import instanceOf from './utils/instanceOf'; | ||
|
||
/** | ||
* Determines whether the given value is a ShadowRoot. | ||
* | ||
* @example | ||
* ```js | ||
* isShadowRoot({}); // false | ||
* isShadowRoot(Document); // false | ||
* isShadowRoot(Window); // false | ||
* isShadowRoot(document.getRootNode()); // false | ||
* isShadowRoot(document.body); // false | ||
* isShadowRoot(document.querySelector('html')); // false | ||
* isShadowRoot(document.createElement('img')); // false | ||
* isShadowRoot(document.createElement('span').attachShadow({ mode: 'open' })); // true | ||
* ``` | ||
*/ | ||
export default function isShadowRoot(value: unknown): value is ShadowRoot { | ||
return instanceOf(value, ShadowRoot); | ||
} |
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,120 @@ | ||
/** | ||
* ❌: The expectation should be equal to false | ||
* ✅: The expectation should be equal to true | ||
* ➖: The expectation can be equal to true or false | ||
*/ | ||
|
||
import values from '../__Fixtures/values'; | ||
import isDocumentFragment from '../../src/isDocumentFragment'; | ||
|
||
const KEY = 'documentFragments'; | ||
|
||
describe('is:isDocumentFragment', () => { | ||
it(`❌ nil !== ${KEY}`, () => { | ||
values.nil.forEach((value) => { | ||
expect(isDocumentFragment(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ booleans !== ${KEY}`, () => { | ||
values.booleans.forEach((value) => { | ||
expect(isDocumentFragment(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ integers !== ${KEY}`, () => { | ||
values.integers.forEach((value) => { | ||
expect(isDocumentFragment(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ floats !== ${KEY}`, () => { | ||
values.floats.forEach((value) => { | ||
expect(isDocumentFragment(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ numbers !== ${KEY}`, () => { | ||
values.numbers.forEach((value) => { | ||
expect(isDocumentFragment(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ bigInts !== ${KEY}`, () => { | ||
values.bigInts.forEach((value) => { | ||
expect(isDocumentFragment(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ strings !== ${KEY}`, () => { | ||
values.strings.forEach((value) => { | ||
expect(isDocumentFragment(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ symbols !== ${KEY}`, () => { | ||
values.symbols.forEach((value) => { | ||
expect(isDocumentFragment(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ arrays !== ${KEY}`, () => { | ||
values.arrays.forEach((value) => { | ||
expect(isDocumentFragment(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ DOM elements !== ${KEY}`, () => { | ||
values.elements.forEach((value) => { | ||
expect(isDocumentFragment(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ DOM nodeLists !== ${KEY}`, () => { | ||
values.nodeLists.forEach((value) => { | ||
expect(isDocumentFragment(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`➖ DOM alternative contexts !== || === ${KEY}`, () => { | ||
values.alternativeDOMs.forEach((value) => { | ||
expect(isDocumentFragment(value)).toEqual(value instanceof DocumentFragment); | ||
}); | ||
}); | ||
|
||
it(`❌ functions !== ${KEY}`, () => { | ||
values.functions.forEach((value) => { | ||
expect(isDocumentFragment(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ classes !== ${KEY}`, () => { | ||
values.classes.forEach((value) => { | ||
expect(isDocumentFragment(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ object constructors !== ${KEY}`, () => { | ||
values.constructors.forEach((value) => { | ||
expect(isDocumentFragment(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ invoked object constructors !== ${KEY}`, () => { | ||
values.invokedConstructors.forEach((value) => { | ||
expect(isDocumentFragment(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ object instances !== ${KEY}`, () => { | ||
values.instances.forEach((value) => { | ||
expect(isDocumentFragment(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ objects !== ${KEY}`, () => { | ||
values.objects.forEach((value) => { | ||
expect(isDocumentFragment(value)).toEqual(false); | ||
}); | ||
}); | ||
}); |
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,120 @@ | ||
/** | ||
* ❌: The expectation should be equal to false | ||
* ✅: The expectation should be equal to true | ||
* ➖: The expectation can be equal to true or false | ||
*/ | ||
|
||
import values from '../__Fixtures/values'; | ||
import isShadowRoot from '../../src/isShadowRoot'; | ||
|
||
const KEY = 'shadowRoots'; | ||
|
||
describe('is:isShadowRoot', () => { | ||
it(`❌ nil !== ${KEY}`, () => { | ||
values.nil.forEach((value) => { | ||
expect(isShadowRoot(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ booleans !== ${KEY}`, () => { | ||
values.booleans.forEach((value) => { | ||
expect(isShadowRoot(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ integers !== ${KEY}`, () => { | ||
values.integers.forEach((value) => { | ||
expect(isShadowRoot(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ floats !== ${KEY}`, () => { | ||
values.floats.forEach((value) => { | ||
expect(isShadowRoot(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ numbers !== ${KEY}`, () => { | ||
values.numbers.forEach((value) => { | ||
expect(isShadowRoot(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ bigInts !== ${KEY}`, () => { | ||
values.bigInts.forEach((value) => { | ||
expect(isShadowRoot(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ strings !== ${KEY}`, () => { | ||
values.strings.forEach((value) => { | ||
expect(isShadowRoot(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ symbols !== ${KEY}`, () => { | ||
values.symbols.forEach((value) => { | ||
expect(isShadowRoot(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ arrays !== ${KEY}`, () => { | ||
values.arrays.forEach((value) => { | ||
expect(isShadowRoot(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ DOM elements !== ${KEY}`, () => { | ||
values.elements.forEach((value) => { | ||
expect(isShadowRoot(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ DOM nodeLists !== ${KEY}`, () => { | ||
values.nodeLists.forEach((value) => { | ||
expect(isShadowRoot(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`➖ DOM alternative contexts !== || === ${KEY}`, () => { | ||
values.alternativeDOMs.forEach((value) => { | ||
expect(isShadowRoot(value)).toEqual(value instanceof ShadowRoot); | ||
}); | ||
}); | ||
|
||
it(`❌ functions !== ${KEY}`, () => { | ||
values.functions.forEach((value) => { | ||
expect(isShadowRoot(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ classes !== ${KEY}`, () => { | ||
values.classes.forEach((value) => { | ||
expect(isShadowRoot(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ object constructors !== ${KEY}`, () => { | ||
values.constructors.forEach((value) => { | ||
expect(isShadowRoot(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ invoked object constructors !== ${KEY}`, () => { | ||
values.invokedConstructors.forEach((value) => { | ||
expect(isShadowRoot(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ object instances !== ${KEY}`, () => { | ||
values.instances.forEach((value) => { | ||
expect(isShadowRoot(value)).toEqual(false); | ||
}); | ||
}); | ||
|
||
it(`❌ objects !== ${KEY}`, () => { | ||
values.objects.forEach((value) => { | ||
expect(isShadowRoot(value)).toEqual(false); | ||
}); | ||
}); | ||
}); |