Skip to content

Commit

Permalink
chore: adding TS configs and converting all JS to TS files (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
ftonato authored Mar 4, 2022
1 parent af1cfa5 commit fb9c899
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 37 deletions.
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
111 changes: 107 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
{
"name": "plain-object",
"version": "1.3.0",
"version": "1.4.0",
"description": "Convert nested JSON to simple plain JSON object",
"license": "MIT",
"author": "Ademílson F. Tonato <[email protected]>",
"repository": {
"type": "git",
"url": "git://github.com/ftonato/plain-object.git"
},
"main": "main.js",
"main": "dist/main.js",
"scripts": {
"build": "rollup -c",
"test": "jest"
"build": "rollup -c rollup.config.js",
"test": "jest --no-cache"
},
"engines": {
"node": ">=12"
},
"dependencies": {
"@sindresorhus/is": "^4.6.0"
},
"devDependencies": {
"@rollup/plugin-typescript": "^8.3.1",
"@types/jest": "^27.4.1",
"jest": "^27.5.1",
"rollup": "^2.69.0",
"rollup-plugin-terser": "^7.0.2"
"rollup-plugin-terser": "^7.0.2",
"ts-jest": "^27.1.3",
"tslib": "^2.3.1",
"typescript": "^4.6.2"
},
"keywords": [
"object",
Expand Down
19 changes: 8 additions & 11 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { terser } from "rollup-plugin-terser";
import typescript from "@rollup/plugin-typescript";

export default [
{
input: "index.js",
output: [
{
file: "main.js",
format: "esm",
plugins: [terser()],
},
],
export default {
input: "src/index.ts",
output: {
format: "esm",
file: "dist/main.js",
},
];
plugins: [typescript({ tsconfig: "tsconfig.json" }), terser()],
};
7 changes: 4 additions & 3 deletions test.js → src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const plainObject = require("./index.js");
const {
const plainObject = require("./index.ts");

import {
MOCK,
MOCK_DATE,
MOCK_BIGINT,
MOCK_BUFFER,
MOCK_REGEXP,
MOCK_PROMISE,
} = require("./mock.js");
} from "./mock";

describe("[plain-object pkg] plainObject method", () => {
it("plain object using [string]", () => {
Expand Down
16 changes: 10 additions & 6 deletions index.js → src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
const is = require("@sindresorhus/is");

function isValidNumber(value) {
return is.number(value) && !isNaN(value);
interface GenericObject {
[key: string]: any;
}

function isValidObject(value) {
function isValidNumber(value: GenericObject): boolean {
return is.number(value) && !isNaN(+value);
}

function isValidObject(value: GenericObject): boolean {
return is.object(value) && !is.null(value);
}

function plainObject(obj, response = {}) {
for (let key in obj) {
const value = obj[key];
function plainObject(data: any, response: GenericObject = {}): GenericObject {
for (let key in data) {
const value = data[key];
const type = typeof value;

if (
Expand Down
9 changes: 1 addition & 8 deletions mock.js → src/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,4 @@ const MOCK = {
},
};

module.exports = {
MOCK,
MOCK_DATE,
MOCK_BIGINT,
MOCK_BUFFER,
MOCK_REGEXP,
MOCK_PROMISE,
};
export { MOCK, MOCK_DATE, MOCK_BIGINT, MOCK_BUFFER, MOCK_REGEXP, MOCK_PROMISE };
11 changes: 11 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es5",
"rootDir": "src",
"moduleResolution": "node",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitAny": false
}
}

0 comments on commit fb9c899

Please sign in to comment.