Skip to content

Commit

Permalink
feat: porting the library over from @readme/oas-to-har
Browse files Browse the repository at this point in the history
  • Loading branch information
erunion committed Feb 10, 2022
0 parents commit 7001f22
Show file tree
Hide file tree
Showing 14 changed files with 14,252 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@types/
coverage/
dist/
10 changes: 10 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": [
"@readme/eslint-config",
"@readme/eslint-config/typescript"
],
"root": true,
"rules": {
"@typescript-eslint/no-explicit-any": "off"
}
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@types/
coverage/
dist/
node_modules/
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx commitlint --edit $1
7 changes: 7 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
__tests__/
.github/
.husky/
coverage/
.eslint*
.prettier*
jest.*.js
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@types/
coverage/
dist/
3 changes: 3 additions & 0 deletions __tests__/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@readme/eslint-config/testing"
}
65 changes: 65 additions & 0 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import removeUndefinedObjects from '../src';

test('should leave primitives alone', () => {
expect(removeUndefinedObjects(1234)).toBe(1234);
expect(removeUndefinedObjects('1234')).toBe('1234');
expect(removeUndefinedObjects(null)).toBeNull();
expect(removeUndefinedObjects()).toBeUndefined();
expect(removeUndefinedObjects(undefined)).toBeUndefined();
});

test('should remove empty objects with only empty properties', () => {
const obj = {
a: {
b: {},
c: {
d: {},
},
},
};

expect(removeUndefinedObjects(obj)).toBeUndefined();
});

test('should remove empty objects with only undefined properties', () => {
const obj = {
a: {
b: undefined,
c: {
d: undefined,
},
},
};

expect(removeUndefinedObjects(obj)).toBeUndefined();
});

test('should remove empty arrays from within object', () => {
const obj = {
a: {
b: undefined,
c: {
d: undefined,
},
},
d: [1234, undefined],
e: [],
};

expect(removeUndefinedObjects(obj)).toStrictEqual({
d: [1234],
});
});

test('should remove undefined and null values from arrays', () => {
expect(removeUndefinedObjects([undefined, undefined])).toBeUndefined();
expect(removeUndefinedObjects([null])).toBeUndefined();
expect(removeUndefinedObjects(['1234', null, undefined, { a: null, b: undefined }, ' ', ''])).toStrictEqual([
'1234',
{
a: null,
},
' ',
'',
]);
});
9 changes: 9 additions & 0 deletions __tests__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"module": "es6",
"moduleResolution": "node",
"noImplicitAny": false
},
"include": ["../src/**/*", "*.ts"]
}
13 changes: 13 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
coveragePathIgnorePatterns: ['/dist', '/node_modules'],
globals: {
'ts-jest': {
tsconfig: '__tests__/tsconfig.json',
},
},
modulePaths: ['<rootDir>'],
preset: 'ts-jest/presets/js-with-ts',
roots: ['<rootDir>'],
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(js?|ts?)$',
transform: {},
};
Loading

0 comments on commit 7001f22

Please sign in to comment.