New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

duckless

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

duckless

Runtime javascript typization

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

Duckless

Duckless is a wrapper for you functions, that allows you to use Haskell style function definitions. After that, while runtime, if your function was called in improper way it will be thrown a clear human-readable exception.

Currently supports:

  • Number of arguments
  • Base JavaScript types
  • Complex types, based on JSON Schema
  • Returned value of the function

How to use

let def = require('duckless').def;
let Type = require('duckless').Type;

new Type({
	"title": "Human",
	"type": "object",
	"properties": {
		"firstName": {
			"type": "string"
		},
		"lastName": {
			"type": "string"
		},
		"age": {
			"description": "Age in years",
			"type": "integer",
			"minimum": 0
		}
	},
	"required": ["firstName", "lastName"]
});

let sayMyName = human => `${human.firstName} ${human.lastName}`;

sayMyName = def(sayMyName, ':: Human -> String');

sayMyName({firstName: "Werner", lastName: "Heisenberg"}); // Werner Heisenberg
sayMyName({firstName: "Werner"}); // Missing required property: lastName in 1 argument "Human"

Why?

The first question may be: why not to use TypeScript, Flow or other typed languages for js?

The answer is yes, please use them, they are really good ones, but if you don't want to bring transpilers into your projects, duckless maybe that what you need.

The second point is that after compiling you will still have JavaScript and in some cases (for example when data comes externally) errors still can occur. Using duckless at least you will get a good point to debug the issue.

Keywords

FAQs

Package last updated on 17 Apr 2016

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