
Security Fundamentals
Obfuscation 101: Unmasking the Tricks Behind Malicious Code
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Simple finite state machine. With guard conditions and callbacks
$ npm install --save makina
import createStateMachine from 'makina';
// Some guard conditions
const always = () => true;
const never = () => false;
// Create a simple SM
const myStateMachine = createStateMachine({
initState: 'INIT',
transitions: [
['INIT', 'start', always, 'STATE1'],
['STATE1', 'goBack', always, 'INIT'],
['STATE1', 'continue', always, 'STATE2'],
['STATE2', 'goBack', never, 'INIT'],
['STATE2', 'goBack', always, 'STATE1'],
['STATE2', 'finish', always, 'END']
]
});
myStateMachine.start().continue().goBack().continue().getState();
// STATE 2
The createStateMachine
method receives a state machine config object with only 2 keys:
initState
: the initial state of the state machine.transitions
: a list with the transition definitions. A transition definition has the format:['from state', 'transitionName', guardCondition, 'to state']
When a state machine (sm
) is in the estate 'from state'
and the sm.transitionName(data)
method is called, it
will return the state 'to state'
if guardCondition(data) == true
.
If the guard condition is not satisfied but there is another transition definition with the same name and a different guard condition, it will be executed.
const isEven = (n) => n % 2 === 0;
const isOdd = (n) => !isEven(n);
const myStateMachine = createStateMachine({
initState: 'INIT',
transitions: [
['INIT', 'start', isEven, 'STATE1'],
['INIT', 'start', isOdd, 'STATE2']
]
});
myStateMachine.start(2).getState(); // STATE1
myStateMachine.start(1).getState(); // STATE2
You can register a callback to be called after a transition is executed:
const myStateMachine = createStateMachine({
initState: 'INIT',
transitions: [
['INIT', 'start', always, 'STATE1', (msg) => console.log(msg)]
]
});
myStateMachine.start('hello callback'); // hello callback
$ npm install
$ npm test
FAQs
Simple finite state machine. With guard conditions and callbacks
The npm package makina receives a total of 0 weekly downloads. As such, makina popularity was classified as not popular.
We found that makina 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.
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.
Security News
Biome's v2.0 beta introduces custom plugins, domain-specific linting, and type-aware rules while laying groundwork for HTML support and embedded language features in 2025.