Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
Add wrap element helper
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgraham committed Dec 10, 2018
1 parent 26e63f2 commit 505e91e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Also note that `fs.mkdir` doesn't throw an error if the directory already exists
- util.localIp
- util.cancellableDelay
- util.multiResolve - multiple path.resolve
- util.unwrapElement - parse an element ID from an element object: e.g.: `{ELEMENT: 123, "element-6066-11e4-a52e-4f735466cecf": 123}` returns `123`
- util.wrapElement - convert an element ID to an element object of the form: e.g.: `123` returns `{ELEMENT: 123, "element-6066-11e4-a52e-4f735466cecf": 123}`

- *fs.hasAccess* - use this over `fs.access`
- *fs.exists* - calls `fs.hasAccess`
Expand Down
9 changes: 8 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ function unwrapElement (el) {
return el;
}

function wrapElement (elementId) {
return {
ELEMENT: elementId,
[W3C_WEB_ELEMENT_IDENTIFIER]: elementId,
};
}

/*
* Returns object consisting of all properties in the original element
* which were truthy given the predicate.
Expand Down Expand Up @@ -219,7 +226,7 @@ async function isSameDestination (path1, path2, ...pathN) {

export {
hasValue, escapeSpace, escapeSpecialChars, localIp, cancellableDelay,
multiResolve, safeJsonParse, unwrapElement, filterObject,
multiResolve, safeJsonParse, wrapElement, unwrapElement, filterObject,
toReadableSizeString, isSubPath, W3C_WEB_ELEMENT_IDENTIFIER,
isSameDestination,
};
9 changes: 9 additions & 0 deletions test/util-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,15 @@ describe('util', function () {
});
});

describe('wrapElement', function () {
it('should include ELEMENT and w3c element', function () {
util.wrapElement(123).should.eql({
[util.W3C_WEB_ELEMENT_IDENTIFIER]: 123,
ELEMENT: 123,
});
});
});

describe('toReadableSizeString', function () {
it('should fail if cannot convert to Bytes', function () {
(() => util.toReadableSizeString('asdasd')).should.throw(/Cannot convert/);
Expand Down

0 comments on commit 505e91e

Please sign in to comment.