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

@airtasker/form-schema-compiler

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@airtasker/form-schema-compiler

a form schema compiler

  • 0.0.11
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
985
decreased by-59.48%
Maintainers
1
Weekly downloads
 
Created
Source

Air tasker from schema compiler

Helps your create a security (sandbox) custom form.
npm downloads

Installation

npm install --save @airtasker/form-schema-compiler

This assumes that you’re using npm package manager with a module bundler like Webpack or Browserify to consume CommonJS modules.

If you don’t yet use npm or a modern module bundler, and would rather prefer a single-file UMD build that makes FormSchemaCompiler available as a global object.

Documentation

compileComponents(schema, [options]):AST

Compile an airtasker form schema to an AST (abstract structure tree).

Arguments
  • schema: Airtaker form schema
  • options: { typeCompilers }
    • typeCompilers: { [TYPE]: createCompiler():{[before(schema)], [after(AST)]}}: you can add custom components compiler. it have high priority than default components compiler.

apply(ast, options):any

Apply an AST.

Arguments
  • ast: an compiled AST

  • options: { variableGetter(name), applyComponents }

    • variableGetter(name)(function): if there is a identifier type, will use this function to get variable value
    • applyComponents(componentASTs)(function): components type handler.

const

a const file

export const TYPES = {
  Numeric: 'Numeric',
  String: 'String',
  Boolean: 'Boolean',
  Null: 'Null',
  RegExp: 'RegExp',
  Identifier: 'Identifier',
  BinaryExpression: 'BinaryExpression',
  UnaryExpression: 'UnaryExpression',
  CallExpression: 'CallExpression',
  Components: 'Components',
  Operator: 'Operator',
  Punctuation: 'Punctuation',
  Raw: 'Raw',
};

export const PRIMITIVES = [
  TYPES.Numeric,
  TYPES.String,
  TYPES.Boolean,
  TYPES.Null,
];

export const OBJECTS = [TYPES.RegExp, TYPES.Identifier, TYPES.Component];

export const EXPRESSIONS = [
  TYPES.BinaryExpression,
  TYPES.CallExpression,
  TYPES.UnaryExpression,
];

export const OPERATORS = {
  Add: '+',
  Subtract: '-',
  Multiply: '*',
  Remainder: '%',
  Divide: '/',
  GreaterThan: '>',
  GreaterThanOrEqualTo: '>=',
  LessThan: '<',
  LessThanOrEqualTo: '<=',
  EqualTo: 'is',
  NotEqualTo: 'isnt',
  And: 'and',
  Or: 'or',
  Match: 'match',
  Not: 'not',
};

export const ANNOTATION_TYPES = {
  Expression: 'Expression',
  Template: 'Template',
  Component: 'Component',
  Action: 'Action',
  DataBinding: 'DataBinding',
};

export const ANNOTATIONS = {
  [ANNOTATION_TYPES.Expression]: ['{', '}'],
  [ANNOTATION_TYPES.Template]: ['#', '#'],
  [ANNOTATION_TYPES.Component]: ['<', '>'],
  [ANNOTATION_TYPES.Action]: ['(', ')'],
  [ANNOTATION_TYPES.DataBinding]: ['[', ']'],
};

export const GLOBAL_FUNCTIONS = {
  toString: 'toString'
};

Schema

Airtasker form schema using JSON schema.

Annotation
  • key: no annotation, compile as json
    compile

    {
      key: "1",
      key2: 1,
      key3: null,
      key4: true,
      key5: []
    }
    

    to

    {
      key: {type: "String", value: "1"},
      key2: {type: "Number", value: 1},
      key3: {type: "Null", value: null},
      key4: {type: "Boolean", value: true},
      key5: {type: "Raw", value: []},
    }
    
  • <key>: component annoation
    compile

      {"<key>": {/*component schema*/}}
    

    to

      {"key": {/*component ast*/}}
    
  • [key]: data binding compile

      {"[key]": "foo"}
    

    to

      {"key": { type: "identifier", name: "foo" }
    
  • #key#: template
    compile

      {"#key#": "foo{"bar"}"}
    

    to

      {
        "key": {
          type: "BinaryExpression",
          left: { type: "String", value: "foo" },
          operator: "+",
          right: {
            type: "callExpression",
            callee: { type: "identifier", name: "toString" },
            arguments: [{ type: "identifier", name: "bar" }]
          }
        }
      }
    
  • {key}: expression
    compile

      {"{key}": "1 + 2"}
    

    to

      {
        "key": {
          type: "BinaryExpression",
          left: { type: "Numeric", value: "1" },
          operator: "+",
          right: { type: "Numeric", value: "2" },
        }
      }
    
  • (key): action, eventValue is a special identifier that's reference the action callback value
    compile

      {"(click)": "doAction(eventValue)"}
    

    to

      {
        "onClick": {
          type: "callExpression",
          callee: { type: "identifier", name: "doAction" },
          arguments: [{ type: "identifier", name: "eventValue" }]
        }
      }
    

License

MIT

Keywords

FAQs

Package last updated on 19 Apr 2018

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