Git Product home page Git Product logo

fusspot's Issues

Maybe remove date and coordinates validators, which seem specific to mapbox-sdk-js

The coordinates validator seems specific to mapbox-sdk-js.

And although "date" sounds like it might be generic enough, it's actually kind of specific to how we decide to type that for mapbox-sdk-js: anything that can be converted to a Date via new Date(x). I'm not sure that's generically useful, since it implies implementation details behind the scenes.

@kepta do you think we should keep either of these?

Enable NODE_ENV performance optimisation

It would be a great feature, especially for frontend applications, if we could provide an assertion function which doesn't run any validation code when NODE_ENV=production. We can write code for this function in such a way that helps code bundler strip the validation code.

Non-empty string assertion

I very often find myself wanting to verify not just that a value is a string but also that that string is not empty. It's very easy to end up with a '' through automatic coercion in JS when a value is essentially undefined or null.

@kepta what do you think about adding a v.nonEmptyString?

Shortcut to set apiName option — possibly rename that option

I want to start trying to use this library frequently to check function arguments that are not necessary objects. In order to get nice clear error message, then, I need to set that apiName option. I was thinking it might be more ergonomic if we could say "If the second argument to assert is a string, we'll consider it the equivalent of apiName." — e.g. v.assert(x, 'something').

I'm also wondering if we might want to rename the apiName option property. I don't really understand the api part of that. How about description?

@kepta what do you think?

New name

@kepta I'm thinking we should give this repo/library a less generic name. How about "formalist" or "fusspot"?

Using fusspot for more than validation?

TLDR: Certain functions in node.js application could benefit from fusspot's parameter validation. This could be used as a sort of react-props for node.js which validates only when running the tests.

A lot of times a simple typo could silently sneak in and cause unexpected behaviour. In the example below, emphasise would remain falsy since foo gets the wrong parameter property.

const foo = ({ abc, xyz, tgif, emphasise }) => {
   if (emphasise) {
      return chalk.bold('I am emphasised');
   }
}

foo({ abc, xyz, tgif, emphasize }); // a simple American to British glitch

Also, if a fellow developer decides to change foo's parameter schema, she/he needs to dig into all the call sites of foo to fix it. These problems aren't anything new and can be carefully fixed with unit testing.

My proposal is that we use fusspot along with unit testing to write less test cases and catch bugs early on. A function could be wrapped around an assertion function (v.assertParams?) and the code would only validate when running tests i.e. NODE_ENV=test else it would simply be a passthrough (for performance reasons).

One of the drawbacks of this approach would be that we would need to write the parameters at two places and keep them in sync. Also, it is a non standard solution and might throw some people off.

v.number should reject NaN

Although typeof NaN === 'number', I'd expect that you always want to reject NaN if you're expecting a real number.

Implement and/or document extension mechanism

One of the goals of the library is to make it easy to integrate custom validators. Right now that feature is undocumented. Let's make sure it is in fact easy and then document the method.

0.7.1 is a breaking change

@kepta I think we should revert 0.7.1 and the change for #39.

The misunderstanding there is that if a property is actually required, that should be made explicit with fusspot.required. In @kellyoung's example where f.assert(f.strictShape({name: f.string}))({}) passes, that's fine name is not required. If name were required, the schema should be changed to f.stripeShape({ name: f.required(f.string)) }).

Is coordinates validator too strict with longitude?

There are valid reasons for providing longitudes that exceed +/-180, so I worry that our validator is being too strict.

Should we only enforce that latitude is +/-90, since I don't know of any reasons to exceed those limits? Or should we instead remove this validator and just check that we have an array of two numbers?

cc @mapbox/frontend-platform

Unnecessary space between items in list

Error: The following keys of value did not pass validation:

      - files: files is required.

      - settings: settings is required.

Seems like there are too many empty lines involved.

Add Date object validator

I think every single time I use this project I also want a Date object validator.

Here's a quick implementation:

function validateDate(value) {
  if (!(value instanceof Date) || value.toString() === 'Invalid Date') {
    return 'date';
  }
};

@kepta any objections to getting this into the main library?

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.