Skip to content

Commit ab78058

Browse files
committed
tech(code dom): Rename toNodeArray to to_node_array, keeping the old name for BBB.
This is done to align the names according the naming conventions in Patternslib. Also, this is not a breaking change, as toNodeArray is now nowhere used (we're using to_element_array instead) and we kept the old name as alias for backwards compatibility.
1 parent f08b83f commit ab78058

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/core/dom.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const document_ready = (fn) => {
4141
*
4242
* @returns {Array} - An array of DOM nodes.
4343
*/
44-
const toNodeArray = (nodes) => {
44+
const to_node_array = (nodes) => {
4545
if (nodes?.jquery || nodes instanceof NodeList) {
4646
nodes = [...nodes];
4747
} else if (nodes instanceof Array === false) {
@@ -60,7 +60,7 @@ const toNodeArray = (nodes) => {
6060
* @returns {Array} - An array of DOM elements.
6161
*/
6262
const to_element_array = (nodes) => {
63-
nodes = toNodeArray(nodes);
63+
nodes = to_node_array(nodes);
6464
// Filter for DOM elements only.
6565
nodes = nodes.filter((node) => node instanceof Element);
6666
return nodes;
@@ -635,7 +635,8 @@ const find_inputs = (el) => {
635635
const dom = {
636636
document_ready: document_ready,
637637
to_element_array: to_element_array,
638-
toNodeArray: toNodeArray,
638+
to_node_array: to_node_array,
639+
toNodeArray: to_node_array, // BBB.
639640
querySelectorAllAndMe: querySelectorAllAndMe,
640641
wrap: wrap,
641642
hide: hide,

src/core/dom.test.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe("core.dom tests", () => {
8888
});
8989
});
9090

91-
describe("toNodeArray tests", () => {
91+
describe("to_node_array tests", () => {
9292
it("returns an array of nodes, if a jQuery object was passed.", (done) => {
9393
const html = document.createElement("div");
9494
html.innerHTML = `
@@ -100,7 +100,7 @@ describe("core.dom tests", () => {
100100
const testee = $("span", html);
101101
expect(testee.length).toBe(2);
102102

103-
const ret = dom.toNodeArray(testee);
103+
const ret = dom.to_node_array(testee);
104104

105105
expect(ret.jquery).toBeFalsy();
106106
expect(ret.length).toBe(2);
@@ -127,7 +127,7 @@ describe("core.dom tests", () => {
127127
const testee = html.querySelectorAll("span");
128128
expect(testee.length).toBe(2);
129129

130-
const ret = dom.toNodeArray(testee);
130+
const ret = dom.to_node_array(testee);
131131
expect(ret instanceof NodeList).toBeFalsy();
132132
expect(ret.length).toBe(2);
133133
expect(ret[0]).toBe(el1);
@@ -139,7 +139,7 @@ describe("core.dom tests", () => {
139139
it("returns an array with a single node, if a single node was passed.", (done) => {
140140
const html = document.createElement("div");
141141

142-
const ret = dom.toNodeArray(html);
142+
const ret = dom.to_node_array(html);
143143
expect(ret instanceof Array).toBeTruthy();
144144
expect(ret.length).toBe(1);
145145
expect(ret[0]).toBe(html);
@@ -148,7 +148,7 @@ describe("core.dom tests", () => {
148148
});
149149

150150
it("returns an empty array, if nothing was passed", (done) => {
151-
const ret = dom.toNodeArray();
151+
const ret = dom.to_node_array();
152152
expect(ret.length).toBe(0);
153153
expect(ret instanceof Array).toBe(true);
154154

@@ -165,6 +165,17 @@ describe("core.dom tests", () => {
165165

166166
done();
167167
});
168+
169+
it("returns only DOM Nodes, using the deprecated name", (done) => {
170+
const el = document.body;
171+
const txt = document.createTextNode("okay");
172+
const ret = dom.toNodeArray([1, false, txt, "okay", el]);
173+
expect(ret.length).toBe(2);
174+
expect(ret[0]).toBe(txt);
175+
expect(ret[1]).toBe(el);
176+
177+
done();
178+
});
168179
});
169180

170181
describe("to_element_array tests", () => {

0 commit comments

Comments
 (0)