
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
als-component
Advanced tools
Als-component allows you to manage dom content as components with JavaScript.
To show html colored code inside string in js, use es6-string-html plugin
in vsCode and
/*html*/`html code`
new in 0.5
component.genId(start)
method - generating id and increasing it automaticlynew in 0.6
There are 3 files:
Syntax:
new Component(ComponentName,fn,data)
.update(data,id,updateElement=true)
.get(data,id) // => update(data,id,false)
Parameters:
new Component(ComponentName,fn,data)
<tag component="componentName" id="id"></tag>
Component.componentName.data
or Component.componentName.id
if there is idupdate(data,id,updateElement=true)
Component.Upper - Component Component.lower - fn Component.$fn - $utility
<!-- Include component.js -->
<script src="/node_moduls/als-component/component.js"></script>
<!-- Here will appear App component-->
<div component="app"></div>
<script>
// Creating component Test (must be before App)
let Test = new Component('Test',function({testing,some},id) {
return /*html*/`<div component="test">
test component
<div>${testing}</div>
<div>${some}</div>
</div>`
})
// Creating component App with Test component inside
new Component('App',function(data,id) {
let testing = 'testing variable'
return /*html*/`<div component="app">
${Test.get({testing,some:'some variable'},'test-id')}
<input type="text" value="${testing}"
oninput="
Test.data.testing = this.value
Test.update()
">
<div id="test">Hello from main component</div>
</div>`
}).update() // updating component App in html
// element method
App.element() // return app html element
Test.element('test-id') // return test html element
</script>
The example above, creates 2 components(App,Test) and inserting it to <div component="app"></div>
.
let {$genId,$firstUpper,$qs,$qsa,$next,$prev,$parent,$var} = Component
$genId() // idsxiz5j
$genId('test-') // test-sxiz5j
$firstUpper('some'), // Some
$('#test'), // $(selector,source=document) = document.querySelctor(selector)
$$('.some'), // $$(selector,source=document) = document.querySelctorAll(selector)
$next(dom), // = dom.nextElementSibling
$prev(dom), // = dom.previousElementSibling
$parent(dom), // = dom.parentNode
$var('bg-color'), // getting value for css variable var(--bg-color)
$var('bg-color','blue'), // set new value to var(--bg-color)
For using export with express you need to add it as middleware:
app.use(require('als-component').mw)
Now you have available some addition on response (res):
app.get('/',(req,res) => {
res.component(componentName,fn,data,update=false) // creating components
res.fns // array for functions which will be available on Component.fnName
return res.end(`
<some html>
${res.exportComponents() // publishing components and functions}
`)
})
Let's see how todo application will work with Component. The files we will need:
todo.js
module.exports = function(todo,id){
return /*html*/`<div component="todo" id="${id}"
${todo.completed ? 'style="text-decoration:line-through"' : ''}
onclick="
Todo['${id}'].completed = !Todo['${id}'].completed;
Todo.update(undefined,'${id}')
">
${todo.title}
</div>`
}
todos.js
module.exports = function (data,id){
return /*html*/`<div component="todos">
${data.map(todo=> Component.Todo.get(
todo,
Component.Todo.genId('todo')
)).join('')}
</div>`
}
data.js
module.exports = [
{title: "delectus aut autem",completed: true},
{title: "quis ut nam facilis et officia qui",completed: false},
{title: "fugiat veniam minus",completed: false}
]
addnew.js
module.exports = function addNew(element) {
Component.Todos.data.unshift({title:element.value,completed:false})
Component.Todos.update()
}
server.js
const express = require('express')
let app = express()
app.use(require('als-component').mw)
app.get('/',(req,res) => {
res.fns.push(require('./addnew')) // Adding function
// Defining components
res.component('Todo',require('./todo'))
res.component('Todos',require('./todos'),require('./data'),true)
return res.end(/*html*/`<!DOCTYPE html>
<html lang="en">
<head>
<title>Todos</title>
</head>
<body>
<div component="todos"></div>
<input type="text" onchange="Component.addNew(this)">
${res.exportComponents()}
</body>
</html>`)
})
app.listen(3000)
router.js has function router(routes,defaultRoute)
. The function allows you to use html layout for js files and functions.
Parameters:
?route=key
and value is a src of js file or function.Here is example:
<!DOCTYPE html>
<html lang="en">
<head>
<script src="/node_modules/als-component/component.js"></script>
<script src="/node_modules/als-component/router.js"></script>
<title>Some</title>
</head>
<body>
<nav>
<a href="?route=test">test</a>
<a href="?route=test1">test1</a>
</nav>
<main component="main"></main>
</body>
<script>
router({
test1:'/test1.js',
test:() => new Componenet('test',/*html*/`
<main component="main">Hello from test fn</main>
`).update()
},'/home.js')
</script>
</html>
test1.js
new Componenet('Test',/*html*/`
<main component="main">Hello from test1.js</main>
`).update()
home.js
Component.$(['component=main']).innerHTML = /*html*/`
Home page - default page if route not found.
`
FAQs
lightweight JavaScript library for creating reactive, server-rendered, and browser-based components.
The npm package als-component receives a total of 0 weekly downloads. As such, als-component popularity was classified as not popular.
We found that als-component demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.