You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

moddle

Package Overview
Dependencies
Maintainers
9
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

moddle

A library for importing meta-model based file formats into JS


Version published
Weekly downloads
82K
increased by8.33%
Maintainers
9
Created
Weekly downloads
 

Changelog

Source

5.0.4

  • FIX: guard against ModdleElement#set miss-use (#43)

Readme

Source

moddle

CI

A utility library for working with meta-model based data structures.

What is it good for?

moddle offers you a concise way to define meta models in JavaScript. You can use these models to consume documents, create model elements and perform model validation.

A moddle description is a simple JSON file that describes types, their properties and relationships:

{
  "name": "Cars",
  "uri": "http://cars",
  "prefix": "c",
  "types": [
    {
      "name": "Base",
      "properties": [
        { "name": "id", "type": "String", "isAttr": true }
      ]
    },
    {
      "name": "Root",
      "superClass": [ "Base" ],
      "properties": [
        { "name": "cars", "type": "Car", "isMany": true }
      ]
    },
    {
      "name": "Car",
      "superClass": [ "Base" ],
      "properties": [
        { "name": "name", "type": "String", "isAttr": true, "default": "No Name" },
        { "name": "power", "type": "Integer", "isAttr": true },
        { "name": "similar", "type": "Car", "isMany": true, "isReference": true }
      ]
    }
  ]
}

moddle allows you to instantiate that definition and create objects from it:

import { Moddle } from 'moddle';

var cars = new Moddle([ carsJSON ]);

var taiga = cars.create('c:Car', { name: 'Taiga' });

console.log(taiga);
// { $type: 'c:Car', name: 'Taiga' };


var cheapCar = cars.create('c:Car');

console.log(cheapCar.name);
// "No Name"


// really?
cheapCar.get('similar').push(taiga);

Then again, moddle allows you to perform introspection on model instances, too.

var carDescriptor = cheapCar.$descriptor;

console.log(carDescriptor.properties);
// [ { name: 'id', type: 'String', ... }, { name: 'name', type: 'String', ...} ... ]

Have a look at our test coverage to learn about everything that is currently supported.

Resources

  • moddle-xml: read xml documents based on moddle descriptors

License

MIT

Keywords

FAQs

Package last updated on 28 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc