Socket
Socket
Sign inDemoInstall

minimalistic-js

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    minimalistic-js

Cross-platform simple validation


Version published
Weekly downloads
16
decreased by-15.79%
Maintainers
1
Install size
14.5 kB
Created
Weekly downloads
 

Readme

Source

minimalistic.js

Installation

To install the stable version:

npm install --save minimalistic-js

Example validation

Check string
import { validation, methods } from 'minimalistic-js';

const loginError = validation({
    value: 'admin', // input value
    methods: { // check methods
        required: methods.required,
        email: methods.isEmail
    },
    messages: { // error messages
        required: 'The field is required',
        email: 'The email address entered is invalid'
    }
});

if (loginError) {
    console.warn(loginError);
}
Check file
import { validation, methods } from 'minimalistic-js';

const fileError = validation({
    value: File, // your file
    methods: { // check methods
        required: methods.required,
        maxFileSize: methods.maxFileSize(100000)
    },
    messages: { // error messages
        required: 'The field is required',
        maxFileSize: 'The maximum file size is 100kb'
    }
});

if (fileError) {
    console.warn(fileError);
}
Example ES5 Node.js
var minimalisticJs = require("minimalistic-js");

var fieldError = minimalisticJs.validation({
    value: '',
    methods: { // check methods
        required: minimalisticJs.methods.required
    },
    messages: { // error messages
        required: 'The field is required'
    }
});

if (fieldError) {
    console.warn(fieldError);
}

Check methods

https://github.com/LeadSoftInc/minimalistic.js/blob/master/src/methods.js

Create custom check method

import { validation } from 'minimalistic-js';

// custom check method
function customMethod(value) {
    return value.length === 0;
}

const fieldError = validation({
    value: '', // your value
    methods: { // check methods
        custom: customMethod
    },
    messages: { // error messages
        custom: 'Custom error message'
    }
});

if (fieldError) {
    console.warn(fieldError);
}

Keywords

FAQs

Last updated on 04 Dec 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc