diff --git a/types/chromecast-caf-receiver/cast.framework.breaks.d.ts b/types/chromecast-caf-receiver/cast.framework.breaks.d.ts index 39e73dfe25ad19..fa11f27d916cd7 100644 --- a/types/chromecast-caf-receiver/cast.framework.breaks.d.ts +++ b/types/chromecast-caf-receiver/cast.framework.breaks.d.ts @@ -43,6 +43,18 @@ export class BreakClipLoadInterceptorContext { * @see https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.breaks.BreakManager */ export interface BreakManager { + /** + * Adds dynamic break and break clips. The break clips will be associated with the break + * ({@link Break.breakClipIds} and {@link Break.duration} will be updated according to the clips). + * @param breakData The {@link Break} object to be added. + * @param breakClips Array of non-null {@link BreakClip} objects. + * @param broadCastMediaStatus Whether CAF should check if the current break status has changed. + * This may not be desirable before playback begins, as the receiver may still need to add + * more breaks (e.g., during load complete). + * @returns `true` if break was added successfully. + */ + addBreak(breakData: Break, breakClips: BreakClip[], broadCastMediaStatus?: boolean): boolean; + /** * Get current media break by id. */ @@ -74,6 +86,12 @@ export interface BreakManager { /** Returns true if watched breaks should be played. */ getPlayWatchedBreak(): boolean; + /** + * Removes a break and associated break clips. + * @returns `true` if break was removed successfully. + */ + removeBreakById(breakId: string): boolean; + /** * Provide an interceptor to allow developer to insert more break clips or * modify current break clip before a break is started. diff --git a/types/chromecast-caf-receiver/cast.framework.messages.d.ts b/types/chromecast-caf-receiver/cast.framework.messages.d.ts index 6f5cf7c3bbd53a..bd360fdc146f41 100644 --- a/types/chromecast-caf-receiver/cast.framework.messages.d.ts +++ b/types/chromecast-caf-receiver/cast.framework.messages.d.ts @@ -2556,6 +2556,12 @@ export class Break { * Duration of break in sec. */ duration?: number | undefined; + /** + * Indicates whether the break is expanded on the timeline. The duration of expanded + * breaks is included in the total playback duration. A value of `true` indicates + * that the break is expanded. When omitted, the value is assumed to be `false`. + */ + expanded?: boolean; /** * Unique id of break. */ diff --git a/types/chromecast-caf-receiver/chromecast-caf-receiver-tests.ts b/types/chromecast-caf-receiver/chromecast-caf-receiver-tests.ts index 70ac60f31c55c3..68bba3a93f0c15 100644 --- a/types/chromecast-caf-receiver/chromecast-caf-receiver-tests.ts +++ b/types/chromecast-caf-receiver/chromecast-caf-receiver-tests.ts @@ -60,6 +60,7 @@ const items = qBase.fetchItems(1, 3, 4); const breakSeekData = new cast.framework.breaks.BreakSeekData(0, 100, []); const breakClipLoadContext = new cast.framework.breaks.BreakClipLoadInterceptorContext(adBreak); const breakManager: BreakManager = { + addBreak: () => true, getBreakById: () => adBreak, getBreakClipCurrentTimeSec: () => null, getBreakClipDurationSec: () => null, @@ -67,6 +68,7 @@ const breakManager: BreakManager = { getBreakClips: () => [breakClip], getBreaks: () => [adBreak], getPlayWatchedBreak: () => true, + removeBreakById: () => true, setBreakClipLoadInterceptor: () => {}, setBreakSeekInterceptor: () => {}, setPlayWatchedBreak: () => {}, diff --git a/types/number-abbreviate/.npmignore b/types/number-abbreviate/.npmignore new file mode 100644 index 00000000000000..93e307400a5456 --- /dev/null +++ b/types/number-abbreviate/.npmignore @@ -0,0 +1,5 @@ +* +!**/*.d.ts +!**/*.d.cts +!**/*.d.mts +!**/*.d.*.ts diff --git a/types/number-abbreviate/index.d.ts b/types/number-abbreviate/index.d.ts new file mode 100644 index 00000000000000..4cdb19a8564019 --- /dev/null +++ b/types/number-abbreviate/index.d.ts @@ -0,0 +1,64 @@ +/** + * Represents an instance of the NumberAbbreviate abbreviator. + * Created by `new NumberAbbreviate(units)` or internally by the direct function call. + */ +interface AbbreviatorInstance { + /** + * Units used in the abbreviations + * + * @default ['k', 'm', 'b', 't'] + */ + units: string[]; + /** + * Abbreviates a number into a more readable format (e.g., 1000000 -> 1M). + * + * @param value number to be abbreviated. Non-numeric strings will result in `NaN` + * @param decimalPlaces number of decimal places to include (default: 0). + * @returns the abbreviated string or `NaN` + */ + abbreviate(value: number | string, decimalPlaces?: number): string; + /** + * Internal helper function for the abbreviation logic. + * + * @internal + * @param number number to be abbreviated + * @param decPlaces number of decimal places to include. + * @returns the abbreviated string fragment without sign. + */ + _abbreviate(number: number, decPlaces: number): string; +} + +/** + * A utility for abbreviating numbers into more readable formats (e.g., 1000000 becomes 1m). + * Can be used as a direct function call for quick abbreviation or instantiated + * as a class for custom unit configurations. + * + * @example + * // Direct function call: + * import abbreviate from "number-abbreviate"; + * console.log(abbreviate(1234567, 1)); // Outputs: "1.2m" + * + * @example + * // Using as a constructor for custom units: + * import NumberAbbreviateClass from "number-abbreviate"; + * const customAbbrev = new NumberAbbreviateClass(['k', 'M', 'B', 'T']); + * console.log(customAbbrev.abbreviate(5000000000, 2)); // Outputs: "5.00B" + */ +interface NumberAbbreviateFunction { + /** + * Creates a new instance of the NumberAbbreviate utility with custom unit abbreviations. + * @param units Optional. An array of custom unit strings (default: ['k', 'm', 'b', 't']). + */ + new(units?: string[]): AbbreviatorInstance; + /** + * Abbreviates a number into a more readable format. + * @param value number or string to abbreviate. Non-numeric strings will result in `NaN` + * @param decimalPlaces number of decimal places to include (default: `0`). + * @param units an array of custom unit strings for this specific call, used in order. (default: `['k', 'm', 'b', 't']`) + * @returns the abbreviated string or `NaN` + */ + (value: number | string, decimalPlaces?: number, units?: string[]): string; +} + +declare const NumberAbbreviate: NumberAbbreviateFunction; // <--- CHANGE HERE: Added 'declare' +export = NumberAbbreviate; diff --git a/types/number-abbreviate/number-abbreviate-tests.ts b/types/number-abbreviate/number-abbreviate-tests.ts new file mode 100644 index 00000000000000..eab06ff46acb1b --- /dev/null +++ b/types/number-abbreviate/number-abbreviate-tests.ts @@ -0,0 +1,58 @@ +import NumberAbbreviate from "number-abbreviate"; + +const num: number = 12345; +const strNum: string = "98765"; +const nonNumericStr: string = "hello"; + +// Test the direct function call (shorthand mode) +const res1: string = NumberAbbreviate(1000); +const res2: string = NumberAbbreviate(1111, 0); +const res3: string = NumberAbbreviate(1111, 1); +const res4: string = NumberAbbreviate(1111, 2); +const res5: string = NumberAbbreviate(num); +const res6: string = NumberAbbreviate(strNum, 1); +const res7: string = NumberAbbreviate(-12345); +const res8: string = NumberAbbreviate(123456789, 2, ["k", "M", "B"]); + +// @ts-expect-error +NumberAbbreviate("invalid", true, ["a"]); + +// Test the class/constructor mode +const numAbbr1 = new NumberAbbreviate(); +const res9: string = numAbbr1.abbreviate(12, 1); +const res10: string = numAbbr1.abbreviate(0, 2); +const res11: string = numAbbr1.abbreviate(1234, 0); +const res12: string = numAbbr1.abbreviate(34567, 2); +const res13: string = numAbbr1.abbreviate(918395, 1); +const res14: string = numAbbr1.abbreviate(2134124, 2); +const res15: string = numAbbr1.abbreviate(47475782130, 2); +const res16: string = numAbbr1.abbreviate(-1234, 0); +const res17: string = numAbbr1.abbreviate(-918395, 1); +const res18: string = numAbbr1.abbreviate(-47475782130, 2); +const res19: string = numAbbr1.abbreviate(num, 0); +const res20: string = numAbbr1.abbreviate(strNum); + +// @ts-expect-error +numAbbr1.abbreviate("invalid", true); + +// Test constructor with custom units +const customUnits = ["A", "B", "C"]; +const numAbbr2 = new NumberAbbreviate(customUnits); +const res21: string = numAbbr2.abbreviate(1000, 0); +const res22: string = numAbbr2.abbreviate(1000000, 1); +const res23: string = numAbbr2.abbreviate(1000000000, 2); +const res24: string = numAbbr2.abbreviate(num, 1); +const res25: string = numAbbr2.abbreviate(strNum, 2); + +// Test instance properties +const unitsProp1: string[] = numAbbr1.units; +const unitsProp2: string[] = numAbbr2.units; + +// Verify `_abbreviate` type (internal, but we typed it) +const internalAbbrResult: string = numAbbr1._abbreviate(12345, 0); +// @ts-expect-error +numAbbr1._abbreviate(123, "not_a_number"); + +// Test handling of non-numeric strings resulting in NaN (runtime) +const nanResult1: string = NumberAbbreviate(nonNumericStr); +const nanResult2: string = numAbbr1.abbreviate(nonNumericStr); diff --git a/types/number-abbreviate/package.json b/types/number-abbreviate/package.json new file mode 100644 index 00000000000000..fe1bb03ea80d31 --- /dev/null +++ b/types/number-abbreviate/package.json @@ -0,0 +1,17 @@ +{ + "private": true, + "name": "@types/number-abbreviate", + "version": "2.0.9999", + "projects": [ + "https://github.com/domharrington/js-number-abbreviate#readme" + ], + "devDependencies": { + "@types/number-abbreviate": "workspace:." + }, + "owners": [ + { + "name": "Alton Rose", + "githubUsername": "altie122" + } + ] +} diff --git a/types/number-abbreviate/tsconfig.json b/types/number-abbreviate/tsconfig.json new file mode 100644 index 00000000000000..6d020863f52d15 --- /dev/null +++ b/types/number-abbreviate/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "node16", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "number-abbreviate-tests.ts" + ] +}