Skip to content

Commit

Permalink
Merge pull request #16 from tewen/import-defect
Browse files Browse the repository at this point in the history
Fixed import related issues breaking build.
  • Loading branch information
tewen committed Jul 26, 2021
2 parents ab9e4a2 + 1976cba commit 0aed7cf
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 22 deletions.
17 changes: 15 additions & 2 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions src/__tests__/function.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Mock = jest.Mock;

const { acceptNoArguments, functionOrValue, tryCatch } = require('../');
import { acceptNoArguments, functionOrValue, tryCatch } from '../';

describe('function', () => {
describe('acceptNoArguments()', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/internal.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/json.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { isJsonString, safeJsonParse } = require('../');
import { isJsonString, safeJsonParse } from '../';

describe('json', () => {
describe('isJsonString()', () => {
Expand Down
9 changes: 8 additions & 1 deletion src/__tests__/object.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { isObject, isEmpty, merge, flattenObject } = require('../');
import { isObject, isEmpty, merge, flattenObject } from '../';

describe('object', () => {
describe('isObject()', () => {
Expand Down Expand Up @@ -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');
});

Expand Down Expand Up @@ -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({});
});

Expand All @@ -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({});
});

Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/stream.test.ts
Original file line number Diff line number Diff line change
@@ -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()', () => {
Expand Down
4 changes: 3 additions & 1 deletion src/__tests__/string.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { stringToBoolean, escapeForRegExp } = require('../');
import { stringToBoolean, escapeForRegExp } from '../';

describe('string', () => {
describe('stringToBoolean()', () => {
Expand Down Expand Up @@ -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();
});

Expand Down
9 changes: 5 additions & 4 deletions src/csv.ts
Original file line number Diff line number Diff line change
@@ -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 = <T extends object>(
acc: T,
Expand Down Expand Up @@ -147,6 +147,7 @@ function flattenToCsvFormat(
if (isObject(obj)) {
return reduceObjectOrArray(
obj,
// @ts-ignore
(acc: Record<string, any>, v, k) => {
const isArray = Array.isArray(v);
const key = chooseKey({
Expand Down
4 changes: 2 additions & 2 deletions src/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
}
2 changes: 1 addition & 1 deletion src/internal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function getValue(
obj: Record<string, any>,
keyPath: string,
defaultValue: any
defaultValue?: any
): unknown {
const split = keyPath
.trim()
Expand Down
4 changes: 2 additions & 2 deletions src/json.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { isObject } from './object';

export function isJsonString(str: string): boolean {
export function isJsonString(str: any): boolean {
try {
return isObject(JSON.parse(str));
} catch (e) {
return false;
}
}

export function safeJsonParse(obj: string): object | null {
export function safeJsonParse(obj: any): object | null {
if (obj && typeof obj === 'string') {
try {
return JSON.parse(obj);
Expand Down
2 changes: 1 addition & 1 deletion src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<string, any>> {
return new Promise((resolve, reject) => {
let response = '';
Expand Down

0 comments on commit 0aed7cf

Please sign in to comment.