Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
@appnest/lit-util
Advanced tools
This project is a collection of functions I tend to use when building projects based on lit-html. The goal is to give you some inspiration and make your life a little easier when finding yourself in need of the same functionality.
npm i @appnest/lit-util
// en.json
{
"lang": "en",
"header": {
"title": "Hello",
"subtitle": "World"
},
"cta": {
"awesome": "{{ things }} are awesome!",
"cats": "Cats"
}
}
Use the function getStrings
to load the strings at a given path. If you want to cache the strings for next time you are using the getStrings
function, you might want to cache the result using the function addStringsToCache
using the path as key.
const path = `/assets/i18n/en.json`;
const strings = await getStrings(path);
addStringsToCache(path, strings);
Use the function setStrings
to set the current strings of the language. When this function is invoked, the event stringsChanged
will be dispatched on the window object.
await setStrings(strings);
To get a translated string use the function get
. Give this function a string with the chain of keys that points to the desired string in the JSON structure. The below example is based on the strings defined in step 1
.
get("lang"); // "en"
get("header.title"); // "Hello"
get("header.subtitle"); // "World"
Using the get
function it is possible to interpolate values. Simply use the {{ key }}
syntax in your strings and provide an object with values replacing those defined in the string when using the get
function. The below example is based on the strings defined in step 1
.
get("cta.awesome", { thing: get("cta.cats") )); // Cats are awesome!
translate
directiveIf you are using lit-html
you might want to use the translate
directive. This directive makes sure to automatically update all of the translated parts when the method setStrings
is called and the stringsChanged
event is dispatched on the window object.
class MyComponent extends LitElement {
render () {
html`
<h1>${translate("header.title")}</h1>
<p>${translate("header.subtitle")}</p>
<span>${translate("cta.awesome", {things: get("cta.cats") })}</span>
`;
}
}
@customElement()
to define your custom elements.Use the customElement
decorator to define your custom elements. Simply give it a tag-name and your custom element will be defined.
@customElement("hello-component")
export class HelloComponent extends LitElement {
...
}
Coming soon..
Coming soon..
Licensed under MIT.
FAQs
A collection of useful functions for projects based on lit-html
We found that @appnest/lit-util demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.