struct-type
A struct type for JavaScript.
Last updated 4 years ago by robotlolita .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install struct-type 
SYNC missed versions from official npm registry.

struct-type

Chat on GitterBuild statusNPM versionDependencies statusLicenceStability: Stable

A restricted Struct type for JavaScript.

Example

const struct = require('struct-type');
const t = struct.types;

const Point2d = struct('Point2d', {
  x: t.Any,
  y: t.Any
});

// Make new instances with `.make`
const p1 = Point2d.make({ x: 1, y: 2 });
const p2 = Point2d.make({ x: 2, y: 2 });

// Update fields with `set<Field>`. 
// This constructs a new prototype-based shallow copy (with Object.create):
const p1_2 = p1.setX(2);
p1;   // ==> { x: 1, y: 2 }
p1_2; // ==> { x: 2, __proto__: p1 }

// Flatten structs into regular objects to pass to APIs expecting regular JS objects:
p1_2.toObject();
// ==> { x: 2, y: 2, __proto__: null }

// Each struct gets its own type function:
const Line = struct('Line', {
  start: Point2d.type,
  end: Point2d.type
});

const line = Line.make({ start: p1, end: p2 });

Installation

The officially supported way of getting Refinable is through npm:

$ npm install struct-type

NOTE

If you don't have npm, you'll need to install Node.js in your system before installing Refinable.

A tool like Browserify or Webpack can be used to run Refinable in platforms that don't implement Node-style modules, like the Browser.

Supported platforms

Refinable is supported in all platforms that support ECMAScript 5.

NOTE
For platforms that don't support ECMAScript 5, (like IE8 and 9) the es5-shim library can be used to provide the additional runtime support.

Support

If you think you've found a bug in the project, or want to voice your frustration about using it (maybe the documentation isn't clear enough? Maybe it takes too much effort to use?), feel free to open a new issue in the Github issue tracker.

Pull Requests are welcome. By submitting a Pull Request you agree with releasing your code under the MIT licence.

You can join the Gitter Channel for quick support. You may also contact the author directly through email, or Twitter.

Note that all interactions in this project are subject to Origami Tower's Code of Conduct.

Licence

struct-type is copyright (c) Quildreen Motta 2016, and released under the MIT licence. See the LICENCE file in this repository for detailed information.

Current Tags

  • 1.0.0                                ...           latest (4 years ago)

1 Versions

  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |