diff --git a/package-lock.json b/package-lock.json index 4ca14f2..f2cae5c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "deep-cuts", - "version": "2.1.0", + "version": "2.1.1", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "2.1.0", + "version": "2.1.1", "license": "MIT", "dependencies": { "qs": "^6.5.2" @@ -13,6 +13,7 @@ "devDependencies": { "@size-limit/preset-small-lib": "^5.0.1", "@types/jest": "^25.2.3", + "@types/qs": "^6.9.7", "data-mining-tools": "^1.1.1", "husky": "^7.0.1", "size-limit": "^5.0.1", @@ -2280,6 +2281,12 @@ "@types/node": "*" } }, + "node_modules/@types/qs": { + "version": "6.9.7", + "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz", + "integrity": "sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==", + "dev": true + }, "node_modules/@types/resolve": { "version": "1.17.1", "integrity": "sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw==", @@ -15729,6 +15736,12 @@ "@types/node": "*" } }, + "@types/qs": { + "version": "6.9.7", + "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz", + "integrity": "sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==", + "dev": true + }, "@types/resolve": { "version": "1.17.1", "integrity": "sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw==", diff --git a/package.json b/package.json index 639b7ad..acda990 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "deep-cuts", - "version": "2.1.0", + "version": "2.1.1", "description": "Useful utilities and rare b-sides.", "author": "Trevor Ewen", "license": "MIT", @@ -61,6 +61,7 @@ "devDependencies": { "@size-limit/preset-small-lib": "^5.0.1", "@types/jest": "^25.2.3", + "@types/qs": "^6.9.7", "data-mining-tools": "^1.1.1", "husky": "^7.0.1", "size-limit": "^5.0.1", diff --git a/src/__tests__/function.test.ts b/src/__tests__/function.test.ts index c4be88d..4331c62 100644 --- a/src/__tests__/function.test.ts +++ b/src/__tests__/function.test.ts @@ -1,6 +1,5 @@ import Mock = jest.Mock; - -const { acceptNoArguments, functionOrValue, tryCatch } = require('../'); +import { acceptNoArguments, functionOrValue, tryCatch } from '../'; describe('function', () => { describe('acceptNoArguments()', () => { diff --git a/src/__tests__/internal.test.ts b/src/__tests__/internal.test.ts index e6b057e..c4134b7 100644 --- a/src/__tests__/internal.test.ts +++ b/src/__tests__/internal.test.ts @@ -1,8 +1,9 @@ -const { getValue, setValue } = require('../internal'); +import { getValue, setValue } from '../internal'; describe('internal', () => { describe('getValue()', () => { it('should return the default value if passed a nil primitive', () => { + // @ts-ignore expect(getValue(null, 'name', 'Steve')).toEqual('Steve'); }); diff --git a/src/__tests__/json.test.ts b/src/__tests__/json.test.ts index e4f2a34..a51d8f9 100644 --- a/src/__tests__/json.test.ts +++ b/src/__tests__/json.test.ts @@ -1,4 +1,4 @@ -const { isJsonString, safeJsonParse } = require('../'); +import { isJsonString, safeJsonParse } from '../'; describe('json', () => { describe('isJsonString()', () => { diff --git a/src/__tests__/object.test.ts b/src/__tests__/object.test.ts index 2d6c25f..6cb6f7b 100644 --- a/src/__tests__/object.test.ts +++ b/src/__tests__/object.test.ts @@ -1,4 +1,4 @@ -const { isObject, isEmpty, merge, flattenObject } = require('../'); +import { isObject, isEmpty, merge, flattenObject } from '../'; describe('object', () => { describe('isObject()', () => { @@ -95,18 +95,22 @@ describe('object', () => { describe('flattenObject()', () => { it('should return undefined if passed undefined', () => { + // @ts-ignore expect(flattenObject(undefined)).toBeUndefined(); }); it('should return null if passed null', () => { + // @ts-ignore expect(flattenObject(null)).toBeNull(); }); it('should return a number if passed a number', () => { + // @ts-ignore expect(flattenObject(55.5)).toEqual(55.5); }); it('should return a string if passed a string', () => { + // @ts-ignore expect(flattenObject('Koolaid City')).toEqual('Koolaid City'); }); @@ -227,10 +231,12 @@ describe('object', () => { }); it('should return an object if passed undefined', () => { + // @ts-ignore expect(merge(undefined)).toEqual({}); }); it('should return an object if passed null', () => { + // @ts-ignore expect(merge(null)).toEqual({}); }); @@ -239,6 +245,7 @@ describe('object', () => { }); it('should return an object if passed a set of empty objects, null, and undefined', () => { + // @ts-ignore expect(merge({}, null, {}, undefined, {})).toEqual({}); }); diff --git a/src/__tests__/stream.test.ts b/src/__tests__/stream.test.ts index e8c0a8b..6b4920e 100644 --- a/src/__tests__/stream.test.ts +++ b/src/__tests__/stream.test.ts @@ -1,6 +1,6 @@ -const fs = require('fs'); -const path = require('path'); -const { jsonStreamToObject } = require('../'); +import fs from 'fs'; +import path from 'path'; +import { jsonStreamToObject } from '../'; describe('stream', () => { describe('jsonStreamToObject()', () => { diff --git a/src/__tests__/string.test.ts b/src/__tests__/string.test.ts index de03022..495a623 100644 --- a/src/__tests__/string.test.ts +++ b/src/__tests__/string.test.ts @@ -1,4 +1,4 @@ -const { stringToBoolean, escapeForRegExp } = require('../'); +import { stringToBoolean, escapeForRegExp } from '../'; describe('string', () => { describe('stringToBoolean()', () => { @@ -57,10 +57,12 @@ describe('string', () => { describe('escapeForRegExp()', () => { it('should return undefined if passed undefined', () => { + // @ts-ignore expect(escapeForRegExp(undefined)).toBeUndefined(); }); it('should return null if passed null', () => { + // @ts-ignore expect(escapeForRegExp(null)).toBeNull(); }); diff --git a/src/csv.ts b/src/csv.ts index 4bd00f9..f930d37 100644 --- a/src/csv.ts +++ b/src/csv.ts @@ -1,7 +1,7 @@ -const qs = require('qs'); -const { safeJsonParse } = require('./json'); -const { isObject, isEmpty, merge } = require('./object'); -const { getValue, setValue } = require('./internal'); +import qs from 'qs'; +import { isObject, isEmpty, merge } from './object'; +import { safeJsonParse } from './json'; +import { getValue, setValue } from './internal'; type ReduceCallback = ( acc: T, @@ -147,6 +147,7 @@ function flattenToCsvFormat( if (isObject(obj)) { return reduceObjectOrArray( obj, + // @ts-ignore (acc: Record, v, k) => { const isArray = Array.isArray(v); const key = chooseKey({ diff --git a/src/function.ts b/src/function.ts index 933986a..d25dcdb 100644 --- a/src/function.ts +++ b/src/function.ts @@ -13,11 +13,11 @@ export function functionOrValue(fnOrValue: any, ...args: any[]): unknown { export async function tryCatch( tryFn: Function, - catchFn: Function + catchFn?: Function ): Promise<{ response?: unknown; error?: unknown }> { try { return { response: await tryFn() }; } catch (e) { - return { error: isFunction(catchFn) ? await catchFn(e) : e }; + return { error: catchFn && isFunction(catchFn) ? await catchFn(e) : e }; } } diff --git a/src/internal.ts b/src/internal.ts index 8aab7f7..6cd3bc2 100644 --- a/src/internal.ts +++ b/src/internal.ts @@ -1,7 +1,7 @@ export function getValue( obj: Record, keyPath: string, - defaultValue: any + defaultValue?: any ): unknown { const split = keyPath .trim() diff --git a/src/json.ts b/src/json.ts index a9a67fd..8a894e2 100644 --- a/src/json.ts +++ b/src/json.ts @@ -1,6 +1,6 @@ import { isObject } from './object'; -export function isJsonString(str: string): boolean { +export function isJsonString(str: any): boolean { try { return isObject(JSON.parse(str)); } catch (e) { @@ -8,7 +8,7 @@ export function isJsonString(str: string): boolean { } } -export function safeJsonParse(obj: string): object | null { +export function safeJsonParse(obj: any): object | null { if (obj && typeof obj === 'string') { try { return JSON.parse(obj); diff --git a/src/stream.ts b/src/stream.ts index 7410cd2..65202ae 100644 --- a/src/stream.ts +++ b/src/stream.ts @@ -2,7 +2,7 @@ * @deprecated For stream functions, please switch to https://www.npmjs.com/package/tranquil-stream */ export async function jsonStreamToObject( - stream: NodeJS.ReadWriteStream + stream: NodeJS.ReadWriteStream | NodeJS.ReadableStream ): Promise> { return new Promise((resolve, reject) => { let response = '';