npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

type-czech

v1.7.4

Published

<a id="fast-start"></a> <a id="s"></a> # TypeCzech

Downloads

38

Readme

TypeCzech

Ditch TypeScript and use TypeCzech runtime type checking instead. Live editable JSFiddles with visible type checking in the list below.

Shortest Possible Live Example

The shortest easiest possible example on a live editable JSFiddle.

    type_czech = TypeCzech('LOG-ERRORS')                  // type checking code
                
    function BEFORE_addXY(x, y) {                                            
        return type_czech.checkParam_type([x, y], ['number', 'number'])      
    }                                                                        
    addXY = type_czech.linkUp(addXY, BEFORE_addXY)                           
                                                                             
function addXY(x, y) { return x + y }                     // your code

console.log(" 5 + 5     = ", addXY(5, 5))
linesConsole(2)
console.log(" 6 + 'six' = ", addXY(6, 'six'))             // type error
linesConsole(1)
console.log(" 7 + 7     = ", addXY(7, 7))

Base Example

The motivation is to verify function parameters before execution, and function results after completion with PRE_yourRoutine() and POST_yourRoutine() functions. The example below will not log any type errors in Node.js nor the browser as there are no type errors.

diagram

Run this live on an editable JSFiddle

diagram

React Node.js SSR Barebones Example

This example is live on Render.com as a slow to start, free hosted site that takes 30-180 seconds to start. View the browser console for type errors as below. The barebones source needs three commands to start.

  • npm install
  • npm run dev
  • http://localhost:3000/

Program started with "npm run dev"

diagram

diagram

Program started with "npm run prod"

When the program is launched in production mode, all type checking stops. The incorrect string type is no longer caught.

diagram

diagram

A live editable JSFiddle 707 - React JSX example shows how to type check the parameters of a React list component, as well as the properties of the structure returned.

Node.js Async/Await Example

The live Run Time Type Checking Square Root Finder, 150 seconds to start on free hosting, verifies that live aysnc server calls have correct number types. The types checked for are 'Roman Numerals', 'Word Numbers', 'Floats', and 'Integers'. Run locally with the Square Root Finder source.

The server responds with the square root of XVI is in fact IV.

roman 'xvi' romanSqr('xvi')

Here we see an error when we try to calculate the square root of 16 as a roman number on the server. Locally we get the "'16' is not a valid roman number", and since the server decides that this is a "400 Bad Request", TypeCzech warns us that the server never returns a valid answer with the "POST_serverGetSqrt E did not return within 3007 milliseconds" error message.

The idea is to simulate a non-returning server crash.

roman 16 romanSqr(16)

The server responds with the square root of 16 is 4.

roman 'xvi' integerSqr(16)

A live editable JSFiddle 703 - Async Await shows how to check return types inside an await function.

Live Editable Type-Czech JSFiddle Examples

Contents of 74 live editable examples. Best 'Editor layout' is 'Right results'.

| | | | | | |------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------| | 00-Readme-Example | 01 - What is TypeCzech? | 02 - Validate Parameters by Value | 03 - Turn Off TypeCzech by Not Loading Library | 04 - Turn off by Not Loading Checking Functions | | 05 - Verify Return Results by Value | 06 - Validate Parameters And Results | 07 - Mutated Function Parameters | 08 - Mutated Recursive Function Parameters | 09 - Closure Parameters, Results, and Methods | | 10 - Class Parameters, Results, and Methods | 11 - Object Properties | 12 - Object Interface | 13 - Parameter and Result Multi Scalar Types | 14 - Array and Object Types with Parameter and Results | | 15 - Lone Single Type Parameter Functions | 16 - Arrays with One Type | 17 - Variadic Functions | 18 - Class Type Checks | 19 - Lone Empty Parameter and Result | | 20 - Multiple Empty Parameters and Results | 21 - Extra Optional Parameters | 22 - Empty Checks with Extra Optional Parameters | 23 - Typed Either Checks | 24 - Empty Either Checks | | 25 - Default Parameters | 26 - Empty Abbreviations | 27 - Types, Emptiness, and Extra Parameters | 28 - Accept Null and Undefined Values | 29 - Class Object Type Checks | | 30 - HTML Element Type Checks | 31 - Extended Class Type Checks | 32 - Extended Closure Type Checks | 33 - Count Parameter Checking Function Calls | 34 - Parameter Check Events | | 35 - Throw, Log, or Ignore | 36 - Turn-On, Turn-Off | 37 - Readme Example Arrow Functions | 38 - Every Check | 39 - Check Asserts | | | 40 - Prescribed Use | 41 - Lens Example | 42 - Extended Objects | 43 - PHP On Off Extending Classes | | Classes | 101 - Extended Classes Inline | 102 - Extended Classes Imported | 103 - Extended Classes Production | | | Closures | 201 - Closure Modules Inline | 202 - Closure Modules Imported | 203 - Closure Modules Production | 204 - Extending Closures Single | | IIFEs | 301 - IIFE Modules Inline | 302 - IIFE Modules Imported | 303 - IIFE Modules Production | 304 - Extending IIFEs Single | | Class Free | 401 - ClassFree Constructors Inline | 402 - ClassFree Constructors Imported | 403 - ClassFree Constructors Production | 404 - Extending ClassFree Single | | Prototypes | 501 - Inherited Prototypes Inline | 502 - Inherited Prototypes Imported | 503 - Inherited Prototypes Production | 504 - Extending Prototypes Single | | OLOO | 601 - Created OLOO Inline | 602 - Created OLOO Imported | 603 - Created OLOO Production | 604 - Extending OLOO Single
|   | 700 - Simple-Example | 701 - Array of Objects | 702 - DeClassify |703 - Async Await | | 704 - Ramda Curry | 705 - Sensible Switching | 706 - Elegant On Off | 707 - React JSX |708 - Monad Type Checking |

To Install the Package

NPM JavaScript library for Node.js projects.

npm i type-czech

Require for Node.js is Supported, as Well as Import for React

const { TypeCzech_obj } = require("./node_modules/type-czech/type-czech-require.js");

import TypeCzech_obj from "./node_modules/type-czech/type-czech-import.js";

Online Examples

Why Use

Function Expression Error - Uncaught ReferenceError: myFunction is not defined

Lottery Example

Assert Pollution

The Idea

The Recipe

Type Signatures

Empty Strings, Arrays, and Objects

JSFiddle - 74 Page Live Online Editable Tutorial

Local Filesystem - 74 Page Local Editable Tutorial

16 Simple How To Snippets

TypeCzech API

Node.js Only Examples

Browser and Node.js Tests

Recommended Techniques

Production TypeCzech

FAQ

Dependencies

Run Tests

Compile New Versions

Created by

Steen Hansen

© 2024 Steen Hansen