
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
bind-element
Advanced tools
make binding between dom element and js object
npm install bind-element
var bind_element = require("bind-element");
ele('divResult3').innerHTML =
'<span id=sp1 class=ht-cmd onclick="alert(\'original click 1, on\')">sp1</span>';
//bindElement(el, obj, bindItem) or
//bindElement(el, obj, "type", typeOption, member, memberOption )
//return Error if fail, or `true` if success
var ret1 = bind_element('sp1', null, ["event", "click", function () { alert("listen 1") }]);
var ret2 = bind_element('sp1', null, "event", "click", function () { alert("listen 2") });
assert( !(ret1 instanceof Error) && !(ret2 instanceof Error) );
/*
bind item array:
an array of bindItem/namePath, that is,
[ bindItem|namePath, bindItem|namePath, ... ]
* namePath: refer query-by-name-path @ npm
* the default namePath is "", for the entry element.
*/
//return an object mapping namePath to dom id if success.
//return Error if fail.
//.bindElementArray(el, obj, bindItemArray)
var ret3 = bind_element.array('sp1', null, [
["event", "click", function () { alert("listen 3") }],
["event", "click", function () { alert("listen 4") }],
]);
assert( !(ret3 instanceof Error) );
console.log(ret3);
bind item:
an array to configure element binding,
[ "type", typeOption, member, memberOption ] //basic format
where type and typeOption is related to dom object,
member and memberOption is related to js object.
or shortcut format,
[ "type", typeOption | "typeItem", member, memberOption | .biDirection/0x1 | ".notifyEvent" | .watchJs/0x2 ] //shortcut format
"type"
dom type string, "on/event|evt/attr/style|css/class/prop|property"
typeOption
dom type option
".typeItem" / ".item"
dom type sub-item string;
shortcut argument is a string;
.valueMapper / .map
a value mapper for setting dom item, refer to mapValue().
member
js member
"propertyName" | "methodName" | function;
memberOption
js member option
.biDirection / .bi
set true to bind both from js to dom and from dom to js;
if not set, bind in default way;
shortcut argument is a boolean value, or a number value contain 0x1;
.notifyEvent / .notify
set name string of bi-direction notify event ( will automatically set biDirection=true );
if not set, use default event "change";
shortcut argument is a string;
.watchJs / .watch
if set true, for type "prop", watch dom property change from js ( will automatically set biDirection=true ).
shortcut argument is a number value contain 0x2;
.valueMapper / .map
a value mapper for setting js member, refer to mapValue().
type format:
"on":
event binding by setting GlobalEventHandlers[ "on" + typeItem ],
[ "on", "click", "methodName" | function, extraArgument ]
"evt|event":
event binding by addEventListener()
[ "event|evt", "click", "methodName" | function, extraArgument={ listenerOptions } ]
"attr":
attribute binding,
[ "attr", "title", "propertyName", extraArgument={ biDirection } ]
[ "attr", "title", "methodName" | function, extraArgument ] //refer to MutationRecord
"css|style":
style binding
[ "style", "display", "propertyName", extraArgument={ biDirection } ]
[ "style", "display", "methodName" | function, extraArgument ] //will also evoke on any other style change; refer to MutationRecord;
"class":
element class binding. default binding member is boolean type.
[ "class", "myClass", "propertyName", extraArgument={ biDirection } ]
[ "class", "myClass", "methodName" | function, extraArgument ] //will also evoke on any other class change; refer to MutationRecord;
"prop|property":
property binding,
[ "prop", "value", "propertyName", extraArgument={ notifyEvent, biDirection, watchJs } ]
[ "prop", "value", "methodName" | function, extraArgument={ notifyEvent, watchJs, listenerOptions } ]
FAQs
make binding between dom element and js object
The npm package bind-element receives a total of 0 weekly downloads. As such, bind-element popularity was classified as not popular.
We found that bind-element demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.