Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/predicate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from './isBigIntArray.js';
export * from './isBinaryNumberString.js';
export * from './isBoolean.js';
export * from './isBooleanArray.js';
export * from './isDateString.js';
export * from './isDigitsString.js';
export * from './isFiniteNumber.js';
export * from './isFunction.js';
Expand All @@ -28,6 +29,7 @@ export * from './isNumericString.js';
export * from './isNumericValue.js';
export * from './isNumericValueArray.js';
export * from './isObject.js';
export * from './isObjectLiteral.js';
export * from './isObjectWith.js';
export * from './isOctalNumberString.js';
export * from './isOptionalArray.js';
Expand Down
7 changes: 7 additions & 0 deletions src/predicate/isDateString.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { TypePredicateFn } from '../types/functions.js';

/**
* Determine if `input` is a valid date string.
*/
export const isDateString: TypePredicateFn<string> = (input: unknown): input is string =>
typeof input === 'string' && !Number.isNaN(new Date(input).getTime());
7 changes: 7 additions & 0 deletions src/predicate/isObjectLiteral.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { UnknownRecord } from '../types/records.js';

/**
* Determine if `input` is an object literal.
*/
export const isObjectLiteral = (input: unknown): input is UnknownRecord =>
input !== null && typeof input === 'object' && Object.getPrototypeOf(input) === Object.prototype;
19 changes: 19 additions & 0 deletions test/predicate/isDateString.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { describe, it, expect } from 'vitest';

import { isDateString } from '../../src/predicate/isDateString.js';

describe('isDateString()', () => {
it.each([
new Date().toISOString(),
new Date().toLocaleDateString('en-US'),
new Date().toLocaleString(),
new Date().toUTCString(),
new Date().toString(),
])('Returns true for valid input: %j', (input) => {
expect(isDateString(input)).toBeTruthy();
});

it.each([Date.now(), 'bad input', true, null, {}, undefined])('Returns false for invalid input: %j', (input) => {
expect(isDateString(input)).toBeFalsy();
});
});
20 changes: 20 additions & 0 deletions test/predicate/isObjectLiteral.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { describe, it, expect } from 'vitest';

import { isObjectLiteral } from '../../src/predicate/isObjectLiteral.js';

describe('isObjectLiteral()', () => {
it('Returns true for valid input', () => {
expect(
isObjectLiteral({
test: true,
}),
).toBeTruthy();
});

it.each([Object.create(null), new Date(), globalThis, 1, 'a', true, null, undefined])(
'Returns false for invalid input: %j',
(input) => {
expect(isObjectLiteral(input)).toBeFalsy();
},
);
});