open-index/open-npm huggingface dataset:
npm package: @johnrob1880/js-form-calculator
Description: A useful JavaScript form calculation library.
Latest version: 1.0.2

# js-form-calculator

A useful JavaScript form calculation library.


Install with the node package manager:

```bash
npm install @johnrob1880/js-form-calculator --save
```

Install with the yarn package manager:

```bash
yarn add @johnrob1880/js-form-calculator
```

## Usage

```js
import calculateFrom from '@johnrob1880/js-form-calculator'

let values = { "height": 10, "width": 10 }
let form = {
    "formulas": {
		"area":  {
			"type": "number", 
			"precision": "2",
		 	"segments": [{
                    "top": ["height", "*", "width"], 
                    "bottom": [] 
			}] 
		}    
    },
    "inputs": {
        "height": { "type": "number", "validators": ["req"] },
        "width": { "type": "number", "validators": ["req"] }
    }
}

calculateForm(form, values).then(result => {
    console.log(result)
    // outputs
    // { 
    //     values: { height: 10, width: 10, area: 100 },
    //     isValid: true
    // }   

}).catch( e => {
	console.log('error', e)
	assert.fail('Exception thrown')
})
```

## Supported Validators

`req` - required

`str`, `num`, `bool`, `int` - value type

`pos` - positive number

`zpos` - positive number including zero

`neg` - negative number

`gt` - greater than

`gte` - greater than or equal to

`lt` - less than

`lte` - less than or equal to

`btw` - between a min and max value

`in` - a value in a set of values

`date` - a valid date

## Validator options example

```js

// greater than 10
`gt`: { type: 'number', validators: ['req', 'gt'], vargs: [10] }

// greater than or equal to 10
`gte`: { type: 'number', validators: ['req', 'gt'], vargs: [10] }

// length between 1 and 10
`btw`: { type: 'number', validators: ['req', 'btw'], vargs: [1, 10] }

// in a set of values, be sure to pass an array
`in`: { type: 'number', validators: ['req', 'in'], vargs: [[1, 11]]}
```

## License

[MIT](LICENSE).
npm package: @johnrob1880/restyled
Description: CSS in JS styles for RE:DOM
Latest version: 1.0.21

# restyled

CSS in JS styles for RE:DOM

## Installation

Install this package via npm:

```bash
npm install @johnrob1880/restyled
```

## Create

```js
import { el, mount } from 'redom'
import { create } from '@johnrob1880/restyled'

let restyled = create(el)

class App {
    constructor() {
        this.el = el('.app', this.button = restyled.button({
            textContent: 'Submit',
            // ... same props passed to redom el
        })`
            :this {
                display: inline-block;
                background-color: #000000;
                color: #fff;
                border: none;
                padding: 6px 16px;
            }
        `)
    }
    onmount() {
        // inject styles into the document's head section
        restyled.inject(); 
    }
    onunmount() {
        // remove styles from the document's head section
        restyled.unmount();
    }
}

mount(document.body, new App())
```

## CSS

```js 
    import { css, injectRules, unmountRules } from '@johnrob1880/restyled'

    let buttonStyles = css`
        :this {
            display: inline-block;
            background-color: #000000;
            color: #fff;
            border: none;
            padding: 6px 16px;
        }
    `

    class App {
        constructor() {
            this.el =  el('.app', this.button = el('button', {
                className = buttonStyles
            }))
        }
        onmount() {
            // inject styles into the document's head section
            injectRules()
        }
        onunmount() {
            // remove styles from the document's head section
            unmountRules()
        }
    }

    mount(document.body, new App())
```

## classNames utility

```js
    import { el, mount } from 'redom'
    import { classNames } from '@johnrob1880/restyled'

    let x = 1, y = 2

    let app = el('.app', el('button', {
        className: classNames('btn', 'primary', { 'disabled': x === y })
    }))

    mount(document.body, app)
```


## License

[MIT](LICENSE).
npm package: @johnrob1880/string-calc
Description: Utililty function to calculate literal strings.
Author: John Robinson
Latest version: 1.0.2

# string-calc

Utililty function to calculate literal strings.

Perform addition, subtraction, multiplication, and division on numbers.
```js
let str = '1+2'
console.log(stringCalc(str)) // 3

str = '3-2';
console.log(stringCalc(str)) // 1

str = '2*2'
console.log(stringCalc(str)) // 4

str = '8/2'
console.log(stringCalc(str)) // 4
```

Add days to a date
```js
// expects date format to be YYYYMMDD.
let str = '20180101d+10';
console.log(stringCalc(str)) // 20180121
```

Subtract days from a date
```js
// expects date format to be YYYYMMDD.
let str = '20180131d-30';
console.log(stringCalc(str)) // 20180101
```

## License

[MIT](LICENSE).