Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
@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
The npm package @appnest/lit-util receives a total of 0 weekly downloads. As such, @appnest/lit-util popularity was classified as not popular.
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.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.