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

minimalistic-js

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

minimalistic-js

Cross-platform simple validation

  • 1.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
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

Package last updated on 04 Dec 2017

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