1.6.1 • Published 2 months ago

garbagescript v1.6.1

Weekly downloads
-
License
ISC
Repository
-
Last release
2 months ago

This is an experimental scripting language designed specifically for data validation. It is intended to be easy to understand and adopt quickly.

Usage

Basic evaluation usage:

import { createScript } from 'garbagescript'

// Create a simple multiplication script
const gs = createScript(`$input * 10`)

// Evaluate the script, providing the predetermined `$input` variable
const result = gs.evaluate({ $input: 5 }) // 50

As a validation utility:

import { createScript } from 'garbagescript'

const { validate } = createScript(`
validate {
  if $display_name == "" {
    reject "Display name is required"
  }

  if $password:length < 8 {
    reject "Password must be at least 8 characters long"
  }

  if $birth_date > today - 18 years {
    reject "You must be 18 years or older"
  }
}
`)

const result = validate({
  $display_name: 'Example',
  $password: 'secret',
  $birth_date: new Date(1980, 3, 15),
})

const errors = result.validationErrors
if (errors.length > 0) {
  // Do something with the errors, in this case there is
  // only one regarding the password:
  for (const error of errors) {
    // "Password must be at least 8 characters long"
    console.log(error.message)
  }
}
1.6.1

2 months ago

1.5.3

4 months ago

1.5.2

4 months ago

1.6.0

4 months ago

1.5.1

4 months ago

1.5.0

4 months ago

1.4.1

4 months ago

1.4.0

4 months ago

1.3.1

5 months ago

1.3.0

5 months ago

1.2.2

5 months ago

1.2.1

5 months ago

1.2.0

6 months ago

1.1.0

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago