Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
A set of utilities for building UIs with React
v1.1.0
npm i 0ui
See an example of how everything is used together in example/src/index.js
<script src="https://unpkg.com/0ui/dist/0ui.umd.js"></script>
lib/core.js
Random utilities
More like a shorthand for switch/case
import { match } from "0ui/lib/core";
match("loading")({
loading: () => console.log("Loading"),
error: () => console.log("Error")
});
// "Error"
Immutable style data manipulation for plain JavaScript objects, see imtbl lib.
lib/state.js
Independent state object
import State from "0ui/lib/state";
const state = State.create(0);
state.addWatch("key", (key, state, prevVal, nextVal) => {
console.log(prevVal, nextVal);
});
state.swap(val => val + 1); // 0 1
lib/derived-state.js
Derives state -> state' with a function and propagates updates from state -> state'
import State from "0ui/lib/state";
import DerivedState from "0ui/lib/derived-state";
const bucket = State.create({
items: [
{
price: 104.5
},
{
price: 78.2
}
]
});
const bucketPrice = DerivedState.create(bucket, ({ items }) =>
items.reduce((sum, { price }) => sum + price, 0)
);
bucketPrice.state; // 182.7
bucket.swap(removeFirstItem);
bucketPrice.state; // 178.2
lib/multimethod.js
Multiple dispatch or multimethods is a feature of some programming languages in which a function or method can be dynamically dispatched based on the run-time (dynamic) type or, in the more general case some other attribute, of more than one of its arguments. Wikipedia
import MultiMethod from "0ui/lib/multimethod";
const toJSON = MultiMethod.create(v => {
if (Array.isArray(v)) {
return "array";
} else {
return typeof v;
}
});
toJSON.addMethod("string", v => JSON.stringify(v));
toJSON.addMethod("number", v => v.toString());
toJSON.addMethod("array", arr => {
const jsonArr = arr.map(v => toJSON.dispatch(v)).join(", ");
return `[${jsonArr}]`;
});
toJSON.addMethod("object", o => {
const jsonObj = Object.entries(o)
.map(([k, v]) => toJSON.dispatch(k) + ":" + toJSON.dispatch(v))
.join(", ");
return `{${jsonObj}}`;
});
toJSON.dispatch({
items: [1, "two"]
});
// {"items":[1, "two"]}
lib/ui.js
React Component API wrapper. Subscribes to multiple State objects.
import { createComponent } from "0ui/lib/ui";
import State from "0ui/lib/state";
const Counter = createComponent({
states: {
count: State.create(0) // local state
},
render(states, props) {
const { count } = states;
return (
<div>
<button onClick={() => count.swap(v => v - 1)}>-</button>
<span>{count.state}</span>
<button onClick={() => count.swap(v => v + 1)}>+</button>
</div>
);
}
});
FAQs
A set of utilities for building UIs with React
The npm package 0ui receives a total of 16 weekly downloads. As such, 0ui popularity was classified as not popular.
We found that 0ui 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.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.