phetsims / query-string-machine

Query String Machine is a query string parser that supports type coercion, default values & validation. No dependencies.
MIT License
3 stars 3 forks source link

Why is window.assert used? #12

Closed samreid closed 8 years ago

samreid commented 8 years ago

From https://github.com/phetsims/query-string-machine/issues/9#issuecomment-249651783

@pixelzoom said:

Also wondering about why window.assert && assert() is being used, seem atypical and inconsistent. Should be either window.assert && window.assert(...) or assert && assert(...). E.g.

window.assert && assert( ok, 'default value should be allowed' );
samreid commented 8 years ago

Query String Machine has been designed as a zero-dependency module for ease of use in any project. From the README https://github.com/phetsims/query-string-machine

Query String parser that supports type coercion, defaults, error checking, etc. based on a schema. Small and dependency-free.

window.assert and assert both check for the existence of a global named assert. However, the latter errors out if the global is not found.

I'm curious to know your thoughts and recommendations @pixelzoom.

pixelzoom commented 8 years ago

Recommended to add this at the top of QueryStringMachine:

// Query String Machine has been designed as a zero-dependency module for ease of use in any project.  
// window.assert and assert both check for the existence of a global named assert. However, the latter errors out if the global is not found.
var assert = window.assert;

... then use PhET's typical assert && assert( ... ) pattern.

samreid commented 8 years ago

Nice idea, committed above, anything else to do here?

pixelzoom commented 8 years ago

👍 Closing.