Skip to content

Commit

Permalink
Minor cleanup (#131)
Browse files Browse the repository at this point in the history
* Remove some unnecessary bits

* Update test to reflect behavior
  • Loading branch information
jgarber623 authored Oct 15, 2023
1 parent 9261dcd commit ca3f086
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
7 changes: 2 additions & 5 deletions src/cashcash.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
class Cash {
length = 0;

#nodes;

constructor(selector, context) {
selector = typeof selector === 'string' ? selector.trim() : '';

Expand All @@ -11,13 +9,12 @@ class Cash {
selector = this.selector = typeof context === 'string' && context.trim().length > 0 ? `${context.trim()} ${selector}` : selector;
context = this.context = context instanceof HTMLElement ? context : document;

const nodes = this.nodes = context.querySelectorAll(selector);
const nodes = context.querySelectorAll(selector);

this.length = nodes.length;
this.forEach = nodes.forEach;

// eslint-disable-next-line unicorn/prefer-spread
for (const [index, node] of Array.from(nodes).entries()) {
for (const [index, node] of nodes.entries()) {
this[index] = node;
}
}
Expand Down
6 changes: 3 additions & 3 deletions test/cashcash.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ test('valid non-matching selector, valid non-matching context (HTMLElement)', t
const context = document.querySelector('#bar');
const cash = CashCash('#foo', context);

t.is(cash.context, context);
t.is(cash.context, document);
t.is(cash.selector, '#foo');
t.is(cash.length, 0);
});
Expand Down Expand Up @@ -124,9 +124,9 @@ test('valid matching selector, valid non-matching context (HTMLElement)', t => {
const context = document.querySelector('#foo');
const cash = CashCash('p', context);

t.is(cash.context, context);
t.is(cash.context, document);
t.is(cash.selector, 'p');
t.is(cash.length, 0);
t.is(cash.length, 5);
});

test('valid matching selector, valid matching context (String)', t => {
Expand Down

0 comments on commit ca3f086

Please sign in to comment.