Skip to content

Commit

Permalink
ts init
Browse files Browse the repository at this point in the history
  • Loading branch information
berkaytheunicorn committed Oct 18, 2021
1 parent b987ce3 commit 493771a
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 51 deletions.
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"tabWidth": 2,
"useTabs": false,
"arrowParens": "always",
"trailingComma": "all",
"singleQuote": false
}
16 changes: 3 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"name": "@doubco/wtf",
"version": "0.0.7",
"version": "1.0.1",
"description": "Type checker for JS",
"main": "lib/index.js",
"commonjs": "lib/index.cjs.js",
"module": "lib/index.es.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "rollup -c -w",
Expand All @@ -29,20 +27,12 @@
"undefined"
],
"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/preset-env": "^7.1.0",
"babel-eslint": "^10.0.1",
"eslint": "^5.6.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-prettier": "^3.0.0",
"prettier": "^1.14.3",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-commonjs": "^9.1.8",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-peer-deps-external": "^2.2.0",
"rollup-plugin-url": "^2.0.0"
"rollup-plugin-typescript2": "^0.30.0",
"typescript": "^4.4.4"
},
"author": "Doub.co",
"license": "MIT",
Expand Down
27 changes: 7 additions & 20 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
import babel from "rollup-plugin-babel";
import commonjs from "rollup-plugin-commonjs";
import external from "rollup-plugin-peer-deps-external";
import resolve from "rollup-plugin-node-resolve";
import url from "rollup-plugin-url";
import typescript from "rollup-plugin-typescript2";

import pkg from "./package.json";

export default {
input: "./src/index.js",
input: "./src/index.ts",
output: [
{
file: pkg.main,
format: "cjs",
sourcemap: true,
exports: "named"
exports: "named",
},
{
file: pkg.module,
format: "es",
sourcemap: true,
exports: "named"
}
],
plugins: [
external(),
url(),
babel({
exclude: "node_modules/**"
typescript({
rollupCommonJSResolveHack: false,
clean: true,
}),
resolve(),
commonjs()
]
],
};
36 changes: 19 additions & 17 deletions src/index.js → src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ globals
Symbol
*/

export const isString = i => {
export const isString = (i: any) => {
return typeof i === "string" || i instanceof String;
};

export const isArray = i => {
export const isArray = (i: any) => {
return Array.isArray(i);
};

export const isObject = i => {
export const isObject = (i: any) => {
if (i === null || isArray(i)) {
return false;
}
return typeof i === "function" || typeof i === "object";
};

export const isDate = value => {
export const isDate = (value: any) => {
let getDay = Date.prototype.getDay;
let tryDateObject = function tryDateGetDayCall(value) {
let tryDateObject = function tryDateGetDayCall(value: any) {
try {
getDay.call(value);
return true;
Expand All @@ -42,47 +42,47 @@ export const isDate = value => {
: toStr.call(value) === dateClass;
};

export const isFunction = i => {
export const isFunction = (i: any) => {
return i && {}.toString.call(i) === "[object Function]";
};

export const isFloat = n => {
export const isFloat = (n: any) => {
return Number(n) === n && n % 1 !== 0;
};

export const isInteger = n => {
export const isInteger = (n: any) => {
return Number(n) === n && n % 1 === 0;
};

export const isNumber = n => {
export const isNumber = (n: any) => {
return isFloat(n) || isInteger(n);
};

export const isEmpty = value => {
export const isEmpty = (value: any) => {
if (value === null) return true;
if (value === undefined) return true;
if (isObject(value) && !Object.keys(value).length) return true;
if (!value.length) return true;
};

export const isRegExp = input => {
export const isRegExp = (input: any) => {
return Object.prototype.toString.call(input) === "[object RegExp]";
};

export const isBoolean = input => {
export const isBoolean = (input: any) => {
return input === true || input === false;
};

export const isISO8601 = input => {
export const isISO8601 = (input: string) => {
let re = /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]+)?(Z)?$/;
return re.test(input);
};

export const isNull = i => {
export const isNull = (i: any) => {
return i == null || i == undefined;
};

export const isColor = input => {
export const isColor = (input: string) => {
if (isString(input)) {
let re = /#(?:[a-f\d]{3}){1,2}\b|rgb\((?:(?:\s*0*(?:25[0-5]|2[0-4]\d|1?\d?\d)\s*,){2}\s*0*(?:25[0-5]|2[0-4]\d|1?\d?\d)|\s*0*(?:100(?:\.0+)?|\d?\d(?:\.\d+)?)%(?:\s*,\s*0*(?:100(?:\.0+)?|\d?\d(?:\.\d+)?)%){2})\s*\)|hsl\(\s*0*(?:360|3[0-5]\d|[12]?\d?\d)\s*(?:,\s*0*(?:100(?:\.0+)?|\d?\d(?:\.\d+)?)%\s*){2}\)|(?:rgba\((?:(?:\s*0*(?:25[0-5]|2[0-4]\d|1?\d?\d)\s*,){3}|(?:\s*0*(?:100(?:\.0+)?|\d?\d(?:\.\d+)?)%\s*,){3})|hsla\(\s*0*(?:360|3[0-5]\d|[12]?\d?\d)\s*(?:,\s*0*(?:100(?:\.0+)?|\d?\d(?:\.\d+)?)%\s*){2},)\s*0*(?:1(?:\.0+)?|0(?:\.\d+)?)\s*\)/gi;

Expand All @@ -100,7 +100,7 @@ export const isColor = input => {
return false;
};

export default {
const WTF = {
string: isString,
object: isObject,
date: isDate,
Expand All @@ -114,5 +114,7 @@ export default {
empty: isEmpty,
ISO8601: isISO8601,
color: isColor,
null: isNull
null: isNull,
};

export default WTF;
21 changes: 21 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"declaration": true,
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},

"include": ["**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
Loading

0 comments on commit 493771a

Please sign in to comment.