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
18 changes: 18 additions & 0 deletions types/chromecast-caf-receiver/cast.framework.breaks.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions types/chromecast-caf-receiver/cast.framework.messages.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ 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,
getBreakClipById: () => breakClip,
getBreakClips: () => [breakClip],
getBreaks: () => [adBreak],
getPlayWatchedBreak: () => true,
removeBreakById: () => true,
setBreakClipLoadInterceptor: () => {},
setBreakSeekInterceptor: () => {},
setPlayWatchedBreak: () => {},
Expand Down
5 changes: 5 additions & 0 deletions types/number-abbreviate/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!**/*.d.ts
!**/*.d.cts
!**/*.d.mts
!**/*.d.*.ts
64 changes: 64 additions & 0 deletions types/number-abbreviate/index.d.ts
Original file line number Diff line number Diff line change
@@ -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;
58 changes: 58 additions & 0 deletions types/number-abbreviate/number-abbreviate-tests.ts
Original file line number Diff line number Diff line change
@@ -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);
17 changes: 17 additions & 0 deletions types/number-abbreviate/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
19 changes: 19 additions & 0 deletions types/number-abbreviate/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}