Maker.js, a Microsoft Garage project, is a JavaScript library for creating and sharing modular line drawings for CNC and laser cutters.

View project on GitHub Star

Api - MakerJs Namespace

Root module for Maker.js.

Example: get a reference to Maker.js

var makerjs = require('makerjs');

Index

Variables

environment

environment: string

Current execution environment type, should be one of environmentTypes.

version

version: string

Version info

Functions

$

  • Create a container to cascade a series of functions upon a model. This allows JQuery-style method chaining, e.g.:

    makerjs.$(shape).center().rotate(45).$result
    

    The output of each function call becomes the first parameter input to the next function call. The returned value of the last function call is available via the .$result property.

    Parameters

    • modelContext: IModel

      The initial model to execute functions upon.

    Returns ICascadeModel

    A new cascade container with ICascadeModel methods.

  • Create a container to cascade a series of functions upon a path. This allows JQuery-style method chaining, e.g.:

    makerjs.$(path).center().rotate(90).$result
    

    The output of each function call becomes the first parameter input to the next function call. The returned value of the last function call is available via the .$result property.

    Parameters

    • pathContext: IModel

      The initial path to execute functions upon.

    Returns ICascadePath

    A new cascade container with ICascadePath methods.

  • Create a container to cascade a series of functions upon a point. This allows JQuery-style method chaining, e.g.:

    makerjs.$([1,0]).scale(5).rotate(60).$result
    

    The output of each function call becomes the first parameter input to the next function call. The returned value of the last function call is available via the .$result property.

    Parameters

    • pointContext: IPoint

      The initial point to execute functions upon.

    Returns ICascadePoint

    A new cascade container with ICascadePoint methods.

cloneObject

  • cloneObject<T>(objectToClone: T): T

createRouteKey

  • createRouteKey(route: string[]): string

extendObject

  • extendObject(target: Object, other: Object): Object
  • Copy the properties from one object to another object.

    Example:

    makerjs.extendObject({ abc: 123 }, { xyz: 789 }); //returns { abc: 123, xyz: 789 }
    

    Parameters

    • target: Object

      The object to extend. It will receive the new properties.

    • other: Object

      An object containing properties to merge in.

    Returns Object

    The original object after merging.

isChain

  • isChain(item: any): boolean

isFunction

  • isFunction(value: any): boolean

isModel

  • isModel(item: any): boolean

isNumber

  • isNumber(value: any): boolean

isObject

  • isObject(value: any): boolean

isPath

  • isPath(item: any): boolean

isPathArc

  • isPathArc(item: any): boolean

isPathArcInBezierCurve

  • isPathArcInBezierCurve(item: any): boolean

isPathCircle

  • isPathCircle(item: any): boolean

isPathLine

  • isPathLine(item: any): boolean

isPoint

  • isPoint(item: any): boolean

round

  • round(n: number, accuracy?: number): number
  • Numeric rounding

    Example: round to 3 decimal places

    makerjs.round(3.14159, .001); //returns 3.142
    

    Parameters

    • n: number

      The number to round off.

    • Default value accuracy: number = 1e-7

      Optional exemplar of number of decimal places.

    Returns number

    Rounded number.

splitDecimal

  • splitDecimal(n: number): string[]
  • Split a decimal into its whole and fractional parts as strings.

    Example: get whole and fractional parts of 42.056

    makerjs.splitDecimal(42.056); //returns ["42", "056"]
    

    Parameters

    • n: number

      The number to split.

    Returns string[]

    Array of 2 strings when n contains a decimal point, or an array of one string when n is an integer.

travel

  • travel(modelContext: IModel, route: string | string[]): object
  • Travel along a route inside of a model to extract a specific node in its tree.

    Parameters

    • modelContext: IModel

      Model to travel within.

    • route: string | string[]

      String of a flattened route, or a string array of route segments.

    Returns object

    Model or Path object within the modelContext tree.

Object literals

environmentTypes

environmentTypes: object

Enumeration of environment types.

BrowserUI

BrowserUI: string

NodeJs

NodeJs: string

Unknown

Unknown: string

WebWorker

WebWorker: string

pathType

pathType: object

String-based enumeration of all paths types.

Examples: use pathType instead of string literal when creating a circle.

var circle: IPathCircle = { type: pathType.Circle, origin: [0, 0], radius: 7 };   //typescript
var circle = { type: pathType.Circle, origin: [0, 0], radius: 7 };   //javascript

Arc

Arc: string

BezierSeed

BezierSeed: string

Circle

Circle: string

Line

Line: string

unitType

unitType: object

String-based enumeration of unit types: imperial, metric or otherwise. A model may specify the unit system it is using, if any. When importing a model, it may have different units. Unit conversion function is makerjs.units.conversionScale(). Important: If you add to this, you must also add a corresponding conversion ratio in the unit.ts file!

Centimeter

Centimeter: string

Foot

Foot: string

Inch

Inch: string

Meter

Meter: string

Millimeter

Millimeter: string

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc