1.0.8 • Published 1 year ago

i-hate-typescript v1.0.8

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Intro

Keep in mind that this is not a perfect TypeScript replacement. I didn't really feel the need for TypeScript except when checking the promised type. If there is a developer like me who is comfortable with JavaScript, if he understands the project and uses it, he will be able to receive proper help and stable typing. The above project also needs to be specified like an interface, but it is more convenient and easier to consider the configuration part in additional typescript.

Installation

// with npm
npm i i-hate-typescript

Sample Code

/*
    type select default value
    string type is ""
    float, double int is 0
    boolean is true or false default you choose
*/

//example
console.log(ForceType({ a: 0.1 }, { a: 1 }));
console.log(ForceType({ a: 2 }, { a: 1 }));
console.log(ForceType({ a: "" }, { a: 1 }));
console.log(ForceType({ a: true }, { a: 1 }));

//output
// { a: 1 }
// { a: 1 }
// { a: undefined }
// { a: undefined }

You can also use it usefully in your server code.

const express = require("express");
const app = express();
app.use(express.json());
const { ForceType } = require("i-hate-typescript");

let spec = {
  name: "",
  password: "",
  gender: true,
};

app.post("/test", (req, res) => {
  let unmarshal = ForceType(spec, req.body);
  res.status(200).json(unmarshal);
});

app.listen(8888, () => {
  console.log("server boot");
});

output

console.log(unmarshal);
//output : { name: 'test', password: 'test01041', gender: undefined }

Example

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago