npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dlcs

v1.1.0

Published

Digital Logic Circuit Simulator in Javascript.

Downloads

29

Readme

DLCS

npm version Build Status

Digital Logic Circuit Simulation library in javascript.

Simulate nodes, logic gates, and ICs.

Install

NPM

npm install dlcs
var DLCS = require('dlcs'); 

Clientside

<script src="funary.js"></script>
<script src="DLCS.js"></script>

Example Simple AND with OR gate:

Screenshot

var DLCS = require('dlcs');

//New output node
var outputnode = new DLCS(DLCS.outputnode);

//New OR gate
var orgate = new DLCS(DLCS.orgate);

//New AND gate
var andgate = new DLCS(DLCS.andgate);

//Set inputs paths
outputnode.addInput(orgate).addInput(andgate);

//New input nodes
var inputnode0 = new DLCS(DLCS.inputnode);
var inputnode1 = new DLCS(DLCS.inputnode);
var inputnode2 = new DLCS(DLCS.inputnode);

//Connect to AND
andgate.addInput(inputnode0);
andgate.addInput(inputnode1);
orgate.addInput(inputnode2);

//Set single values
inputnode0.setValue(1,0); //1
inputnode1.setValue(1,0); //1
inputnode2.setValue(0,0); //0

//Simulate circuit
var result = outputnode.simulate().getOutputValues(); //[1]

Example Full adder IC

Screenshot

Full adder takes in inputs A , B, and CIN(Carry in). S(Sum) is addition of inputs. COUT(Carry out) is the overflow of the addition of inputs.

| A | B | CIN | COUT | S | |---|---|-----|------|---| | 0 | 0 | 0 | 0 | 0 | | 0 | 0 | 1 | 0 | 1 | | 0 | 1 | 0 | 0 | 1 | | 0 | 1 | 1 | 1 | 0 | | 1 | 0 | 0 | 0 | 1 | | 1 | 0 | 1 | 1 | 0 | | 1 | 1 | 0 | 1 | 0 | | 1 | 1 | 1 | 1 | 1 |

var DLCS = require('dlcs');

//New Full adder
var fa = new DLCS(DLCS.fa);

//Auto generate array of input and output nodes
var innodes = fa.addInputNodes();
var outnodes = fa.addOutputNodes();

//Set input values
innodes[0].setOutputValues([0]); //0
innodes[1].setOutputValues([1]); //1
innodes[2].setOutputValues([1]); //1

//Little endianess
var result0 = outnodes[0].simulate().getOutputValues(); //[0]
var result1 = outnodes[1].simulate().getOutputValues(); //[1]

N-bit adder

N-bit adder

I0(least significant) to IN(most significant) is the first binary number.

IN+1(least significant) to I2N(most significant) is the second binary number.

N-bit adder takes both and adds them.

N-bit adder

N-bit adder produces U0 to UN+1 output.

//New adder with 8 inputs and 5 outputs
var nadder = new DLCS(DLCS.nadder,0,8,5);

//Auto generate array of input and output nodes
var innodes = nadder.addInputNodes();

//Set input values of one number
innodes[0].setOutputValues([0]); //0
innodes[1].setOutputValues([1]); //1
innodes[2].setOutputValues([0]); //0
innodes[3].setOutputValues([1]); //1

//Set input values of one number
innodes[4].setOutputValues([1]); //1
innodes[5].setOutputValues([1]); //1
innodes[6].setOutputValues([1]); //1
innodes[7].setOutputValues([1]); //1

//Little endianess
var result = nadder.simulate().getOutputValues(); //[1, 0, 0, 1, 1]

Extending DLCS for custom components

//New function of XOR and AND
var customfunction = function (input) {
    return [((input[0] ^ input[1]) & input[2])];
}

//New custom IC data
var customICdata = {"inputs":3,
                "name": "custom",
                "outputs":1,
                "outputvalues":[-1],
                "outputfunction": customfunction
};

//New custom IC data
var customIC = new DLCS(customICdata);

//Generate input nodes
var innodes = customIC.addInputNodes();

innodes[0].setOutputValues([0]); //0
innodes[1].setOutputValues([1]); //1
innodes[2].setOutputValues([0]); //0

customIC.simulate();

var result = customIC.getOutputValues(); //[0]

dlcircuit (Main object)

var DLCS = require('dlcs');

//The object returned from DLC or DLCSim is dlcircuit
//dlcircuit is the object that forms every gate, node, and IC
var andgate = new DLCS(DLCS.andgate);

//Each object contains an output array
//This returns the the output array
andgate.getOutputValues();

//Setting the output array
andgate.setOutputValues([1]);

//Setting individual element
andgate.setValue(1,0);

//Instantaneous simulation of object
//The values will be set and stored until some other operation happens
andgate.simulate();

Related projects

funary npm version

Arbitrary precision binary operations library for Javascript.