Socket
Socket
Sign inDemoInstall

intertype

Package Overview
Dependencies
Maintainers
1
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

intertype - npm Package Compare versions

Comparing version 0.106.0 to 0.107.0

24

lib/helpers.js

@@ -139,8 +139,18 @@ (function() {

//-----------------------------------------------------------------------------------------------------------
this.type_of = function(x) {
var R, arity, c, tagname;
if ((arity = arguments.length) !== 1) {
throw new Error(`^7746^ expected 1 argument, got ${arity}`);
this.type_of = function(x, overrides = null) {
var R, arity, c, i, isa, len, ref1, tagname, type;
if (!((0 < (ref1 = (arity = arguments.length)) && ref1 < 3))) {
throw new Error(`^7746^ expected 1 or 2 arguments, got ${arity}`);
}
//.........................................................................................................
if (overrides != null) {
for (i = 0, len = overrides.length; i < len; i++) {
[type, isa] = overrides[i];
if (isa(x)) {
return type;
}
}
}
if (x === null) {
//.........................................................................................................
return 'null';

@@ -265,2 +275,5 @@ }

return this.isa.boolean(x.collection);
},
"@isa.boolean x.override": function(x) {
return this.isa.boolean(x.override);
}

@@ -280,3 +293,4 @@ }

extras: true,
collection: false
collection: false,
override: false
};

@@ -283,0 +297,0 @@

(function() {
'use strict';
var DECLARATIONS, E, GUY, H, HEDGES, Intertype, Type_factory, debug, help, info, rpr, to_width, urge, warn,
splice = [].splice;
splice = [].splice,
boundMethodCheck = function(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new Error('Bound instance method accessed before binding'); } };

@@ -32,2 +33,3 @@ //###########################################################################################################

super();
this.type_of = this.type_of.bind(this);
this.data = {};

@@ -46,2 +48,3 @@ GUY.props.hide(this, 'cfg', {...H.defaults.Intertype_constructor_cfg, ...cfg});

GUY.props.hide(this, 'type_factory', new Type_factory(this));
GUY.props.hide(this, 'overrides', []);
//.......................................................................................................

@@ -213,2 +216,6 @@ /* TAINT squeezing this in here for the moment, pending reformulation of `isa` &c to make them callable: */

}
if (!GUY.props.get(dsc, 'override', false)) {
return null;
}
this.overrides.unshift([dsc.typename, dsc]);
return null;

@@ -412,2 +419,7 @@ }

type_of(x) {
boundMethodCheck(this, Intertype);
return H.type_of(x, this.overrides);
}
_split_hedgerow_text(hedgerow) {

@@ -444,4 +456,2 @@ return hedgerow.split(this.cfg.sep);

Intertype.prototype.type_of = H.type_of.bind(H);
Intertype.prototype.size_of = H.size_of.bind(H);

@@ -448,0 +458,0 @@

{
"name": "intertype",
"version": "0.106.0",
"version": "0.107.0",
"description": "A JavaScript typechecker",

@@ -5,0 +5,0 @@ "main": "lib/main.js",

@@ -15,2 +15,3 @@

- [`declare`](#declare)
- [The `override` Option](#the-override-option)

@@ -320,2 +321,3 @@ <!-- END doctoc generated TOC please keep comment here to allow auto update -->

hedges like `empty`, `nonempty`
* `override: false`—whether this type should be checked for by `type_of()` (see below for details)

@@ -369,1 +371,20 @@ Like [Clojure spec](https://typedclojure.org)[https://www.youtube.com/watch?v=B_Farscj0hY], InterType

```
#### The `override` Option
The `override` option allows for type declarations to be used by `type_of()` type checks. This feature was
motivated by a case where it was desirable to differentiate functions by their arity (number of arguments);
in this case, types like this one:
```coffee
declare.function3
isa: ( x ) -> ( @isa.function x ) and ( x.length is 3 )
default: ( x, y, z ) ->
override: true
```
that have `override` set to `true` will cause `type_of ( a, b, c ) ->` to return `function3` instead of
`function`. Observe that, as a matter of course, later declarations always take precedence over earlier
ones.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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