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

@makercam/openjscam

v0.1.0-beta.7

Published

A TPLang inspired JavaScript to G-Code preprocessor in pure JavaScript.

Downloads

86

Readme

openjscam

A TPLang inspired JavaScript to G-Code preprocessor in pure JavaScript.

installation

OpenJSCAM can be installed using any node package manager, in this example we will use npm.

npm install --save openjscam

You can also grab the bundle.js file in the root of the project, which contains the code + dependencies all together in one file. It puts all the openjscam functions on the window.openjscam property, this is usefull for running it in the browser.

usage

You can add openjscam as a dependency to you project, then import the functions you need, or make all of them available in your scope by using the with (openjscam) {} operator

Example using require:

const {
    rapid,
    cut,
    icut,
    log
} = require('openjscam')

const zSafe = 3
const zCut = -1.5

rapid({ z: zSafe })
rapid({ x: 0, y: 0 })
cut({ z: zCut })
cut({ y: 100 })
cut({ x: 100 })
cut({ y: -100 })
cut({ x: -100 })
rapid({ z: zSafe })
log()

Example using with (openjscam) {}

const openjscam = require('openjscam')

// by using `with`, all properties of the `openjscam` object are automatically available in it's scope.
with (openjscam) {
    const zSafe = 3
    const zCut = -1.5

    rapid({ z: zSafe })
    rapid({ x: 0, y: 0 })
    cut({ z: zCut })
    cut({ y: 100 })
    cut({ x: 100 })
    cut({ y: -100 })
    cut({ x: -100 })
    rapid({ z: zSafe })
    log()
}

api

units(units: METRIC | IMPERIAL)

Set the units (Will output G21 for METRIC or G20 for IMPERIAL)

example

const { units, METRIC, log } = require('openjscam')
units(METRIC)
log()

output

G21

tool(tool: number)

Set the tool to use (usefull when having a tool changer)

NOT IMPLEMENTED YET

example

const { tool, log } = require('openjscam')
tool(1)
log()

feed(feedRate: number)

Set the feedrate

example

const { feed, log } = require('openjscam')
feed(200)
log()

output

F200

speed(speed: number)

Set the spindle speed (in RPM)

example

const { speed, log } = require('openjscam')
speed(25000)
log()

output

M3 S25000

dwell(duration: number)

Pause for given duration, duration is given in seconds

example

const { dwell, log } = require('openjscam')
dwell(0.5)
log()

output

G4 P0.5

cut(coordinate: Coordinate, incremental: boolean = false)

Linear movement to given coordinate. A Coordinate is an object with x, y, z properties. Provide a coordinate for at least one of the axes.

example

const { cut, log } = require('openjscam')
cut({ x: 10, y: 10 })
log()

output

Note that the feedrate will be set using our previous call to feed(200), when no feedrate is set yet, an error will be thrown

G1 X10 Y10

icut(offset: Coordinate, incremental: boolean = true)

Incremental linear movement to given offset from last coordinate. A Coordinate is an object with x, y, z properties. Provide a coordinate for at least one of the axes.

example

const { icut, log } = require('openjscam')
icut({ x: 10, y: 10 })
log()

output

Note that we assumed the last point was X10 Y10 from the previous example.

G1 X20 Y20

rapid(coordinate: Coordinate, incremental: boolean = false)

Rapid movement to given coordinate. A Coordinate is an object with x, y, z properties. Provide a coordinate for at least one of the axes.

example

const { rapid, log } = require('openjscam')
rapid({ x: 10, y: 10 })
log()

output

G0 X10 Y10

irapid(offset: Coordinate, incremental: boolean = true)

Incremental rapid movement to given offset from last coordinate. A Coordinate is an object with x, y, z properties. Provide a coordinate for at least one of the axes.

example

const { irapid, log } = require('openjscam')
irapid({ x: 10, y: 10 })
log()

output

Note that we assumed the last point was X10 Y10 from the previous example.

G0 X20 Y20

arc(offset: Coordinate, angle: number)

Create an arc from with a given offset from the last point and an angle in degrees.

example

const { arc, log } = require('openjscam')
arc({ x: 10 }, 180)
log()

output

Note that we assumed the last point was X0 Y0

G2 X20 Y0 I10 J0 Z0

translate(offset: Coordinate, cb: Function)

Translate (move) child operations by given offset

example

const { translate, cut, log } = require('openjscam')
translate({ x: 100, y: 50 }, function () {
    cut({ x: 10, y: 10 })
})
log()

output

G1 X110 Y60

rotate(angle: number, cb: Function)

Rotate child operations by given angle in degrees

example

const { rotate, cut, log } = require('openjscam')
rotate(45, function () {
    cut({ x: 10, y: 10 })
})
log()

output

G1 X14.142 Y0 Z0

log()

Log the G-Code to the console

example

const { cut, log } = require('openjscam')
cut({ x: 10, y: 10 })
log()

output

G1 X10 Y10

save(path: string)

Save the G-Code to a file (only works in Node.JS)

example

const { cut, save } = require('openjscam')
cut({ x: 10, y: 10 })
save('/path/to/gcode/file.gcode')

gcode()

Returns the G-Code as an array of strings (lines)

example

const { cut, gcode } = require('openjscam')
cut({ x: 10, y: 10 })
var code = gcode()
// do something with the gcode