Giter VIP home page Giter VIP logo

lgtm's Introduction

LGTM

npm version CI

LGTM is a simple JavaScript library for validating objects and collecting error messages. It leaves the display, behavior, and error messages in your hands, focusing on letting you describe your validations cleanly and concisely for whatever environment you're using.

For examples, installation, setup and more see the wiki.

lgtm's People

Contributors

bmish avatar danruehle avatar dependabot[bot] avatar eventualbuddha avatar greenkeeper[bot] avatar greenkeeperio-bot avatar mbyczkowski avatar mongoose700 avatar trmw avatar wlk125 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lgtm's Issues

[Feature Request] Validations on a nested object.

Is it possible to run validations on a nested object?

For instance.

var paymentInfo = {
   creditCard: {
     number: 45343434343,
     expiration: '01/15'
   }
};

var validator = LGTM.validator()
   .validates('creditCard.number').required('Credit card number is required')
.build();

validator.validate(paymentInfo).then(function() {/*... */);

If not, is there a way to do something like this or do I have to build validations for each part separately and combine the results?

Validator not run against empty string values

I could be setting this up incorrectly but for optional validations it seems as though validations are never run if the value is an empty string.

For example:

var nameValidator = LGTM.validator()
    .validates('name')
        .optional()
        .minLength(2, 'The provided name must be at least 2 characters')
    .build()

Will validate with the following input as the validation routine is never actually run:

{ "name": ""}

In the above case the expected output would be an error and the text 'The provided name must be at least 2 characters'.

Here is a jsbin demonstrating this:

http://jsbin.com/yisimuse/2/edit

If this behavior intentional? Do I need to check for empty, undefined and null values outside of LGTM before running the validator on optional values?

An in-range update of rollup is breaking the build 🚨

The devDependency rollup was updated from 1.9.2 to 1.9.3.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

rollup is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v1.9.3

2019-04-10

Bug Fixes

  • Simplify return expressions that are evaluated before the surrounding function is bound (#2803)

Pull Requests

  • #2803: Handle out-of-order binding of identifiers to improve tree-shaking (@lukastaegert)
Commits

The new version differs by 3 commits.

  • 516a06d 1.9.3
  • a5526ea Update changelog
  • c3d73ff Handle out-of-order binding of identifiers to improve tree-shaking (#2803)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Question: why is validation response structure like it is?

Just curious: it seems like we must return 1 and only 1 message for each attribute, but result for each errors attribute is an array, why?

// Validate all attributes and return results with a promise.
validator.validate(person).then(function(result) {
  console.log(result);
  // { "valid": false, "errors": { "firstName": [ ], "lastName": ["You must enter a last name."], "age": [ ] } }
});

add default messages

It's hard to type the same message every time, or even abstract to constants. Maybe we have to have some defaults?

Also, this won't work:

var v = LGTM.validator().validates('name').required().build();
v.validate({foo: 'bar'}).then(function(r) {
  console.log(r); // {valid: true}
});

While this works:

var v = LGTM.validator().validates('name').required('any message').build();
v.validate({foo: 'bar'}).then(function(r) {
  console.log(r); // {valid: false}
});

Add support for custom message

Did not see this within the api documentation anywhere, so if it is supported, please point me in the right direction.

I would like to specify a custom variable message based on the value being validated. Something like:

validator.addValidation('text',
    (text => text.length == 12),
    (text => `Text should be 12 characters long. (${text.length}/12)`));

The key part would be including the ability to display information about the value being validated within the message, rather than a completely static message.

LGTM standalone | $$config$$config.async method is undefined

I do not know why but lgtm-standalone.js does not work at all.

LGTM.validator().build().validate()
TypeError: $$config$$config.async is not a function
$$promise$$Promise.prototype.then()lgtm-st...?body=1 (wiersz 1567)
$$lgtm$object_validator$$ObjectValidator.prototype.validate()lgtm-st...?body=1 (line 198)
$$config$$config.async(function(){

Resolving validation promises?

Hi,

I'm trying to use your validator for my middleware project.

https://github.com/kristianmandrup/validator-mw

In in I have a run() method which executes the validation on a data object, however I always end up returning from the run function before the promise is resolved. I tried using done to wait until it is done, but get a "no such method". Which promise framework is used underneath? Hmm... I don't see any? Just basic node promises? I'm new to promises. Would be nice if you had an example of this in the README. Perhaps I should use defer.resolve() or smth?

run ->
  defer = validator.validate(data).then( -> ...)
  defer.resolve()

PS: I use LiveScript ;)

Dynamic messages

Hi, I want to know if there is a possibility to include a variation of the error message based on the current value of the field that failed validation:

const person = { name: '', isCool: true };
const person2 = { name: '', isCool: false };
// name is required, but if the person is cool, we get a different message.  I don't want to use person instance directly.
LGTM.validator()
  .validates('name')
     .required(object => object.isCool ? 'Person is cool, but needs a name', 'Name is required');
  .build()
.validate(person);

Composing chained validations from multiple validators

I'm using LGTM to validate REST API inputs and found myself repeating the same validations over and over. For example, all my GET endpoints need to validate LIMIT and OFFSET so I have something like this:

var getUsersValidator = LGTM.validator()

    // Validate limit
    .validates('limit')
    .optional()
    .integer(validationJsonError.serialize({
        detail:'The "limit" value must be an integer',
        errorAttribute: 'limit'
    }))
    .minValue(0, validationJsonError.serialize({
            detail:'The minimum value for the "limit" is 0',
            errorAttribute: 'limit'
        }))

    // Validate 'offset'
    .validates('offset')
    .optional()
    .integer(validationJsonError.serialize({
                detail:'The "offset" value must be an integer',
                errorAttribute: 'offset'
            }))
    .minValue(0, validationJsonError.serialize({
                detail: 'The minimum value for the offset is 0',
                errorAttribute: 'offset'
            }))

// Additional validations
.build();

var getPostsValidator =  LGTM.validator()
// Repeat above for limit and offset

Note that instead of returning string messages I return a JSON API error object (http://jsonapi.org/format/#errors). I know in all the examples you return a string but returning the object and then formatting all the JSON API errors into a single JSON API compliant response works really well (might be worth mentioning in the docs that you can return a custom object).

What I'd like to be able to do is compose together different validators to run together as a single compound validation or be able to easily construct a new compound validator from primitive validators (a validator that validates one attribute or property). I'm having a hard time figuring out a clean way to do this.

I basically want to encapsulate the validation logic for limit and the validation logic for offset and then use those as primitives to create a new more complex validator (there are other things like sort and order as well). This is made up but something like this:

var limit = LGTM.validator()    
    .validates('limit')
    .optional()
    .integer(validationJsonError.serialize({
        detail:'The "limit" value must be an integer',
        errorAttribute: 'limit'
    }))
    .minValue(0, validationJsonError.serialize({
            detail:'The minimum value for the "limit" is 0',
            errorAttribute: 'limit'
        }));

var offset = LGTM.validator()
    .validates('offset')
    .optional()
    .integer(validationJsonError.serialize({
                detail:'The "offset" value must be an integer',
                errorAttribute: 'offset'
            }))
    .minValue(0, validationJsonError.serialize({
                detail: 'The minimum value for the offset is 0',
                errorAttribute: 'offset'
            }));


var user = LGTM.validator()
    .maxLength(25)
   .required();

var posts = LGTM.validator()
   .maxLength(200)
   .required();


// My new validators
var getUserValidator = LGTM.build([limit, offset, user]);
var getPostsValidator = LGTM.build([limit, offset, posts]);

Are there some best practices on how I can achieve this? Thanks!

Publish sourcemaps

The bower dist assets have a reference to the sourcemap, but the .map files aren't published. Running make dist generates this ones correctly, but we don't include them.

Any chance we can bump to 1.0.5 in bower and include the maps? Alternatively, we could drop the sourcemap tag instead. This will help reduce the noise in tools (like ember-cli that complains if the sourcemap isn't found) or Chrome devtools that will get a 404.

This is low priority, nothing breaks, but it just creates unnecessary noise.

Changing input values as part of validation?

I really enjoy using LGTM for validation in our Node.js application. One thing I've found myself wanting to be able to do is change input values in a custom helper which right now can only pass back a true or false for whether or not the input value passed validation.

An example use case would be for a helper that checks for a boolean value. In this case I want to validate the boolean value true as well as the string value "true" and likewise for false and "false" (but not count null, 0, or 1 as boolean values). However, if the input is the string "true" or "false" I'd like to convert this into actual boolean values 'true' and 'false' as part of the validation process.

Another example could be as simple as changing the case of an input from upper to lower or formatting a date input into a specific output format as part of the validation process.

Is this something that can currently be done with LGTM? If not, is this something that would be of interest to add?

Thank you!

An in-range update of gzip-size is breaking the build 🚨

The devDependency gzip-size was updated from 5.0.0 to 5.1.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

gzip-size is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v5.1.0

v5.0.0...v5.1.0

Commits

The new version differs by 2 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of mocha is breaking the build 🚨

The devDependency mocha was updated from 6.0.2 to 6.1.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

mocha is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v6.1.0

6.1.0 / 2019-04-07

🔒 Security Fixes

  • #3845: Update dependency "js-yaml" to v3.13.0 per npm security advisory (@plroebuck)

🎉 Enhancements

  • #3766: Make reporter constructor support optional options parameter (@plroebuck)
  • #3760: Add support for config files with .jsonc extension (@sstephant)

📠 Deprecations

These are soft-deprecated, and will emit a warning upon use. Support will be removed in (likely) the next major version of Mocha:

🐛 Fixes

  • #3829: Use cwd-relative pathname to load config file (@plroebuck)
  • #3745: Fix async calls of this.skip() in "before each" hooks (@juergba)
  • #3669: Enable --allow-uncaught for uncaught exceptions thrown inside hooks (@givanse)

and some regressions:

📖 Documentation

🔩 Other

  • #3830: Replace dependency "findup-sync" with "find-up" for faster startup (@cspotcode)
  • #3799: Update devDependencies to fix many npm vulnerabilities (@XhmikosR)
Commits

The new version differs by 28 commits.

  • f4fc95a Release v6.1.0
  • bd29dbd update CHANGELOG for v6.1.0 [ci skip]
  • aaf2b72 Use cwd-relative pathname to load config file (#3829)
  • b079d24 upgrade deps as per npm audit fix; closes #3854
  • e87c689 Deprecate this.skip() for "after all" hooks (#3719)
  • 81cfa90 Copy Suite property "root" when cloning; closes #3847 (#3848)
  • 8aa2fc4 Fix issue 3714, hide pound icon showing on hover header on docs page (#3850)
  • 586bf78 Update JS-YAML to address security issue (#3845)
  • d1024a3 Update doc examples "tests.html" (#3811)
  • 1d570e0 Delete "/docs/example/chai.js"
  • ade8b90 runner.js: "self.test" undefined in Browser (#3835)
  • 0098147 Replace findup-sync with find-up for faster startup (#3830)
  • d5ba121 Remove "package" flag from sample config file because it can only be passes as CLI arg (#3793)
  • a3089ad update package-lock
  • 75430ec Upgrade yargs-parser dependency to avoid loading 2 copies of yargs

There are 28 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of babel7 is breaking the build 🚨

There have been updates to the babel7 monorepo:

    • The devDependency @babel/core was updated from 7.7.7 to 7.8.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

This monorepo update includes releases of one or more dependencies which all belong to the babel7 group definition.

babel7 is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of uglify-js is breaking the build 🚨

The devDependency uglify-js was updated from 3.6.3 to 3.6.4.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

uglify-js is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v3.6.4

 

Commits

The new version differs by 11 commits.

  • 370c8e0 v3.6.4
  • 4240fba fix corner cases in unused (#3519)
  • 267bc70 fix corner case in unused (#3517)
  • a53ab99 fix corner case in side_effects (#3514)
  • 02308a7 fix corner case in reduce_vars (#3510)
  • 0b3705e fix corner cases in inline (#3507)
  • da5a21b fix GitHub Actions script for fuzzing (#3504)
  • 5bd0cf8 enable GitHub Actions (#3503)
  • 9199ab5 minor tweaks (#3502)
  • ca6dce4 fix corner case in collapse_vars (#3501)
  • 543dd7d fix corner case in comments (#3500)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot 📦🚀

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.