feat: add native hls media + refactor (#1154)

This commit is contained in:
Wesley Luyten
2026-03-30 20:13:19 -05:00
committed by GitHub
parent 0433722ee4
commit 1b2afc6e41
24 changed files with 552 additions and 200 deletions
+1
View File
@@ -1,2 +1,3 @@
export { defaults } from './defaults';
export { pick } from './pick';
export { shallowEqual } from './shallow-equal';
@@ -0,0 +1,22 @@
const hasOwn = Object.prototype.hasOwnProperty;
export function shallowEqual<T>(a: T, b: T): boolean {
if (Object.is(a, b)) return true;
if (typeof a !== 'object' || a === null || typeof b !== 'object' || b === null) {
return false;
}
const keysA = Object.keys(a);
const keysB = Object.keys(b);
if (keysA.length !== keysB.length) return false;
for (const key of keysA) {
if (!hasOwn.call(b, key) || !Object.is((a as Record<string, unknown>)[key], (b as Record<string, unknown>)[key])) {
return false;
}
}
return true;
}
@@ -0,0 +1,66 @@
import { describe, expect, it } from 'vitest';
import { shallowEqual } from '../shallow-equal';
describe('shallowEqual', () => {
it('returns true for identical primitives', () => {
expect(shallowEqual(1, 1)).toBe(true);
expect(shallowEqual('a', 'a')).toBe(true);
expect(shallowEqual(true, true)).toBe(true);
expect(shallowEqual(null, null)).toBe(true);
expect(shallowEqual(undefined, undefined)).toBe(true);
});
it('returns false for different primitives', () => {
expect(shallowEqual(1, 2)).toBe(false);
expect(shallowEqual('a', 'b')).toBe(false);
expect(shallowEqual(true, false)).toBe(false);
expect(shallowEqual(null, undefined)).toBe(false);
});
it('returns true for same reference', () => {
const obj = { a: 1 };
expect(shallowEqual(obj, obj)).toBe(true);
});
it('returns true for objects with same keys and values', () => {
expect(shallowEqual({ a: 1, b: 2 }, { a: 1, b: 2 })).toBe(true);
});
it('returns false for objects with different values', () => {
expect(shallowEqual({ a: 1 }, { a: 2 })).toBe(false);
});
it('returns false for objects with different keys', () => {
expect(shallowEqual({ a: 1 }, { b: 1 })).toBe(false);
expect(shallowEqual({ a: 1 }, { a: 1, b: 2 })).toBe(false);
});
it('returns false for nested objects with different references', () => {
expect(shallowEqual({ a: { b: 1 } }, { a: { b: 1 } })).toBe(false);
});
it('returns true for nested objects with same reference', () => {
const nested = { b: 1 };
expect(shallowEqual({ a: nested }, { a: nested })).toBe(true);
});
it('handles NaN correctly', () => {
expect(shallowEqual(NaN, NaN)).toBe(true);
expect(shallowEqual({ a: NaN }, { a: NaN })).toBe(true);
});
it('handles +0 and -0', () => {
expect(shallowEqual(0, -0)).toBe(false);
expect(shallowEqual({ a: 0 }, { a: -0 })).toBe(false);
});
it('returns false when comparing object to null', () => {
expect(shallowEqual({ a: 1 }, null)).toBe(false);
expect(shallowEqual(null, { a: 1 })).toBe(false);
});
it('returns false when comparing object to primitive', () => {
expect(shallowEqual({ a: 1 }, 1 as any)).toBe(false);
expect(shallowEqual(1 as any, { a: 1 })).toBe(false);
});
});