Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

property-modeler

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

property-modeler

A module for enforcing strict rules on object properties

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

This project aims to bring some level of data/type safety to NodeJS whilst allowing us to define clean data models.

Check out the tests for a clear picture of how powerful this is.

This is everything thrown together into one place for quick reference:

	var Modeler = require("../Modeler.js");
	var className = 'MyClassName';

	var ThisClass = function(json) {
		// Class Function definitions here:
		this.toString = function() {
		  return this.PropertyName+" "+this.SomeOtherProperty;
		};
		
		// Class property definitions here:
		Modeler.extend(className, {
		  [PropertyName]: {
		    // all of these are optional!
		    type: "SomeOtherClass",
		    default: { DefaultValue },
		    required: true,
		    // filter will be run against all data entering this property
		    filter: {
		      { trim: true },
		      { replace: ['test', 'TEST'] },
		      { encode: 'base64' / 'json' / 'url' },
		      { decode: 'base64' / 'json' / 'url' },
		      { capitalise: true },
		      { toMoney: true },
		      { toUpperCase: true },
		      { toLowerCase: true }
		    },
		    filter: function(v) {
		      ...
		      return v;
		    },
		    // validation will be run against all data entering this property,
		    // AFTER the filter, AFTER type validation and BEFORE the value is set.
		    // Failing validation will throw away the new data.
		    validation: {
		      isIn: ['list', 'of', 'values'],
		      minlength: 2,
		      maxlength: 4,
		      before: new Date(),
		      after: new Date(),
		      regex: /regex/,
		      looksLike: 'postcode' / 'email',
		      min: 1,
		      max: 100
		    },
		    validation: function(v) {
		      ...
		      return true / false;
		    },
		    mask: Modeler.GET | Modeler.SET | Modeler.HIDDEN | Modeler.ARRAY 
		  },
		  [NextProperty]: {
		  .....
		}, this, json);
	};

	module.exports = ThisClass;
	Modeler.register(ThisClass, className);

Keywords

FAQs

Package last updated on 11 Mar 2013

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc