Socket
Socket
Sign inDemoInstall

@wildpeaks/dom-entry-context

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @wildpeaks/dom-entry-context

Read JSON-encoded data from an HTMLElement attribute


Version published
Weekly downloads
1
Maintainers
1
Install size
3.74 kB
Created
Weekly downloads
 

Readme

Source

DOM Entry Context

Github Release

Typescript function to read JSON-encoded data from an HTMLElement attribute.

Install:

npm install @wildpeaks/dom-entry-context

Example: Read a number from the default attribute data-context

index.html:

<div id="mycontainer" data-context="123">

script.ts:

import {Context, getContext} from '@wildpeaks/dom-entry-context';

const context: Context = getContext('mycontainer');
console.log(context.element); // Reference to #mycontainer
console.log(context.data);    // 123

Example: Read an object from a custom attribute

index.html:

<div id="mycontainer" data-myprop='{"hello": {"world": 123}}'>

script.ts:

import {Context, getContext} from '@wildpeaks/dom-entry-context';

const context: Context = getContext('mycontainer', 'data-myprop');
console.log(context.element);          // Reference to #mycontainer
console.log(context.data);             // {"hello": {"world": 123}}
console.log(context.data.hello);       // {"world": 123}
console.log(context.data.hello.world); // 123

Keywords

FAQs

Last updated on 22 Jan 2021

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc