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 Module

Root module for Maker.js.

Example: get a reference to Maker.js

var makerjs = require('makerjs');

Index

Variables

Private Const _kdbush

_kdbush: any

Private clone

clone: any

environment

environment: string

Current execution environment type, should be one of environmentTypes.

Private Const kdbush

kdbush: kdbushLib

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
  • Clone an object.

    Type parameters

    • T

    Parameters

    • objectToClone: T

      The object to clone.

    Returns T

    A new clone of the original object.

createRouteKey

  • createRouteKey(route: string[]): string
  • Create a string representation of a route array.

    Parameters

    • route: string[]

      Array of strings which are segments of a route.

    Returns string

    String of the flattened array.

Private detectEnvironment

  • detectEnvironment(): 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
  • Test to see if an object implements the required properties of a chain.

    Parameters

    • item: any

      The item to test.

    Returns boolean

isFunction

  • isFunction(value: any): boolean
  • Test to see if a variable is a function.

    Parameters

    • value: any

      The object to test.

    Returns boolean

    True if the object is a function type.

isModel

  • isModel(item: any): boolean
  • Test to see if an object implements the required properties of a model.

    Parameters

    • item: any

    Returns boolean

isNumber

  • isNumber(value: any): boolean
  • Test to see if a variable is a number.

    Parameters

    • value: any

      The object to test.

    Returns boolean

    True if the object is a number type.

isObject

  • isObject(value: any): boolean
  • Test to see if a variable is an object.

    Parameters

    • value: any

      The object to test.

    Returns boolean

    True if the object is an object type.

isPath

  • isPath(item: any): boolean
  • Test to see if an object implements the required properties of a path.

    Parameters

    • item: any

      The item to test.

    Returns boolean

isPathArc

  • isPathArc(item: any): boolean
  • Test to see if an object implements the required properties of an arc.

    Parameters

    • item: any

      The item to test.

    Returns boolean

isPathArcInBezierCurve

  • isPathArcInBezierCurve(item: any): boolean
  • Test to see if an object implements the required properties of an arc in a bezier curve.

    Parameters

    • item: any

      The item to test.

    Returns boolean

isPathCircle

  • isPathCircle(item: any): boolean
  • Test to see if an object implements the required properties of a circle.

    Parameters

    • item: any

      The item to test.

    Returns boolean

isPathLine

  • isPathLine(item: any): boolean
  • Test to see if an object implements the required properties of a line.

    Parameters

    • item: any

      The item to test.

    Returns boolean

isPoint

  • isPoint(item: any): boolean
  • Test to see if an object implements the required properties of a point.

    Parameters

    • item: any

      The item to test.

    Returns 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.

Private split

  • split(s: string, char: string): string[]
  • Parameters

    • s: string
    • char: string

    Returns string[]

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.

Private tryEval

  • tryEval(name: string): any

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