repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
feeddeck
github_2023
feeddeck
typescript
caller
function caller(this: Bind | any, levelUp = up) { const err = new Error(); const stack = err.stack?.split('\n')[levelUp]; if (stack) { return getFile.bind(this)(stack); } }
// deno-lint-ignore no-explicit-any
https://github.com/feeddeck/feeddeck/blob/50ad24a7bc8d4f9ae06edbe38f14da057d686bae/supabase/functions/_shared/utils/log.ts#L73-L79
50ad24a7bc8d4f9ae06edbe38f14da057d686bae
feeddeck
github_2023
feeddeck
typescript
getFile
function getFile(this: Bind | any, stack: string) { stack = stack.substring(stack.indexOf('at ') + 3); if (!stack.startsWith('file://')) { stack = stack.substring(stack.lastIndexOf('(') + 1); } const path = stack.split(':'); let file; if (Deno.build.os == 'windows') { file = `${path[0]}:${path[1]}:$...
// deno-lint-ignore no-explicit-any
https://github.com/feeddeck/feeddeck/blob/50ad24a7bc8d4f9ae06edbe38f14da057d686bae/supabase/functions/_shared/utils/log.ts#L82-L101
50ad24a7bc8d4f9ae06edbe38f14da057d686bae
feeddeck
github_2023
feeddeck
typescript
getProfile
const getProfile = async ( supabaseClient: SupabaseClient, user: User, ): Promise<Response> => { const { data: profile, error: profileError } = await supabaseClient .from( 'profiles', ) .select('*').eq( 'id', user.id, ); if (profileError || profile?.length !== 1) { log('err...
/** * `getProfile` returns the users profile. The user profile contains information * about the users subscription and the connected accounts. * * ATTENTION: We should never return the users account token. Instead we should * return a boolean if the user has connected an account or not. */
https://github.com/feeddeck/feeddeck/blob/50ad24a7bc8d4f9ae06edbe38f14da057d686bae/supabase/functions/profile-v2/index.ts#L20-L68
50ad24a7bc8d4f9ae06edbe38f14da057d686bae
feeddeck
github_2023
feeddeck
typescript
isAuthorized
const isAuthorized = (req: Request): boolean => { const authorizationHeader = req.headers.get('Authorization'); if (!authorizationHeader || !authorizationHeader.startsWith('Bearer ')) { return false; } const authToken = authorizationHeader.split('Bearer ')[1]; if (authToken !== FEEDDECK_REVENUECAT_WEBHO...
/** * `isAuthorized` checks if the request is authorized. This is done by checking * the authorization header of the request, which must match the configured * header in RevenueCat. */
https://github.com/feeddeck/feeddeck/blob/50ad24a7bc8d4f9ae06edbe38f14da057d686bae/supabase/functions/revenuecat-webhooks-v1/index.ts#L31-L44
50ad24a7bc8d4f9ae06edbe38f14da057d686bae
zotero-addons
github_2023
syt2
typescript
AddonInfoDetail.close
static async close() { this.window?.close(); }
/** * Close detail window */
https://github.com/syt2/zotero-addons/blob/1be0adb1ec53194a132722873de55d395bb2465c/src/modules/addonDetail.ts#L18-L20
1be0adb1ec53194a132722873de55d395bb2465c
zotero-addons
github_2023
syt2
typescript
AddonInfoDetail.showDetailWindow
static async showDetailWindow(addonInfo: AddonInfo) { this.window?.close(); this.addonInfo = addonInfo; const windowArgs = { _initPromise: Zotero.Promise.defer() }; const win = Zotero.getMainWindow().openDialog( `chrome://${config.addonRef}/content/addonDetail.xhtml`, `${config.addonRef}-add...
/** * Show detail window for specific AddonInfo * @param addonInfo AddonInfo specified */
https://github.com/syt2/zotero-addons/blob/1be0adb1ec53194a132722873de55d395bb2465c/src/modules/addonDetail.ts#L26-L111
1be0adb1ec53194a132722873de55d395bb2465c
zotero-addons
github_2023
syt2
typescript
AddonInfoDetail.refresh
static async refresh() { const win = this.window; const addonInfo = this.addonInfo; if (!win || !addonInfo || !isWindowAlive(win)) { return; } const releaseInfo = addonReleaseInfo(addonInfo); const tagName = releaseInfo?.tagName; const version = releaseInfo?.xpiVersion; const releaseTime = a...
/** * Refresh shown detail window if need */
https://github.com/syt2/zotero-addons/blob/1be0adb1ec53194a132722873de55d395bb2465c/src/modules/addonDetail.ts#L172-L260
1be0adb1ec53194a132722873de55d395bb2465c
zotero-addons
github_2023
syt2
typescript
AddonInfoAPI.fetchAddonInfos
static async fetchAddonInfos(url: string, timeout?: number, onTimeoutCallback?: VoidFunction): Promise<AddonInfo[]> { ztoolkit.log(`fetch addon infos from ${url}`); try { const options: { timeout?: number } = {}; if (timeout) { options.timeout = timeout; } const response = await ...
/** * Fetch AddonInfo from url * @param url url to fetch AddonInfo JSON * @param timeout set timeout if specified * @param onTimeoutCallback timeout callback if specified timeout * @returns AddonInfo[] */
https://github.com/syt2/zotero-addons/blob/1be0adb1ec53194a132722873de55d395bb2465c/src/modules/addonInfo.ts#L265-L285
1be0adb1ec53194a132722873de55d395bb2465c
zotero-addons
github_2023
syt2
typescript
AddonInfoManager.addonInfos
get addonInfos() { const url = currentSource().api; if (!url) { return []; } if (url in this.sourceInfos && (new Date().getTime() - this.sourceInfos[url][0].getTime()) < 12 * 60 * 60 * 1000) { return this.sourceInfos[url][1]; } return []; }
/** * Get AddonInfos from memory */
https://github.com/syt2/zotero-addons/blob/1be0adb1ec53194a132722873de55d395bb2465c/src/modules/addonInfo.ts#L298-L305
1be0adb1ec53194a132722873de55d395bb2465c
zotero-addons
github_2023
syt2
typescript
AddonInfoManager.fetchAddonInfos
async fetchAddonInfos(forceRefresh = false) { const source = currentSource(); if (source.id === "source-auto" && !source.api) { return await AddonInfoManager.autoSwitchAvaliableApi(); } const url = source.api; if (!url) { return []; } // 不在刷新,且不需要强制刷新 if (!forceRefresh && this.addonInf...
/** * Fetch AddonInfos from current selected source * @param forceRefresh force fetch * @returns AddonInfo[] */
https://github.com/syt2/zotero-addons/blob/1be0adb1ec53194a132722873de55d395bb2465c/src/modules/addonInfo.ts#L313-L329
1be0adb1ec53194a132722873de55d395bb2465c
zotero-addons
github_2023
syt2
typescript
AddonInfoManager.autoSwitchAvaliableApi
static async autoSwitchAvaliableApi(timeout = 3000) { interface ApiResult { source: Source & { api: string }; infos: AddonInfo[]; } const sourcesWithApi = Sources.filter((source): source is Source & { api: string } => !!source.api); const sourcePromises: Promise<ApiResult>[] = sourcesWithApi...
/** * Switch to a connectable source * @param timeout Check next source if current source exceed timeout * @returns AddonInfos from automatic source */
https://github.com/syt2/zotero-addons/blob/1be0adb1ec53194a132722873de55d395bb2465c/src/modules/addonInfo.ts#L336-L384
1be0adb1ec53194a132722873de55d395bb2465c
zotero-addons
github_2023
syt2
typescript
AddonListenerManager.addListener
static addListener() { AddonManager.addAddonListener(this.addonEventListener); }
/** * Add addon listener in Zotero */
https://github.com/syt2/zotero-addons/blob/1be0adb1ec53194a132722873de55d395bb2465c/src/modules/addonListenerManager.ts#L53-L55
1be0adb1ec53194a132722873de55d395bb2465c
zotero-addons
github_2023
syt2
typescript
AddonListenerManager.removeListener
static removeListener() { AddonManager.removeAddonListener(this.addonEventListener); }
/** * Remove addon listener in Zotero */
https://github.com/syt2/zotero-addons/blob/1be0adb1ec53194a132722873de55d395bb2465c/src/modules/addonListenerManager.ts#L60-L62
1be0adb1ec53194a132722873de55d395bb2465c
zotero-addons
github_2023
syt2
typescript
AddonTable.registerInMenuTool
static registerInMenuTool() { ztoolkit.Menu.register("menuTools", { tag: "menuseparator", id: "addon-table-menuseparator" }); ztoolkit.Menu.register("menuTools", { tag: "menuitem", id: "addon-table-entrance", label: getString("menuitem-addons"), icon: `chrome://${config.a...
/** * Register entrance in menu tools */
https://github.com/syt2/zotero-addons/blob/1be0adb1ec53194a132722873de55d395bb2465c/src/modules/addonTable.ts#L53-L69
1be0adb1ec53194a132722873de55d395bb2465c
zotero-addons
github_2023
syt2
typescript
AddonTable.registerInToolbar
static registerInToolbar() { const toolbar = Zotero.getMainWindow().document.querySelector("#zotero-items-toolbar")!; if (getPref('hideToolbarEntrance')) { toolbar.querySelectorAll("#zotero-toolbaritem-addons").forEach(e => e.remove()); return; } const lookupNode = toolbar.querySelector("#zo...
/** * Register or unregister entrance in toolbar */
https://github.com/syt2/zotero-addons/blob/1be0adb1ec53194a132722873de55d395bb2465c/src/modules/addonTable.ts#L74-L95
1be0adb1ec53194a132722873de55d395bb2465c
zotero-addons
github_2023
syt2
typescript
AddonTable.showAddonsWindow
static async showAddonsWindow(options?: { from?: "toolbar" | "menu" }) { if (this.window && isWindowAlive(this.window)) { // eslint-disable-next-line @typescript-eslint/no-unused-expressions options?.from && this.updateHideToolbarEntranceInWindow(options.from === "toolbar"); this.window.focus(); ...
/** * Display addon table window */
https://github.com/syt2/zotero-addons/blob/1be0adb1ec53194a132722873de55d395bb2465c/src/modules/addonTable.ts#L110-L177
1be0adb1ec53194a132722873de55d395bb2465c
zotero-addons
github_2023
syt2
typescript
AddonTable.close
static async close() { this.window?.close(); }
/** * Close addon table window */
https://github.com/syt2/zotero-addons/blob/1be0adb1ec53194a132722873de55d395bb2465c/src/modules/addonTable.ts#L182-L184
1be0adb1ec53194a132722873de55d395bb2465c
zotero-addons
github_2023
syt2
typescript
AddonTable.isShown
static isShown() { return this.window && isWindowAlive(this.window); }
/** * Check this window is shown * @returns bool */
https://github.com/syt2/zotero-addons/blob/1be0adb1ec53194a132722873de55d395bb2465c/src/modules/addonTable.ts#L190-L192
1be0adb1ec53194a132722873de55d395bb2465c
zotero-addons
github_2023
syt2
typescript
AddonTable.refresh
static async refresh(force = false) { if (!this.isShown) { return; } const selectIndics = this.tableHelper?.treeInstance.selection.selected; const selectAddons = this.addonInfos.filter((e, idx) => selectIndics?.has(idx)); await this.updateAddonInfos(force); this.updateTable(); selectAddons.forEa...
/** * Refresh this window * @param force force fetch AddonInfos from source */
https://github.com/syt2/zotero-addons/blob/1be0adb1ec53194a132722873de55d395bb2465c/src/modules/addonTable.ts#L198-L210
1be0adb1ec53194a132722873de55d395bb2465c
zotero-addons
github_2023
syt2
typescript
AddonTable.updateExistAddons
static async updateExistAddons(options?: { filterAutoUpdatableAddons?: boolean }) { if (this.addonInfos.length <= 0) { await this.updateAddonInfos(false); } const addons = (await this.outdateAddons()).filter(e => { if (options?.filterAutoUpdatableAddons) { const systemUpdatable = AddonMa...
/** * Update exist upgradable addons * @param options Additional options * @param options.filterAutoUpdatableAddons Filter only auto upgradable add-ons that specificed in AddonManager */
https://github.com/syt2/zotero-addons/blob/1be0adb1ec53194a132722873de55d395bb2465c/src/modules/addonTable.ts#L217-L254
1be0adb1ec53194a132722873de55d395bb2465c
zotero-addons
github_2023
syt2
typescript
AddonTable.updateHideToolbarEntranceInWindow
private static updateHideToolbarEntranceInWindow(hide: boolean) { const hideToolbarCheckbox: any = this.window?.document.querySelector('#hide-toolbar-entrance'); const autoUpdateCheckbox: any = this.window?.document.querySelector('#auto-update'); hideToolbarCheckbox.hidden = hide; // eslint-disable-next...
// MARK: private
https://github.com/syt2/zotero-addons/blob/1be0adb1ec53194a132722873de55d395bb2465c/src/modules/addonTable.ts#L259-L265
1be0adb1ec53194a132722873de55d395bb2465c
zotero-addons
github_2023
syt2
typescript
initLocale
function initLocale() { const l10n = new ( typeof Localization === "undefined" ? ztoolkit.getGlobal("Localization") : Localization )([`${config.addonRef}-addon.ftl`], true); addon.data.locale = { current: l10n, }; }
/** * Initialize locale data */
https://github.com/syt2/zotero-addons/blob/1be0adb1ec53194a132722873de55d395bb2465c/src/utils/locale.ts#L8-L17
1be0adb1ec53194a132722873de55d395bb2465c
zotero-addons
github_2023
syt2
typescript
StringMatchUtils.checkMatch
static checkMatch(pattern: string, content: string): boolean { const lcs = this.longestCommonSubsequence(pattern, content); if (lcs.length < Math.min(pattern.length, content.length) * 0.6) { return false; } if (lcs.length >= Math.max(pattern.length, content.length) * 1.2) { return false; } const minWind...
// TODO: upgrade match algorithm
https://github.com/syt2/zotero-addons/blob/1be0adb1ec53194a132722873de55d395bb2465c/src/utils/stringMatchUtils.ts#L3-L10
1be0adb1ec53194a132722873de55d395bb2465c
zotero-addons
github_2023
syt2
typescript
actualInstall
const actualInstall = async () => { try { const install = await AddonManager.getInstallForURL(xpiUrl, { telemetryInfo: { source: config.addonID }, }); return await new Promise<boolean>(resolve => { const listener = { onDownloadStarted: (install: any) => { if (...
// reference in gecko
https://github.com/syt2/zotero-addons/blob/1be0adb1ec53194a132722873de55d395bb2465c/src/utils/utils.ts#L114-L201
1be0adb1ec53194a132722873de55d395bb2465c
zotero-addons
github_2023
syt2
typescript
isWindowAlive
function isWindowAlive(win?: Window) { return win && !Components.utils.isDeadWrapper(win) && !win.closed; }
/** * Check if the window is alive. * Useful to prevent opening duplicate windows. * @param win */
https://github.com/syt2/zotero-addons/blob/1be0adb1ec53194a132722873de55d395bb2465c/src/utils/window.ts#L8-L10
1be0adb1ec53194a132722873de55d395bb2465c
ngxtension-platform
github_2023
ngxtension
typescript
SignalHistoryComponent.addTodo
addTodo(todo: string) { if (!todo) return; this.todos.update((todos) => [ ...todos, { id: todos.length + 1, title: todo, completed: false }, ]); this.newTodoTitle.set(''); }
// todosHistory.reset() - Reset the history to the current state.
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/apps/test-app/src/app/signal-history/signal-history.component.ts#L275-L284
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
TestComponent.constructor
constructor() { connect(this.count, this.source$.pipe(take(2))); connect(this.objectSignal, this.objectSource$); connect(this.reducerSignal, this.objectSource$, (_, curr) => { return curr; }); }
// sub = connect(this.count, this.source$.pipe(take(2)));
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/connect/src/connect.spec.ts#L123-L129
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
TestComponent.constructor
constructor() { connect(this.count, this.source$.pipe(take(2))); }
// sub = connect(this.count, this.source$.pipe(take(2)));
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/connect/src/connect.spec.ts#L331-L333
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
parseArgs
function parseArgs( args: any[], ): [ Observable<unknown> | null, Reducer<unknown, unknown> | null, Injector | DestroyRef | null, boolean, (() => unknown) | null, ] { if (args.length > 3) { return [ args[0] as Observable<unknown>, args[1] as Reducer<unknown, unknown>, args[2] as Injector | DestroyRef,...
// TODO: there must be a way to parse the args more efficiently
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/connect/src/connect.ts#L191-L274
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
NgxControlError.context
public get context() { return ( this.viewContainerRef.get(0) as EmbeddedViewRef<NgxControlErrorContext> )?.context; }
/** * The context of this template. */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/control-error/src/control-error.ts#L393-L397
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
NgxControlError.ngTemplateContextGuard
public static ngTemplateContextGuard = ( directive: NgxControlError, context: unknown, ): context is NgxControlErrorContext => true
/** @ignore */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/control-error/src/control-error.ts
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
NgxControlValueAccessor.constructor
public constructor() { if (this.ngControl != null) this.ngControl.valueAccessor = this; }
/** @ignore */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/control-value-accessor/src/control-value-accessor.ts#L217-L219
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
NgxControlValueAccessor.markAsTouched
private initialValue = (): T => { if (this.ngControl != null) return this.ngControl.value; return injectCvaDefaultValue(); }
/** * This function should be called when this host is considered `touched`. * * NOTE: Whenever a `blur` event is triggered on this host, this function is called. * * @see {@link NgxControlValueAccessor.registerOnTouched} * @see {@link NgxControlValueAccessor.ngControl} */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/control-value-accessor/src/control-value-accessor.ts
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
NgxControlValueAccessor.ngOnInit
public ngOnInit(): void { if (this.ngControl != null) { runInInjectionContext(this.injector, () => { // NOTE: Don't use 'effect' because we have no idea if we are setting other signals here. // sync value rxEffect(toObservable(this.value$), (value) => { if (!this.compareTo(this.ngControl?.value, ...
/** @ignore */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/control-value-accessor/src/control-value-accessor.ts#L244-L266
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
NgxControlValueAccessor.registered
private get registered() { return this.ngControl instanceof NgModel ? (this.ngControl as unknown as { _registered: boolean })._registered : true; }
/** * `NgModel` sets up the control in `ngOnChanges`. Idk if bug or on purpose, but `writeValue` and `setDisabledState` are called before the inputs are set. * {@link https://github.com/angular/angular/blob/main/packages/forms/src/directives/ng_model.ts#L223} * * @ignore */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/control-value-accessor/src/control-value-accessor.ts#L330-L334
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
InjectLazyImpl.override
override<T>(type: Type<T>, mock: Type<unknown>) { this.overrides.set(type, mock); }
// no need to clean up
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/inject-lazy/src/inject-lazy-impl.ts#L26-L28
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
onSelectionChange
const onSelectionChange = () => { this.selection.set(null); if (this.window) { this.selection.set(this.window.getSelection()); } };
/** * Handler for the 'selectionchange' event. * We first clear the signal, then update it with the latest selection. */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/inject-text-selection/src/inject-text-selection.ts#L45-L50
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
TextSelectionService.resetSelection
resetSelection() { this.window.getSelection()?.empty(); }
/** * Clears the selection. This is a convenience method for `window.getSelection().empty()`. */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/inject-text-selection/src/inject-text-selection.ts#L78-L80
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
getRangesFromSelection
function getRangesFromSelection(selection: Selection): Range[] { const rangeCount = selection.rangeCount ?? 0; return Array.from({ length: rangeCount }, (_, i) => selection.getRangeAt(i)); }
/** * Returns an array of Range objects from a Selection. */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/inject-text-selection/src/inject-text-selection.ts#L86-L89
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
DisplayNamesPipe.transform
transform( code: string, type: Intl.DisplayNamesType, style?: Intl.DisplayNamesOptions['style'], locale?: string | string[], ): ReturnType<Intl.DisplayNames['of']> { try { return new Intl.DisplayNames(locale || this.locale, { ...this.defaultOptions, type, ...(style ? { style } : {}), }).of(...
/** * Displays the name of the given code in the given locale. * * @param code The code to transform. * @param type DisplayNamesType to use. * @param style Optional. The formatting style to use. Defaults to "short". * @param locale Optional. The locale to use for the transformation. Defaults to LOCALE_ID. ...
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/intl/src/display-names.pipe.ts#L60-L76
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
ListFormatPipe.transform
transform( value: Iterable<string>, style?: Intl.ListFormatOptions['style'], locale?: string | string[], ): string { try { return new Intl.ListFormat(locale || this.locale, { ...this.defaultOptions, ...(style ? { style } : {}), }).format(Array.from(value)); } catch (e) { console.error(e); ...
/** * Transforms the list of values into a formatted string. * * @param value The list of values to format. * @param style Optional. The formatting style to use. Defaults to "long". * @param locale Optional. The locale to use for the transformation. Defaults to LOCALE_ID. * @returns The formatted list of va...
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/intl/src/list-format.pipe.ts#L56-L70
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
PluralRulesPipe.transform
transform( value: number, locale?: string, ): ReturnType<Intl.PluralRules['select']> | string { try { return new Intl.PluralRules( locale || this.locale, this.defaultOptions, ).select(value); } catch (e) { console.error(e); return String(value); } }
/** * Transforms the value into a plural category. * * @param value The value to transform. * @param locale Optional, the locale to use for the formatting. * @returns The plural category for the value or the value as string in case of errors. */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/intl/src/plural-rules.pipe.ts#L56-L69
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
RelativeTimeFormatPipe.transform
transform( value: number, unit: Intl.RelativeTimeFormatUnit, style?: Intl.RelativeTimeFormatOptions['style'], locale?: string, ): ReturnType<Intl.RelativeTimeFormat['format']> { try { return new Intl.RelativeTimeFormat(locale || this.locale, { ...this.defaultOptions, ...(style ? { style } : {}), ...
/** * Transforms the value into a relative time format. * * @param value The value to format. * @param unit The unit of the value. * @param style Optional, the formatting style to use. * @param locale Optional, the locale to use for the formatting. * @returns The relative time format of the value or the v...
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/intl/src/relative-time-format.pipe.ts#L58-L73
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
SupportedValuesOf.transform
transform( key: | 'calendar' | 'collation' | 'currency' | 'numberingSystem' | 'timeZone' | 'unit', ): string[] { try { return Intl.supportedValuesOf(key); } catch (e) { console.error(e); return []; } }
/** * Transforms a key into an array containing the supported calendar, collation, currency, numbering systems, or unit values supported by the implementation. * * @param key A key string indicating the category of values to be returned. This is one of: "calendar", "collation", "currency","numberingSystem", "time...
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/intl/src/supportedValuesOf.pipe.ts#L19-L34
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
WithDefaultAndParseComponent.testTypes
testTypes() { // @ts-expect-error Type 'never' is not assignable to type 'WritableSignal<number>'. this.parseBehaviorWithDefault = signal(1); }
// never
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/linked-query-param/src/linked-query-param.spec.ts#L549-L552
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
LinkedQueryParamGlobalHandler.scheduleNavigation
scheduleNavigation() { this._schedulerNotifier.notify(); }
/** * Schedules the navigation event. */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/linked-query-param/src/linked-query-param.ts#L123-L125
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
LinkedQueryParamGlobalHandler.setParamKeyValue
setParamKeyValue(key: string, value: StringifyReturnType) { this._currentKeys[key] = value; }
/** * Sets the value of a query param. * This will be used on the next navigation event. */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/linked-query-param/src/linked-query-param.ts#L131-L133
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
LinkedQueryParamGlobalHandler.setCurrentNavigationExtras
setCurrentNavigationExtras(config: Partial<NavigateMethodFields> = {}) { const { queryParamsHandling, onSameUrlNavigation, replaceUrl, skipLocationChange, preserveFragment, } = config; if (queryParamsHandling || queryParamsHandling === '') { this._navigationExtras.queryParamsHandling = queryPara...
/** * Sets the navigation extras that will be used on the next navigation event. */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/linked-query-param/src/linked-query-param.ts#L138-L161
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
LinkedQueryParamGlobalHandler.navigate
private navigate(): Promise<boolean> { return this._router .navigate([], { queryParams: this._currentKeys, ...this._navigationExtras, // override the navigation extras }) .then((value) => { // we reset the current keys and navigation extras on navigation // in order to avoid leaking to other ...
/** * Navigates to the current URL with the accumulated query parameters and navigation extras. * Cleans up the current keys and navigation extras after the navigation. */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/linked-query-param/src/linked-query-param.ts#L167-L180
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
parseParamValue
const parseParamValue = (params: Params) => { // Get the value from the params object. const value: string | null = params[key] ?? null; // If a parsing function is provided in the config, use it to parse the value. if (options?.parse) { return options.parse(value); } // If the value is undefined ...
/** * Parses a parameter value based on provided configuration. * @param params - An object containing parameters. * @returns The parsed parameter value. */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/linked-query-param/src/linked-query-param.ts#L344-L360
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
RepeatPipe.transform
transform(length: number, startAt = 0): number[] { if (Number.isNaN(length) || !Number.isInteger(length) || length < 0) { throw new Error(lengthErrorMessageBuilder(length)); } if (Number.isNaN(startAt) || !Number.isInteger(startAt)) { throw new Error(startAtErrorMessageBuilder(startAt)); } return Array....
/** * Returns an array of numbers starting from a given startAt value up to a specified length. * * @param {number} length - The number of elements to include in the resulting array. * @param {number} [startAt=0] - The value at which to start the sequence. Defaults to 0 if not provided. * @returns {number[]} ...
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/repeat-pipe/src/repeat-pipe.ts#L82-L90
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
createResizeStream
function createResizeStream( { debounce, scroll, offsetSize, box, emitInZone, emitInitialResult, }: ResizeOptions, nativeElement: HTMLElement, document: Document, zone: NgZone, ) { const window = document.defaultView; const screen = window?.screen; const isSupport = !!window?.ResizeObserver; let o...
// return ResizeResult observable
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/resize/src/resize.ts#L119-L248
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
findScrollContainers
function findScrollContainers( element: HTMLOrSVGElement | null, window: Window | null, documentBody: HTMLElement, ): HTMLOrSVGElement[] { const result: HTMLOrSVGElement[] = []; if (!element || !window || element === documentBody) return result; const { overflow, overflowX, overflowY } = window.getComputedStyle( ...
// Returns a list of scroll offsets
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/resize/src/resize.ts#L270-L294
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
createHistoryRecord
function createHistoryRecord<T>(value: T): SignalHistoryRecord<T> { return { value, timestamp: Date.now() }; }
/** * Creates a history record with the current timestamp. * @param value The value to store in the history record. * @returns A SignalHistoryRecord object. */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/signal-history/src/signal-history.ts#L22-L24
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
undo
const undo = () => { if (undoStack().length > 1) { // Prevent undoing the initial state // Get the last record from the undo stack const currentRecord = undoStack()[undoStack().length - 1]; // Remove the last record from the undo stack undoStack.update((stack) => stack.slice(0, -1)); // Add...
/** * Undo the last change to the source signal. */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/signal-history/src/signal-history.ts#L135-L152
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
redo
const redo = () => { if (redoStack().length) { // Get the first record from the redo stack as we want to remove it const nextRecord = redoStack()[0]; // Remove the first record from the redo stack redoStack.update((stack) => stack.slice(1)); // Add the next record to the undo stack undoStac...
/** * Redo the last undone change to the source signal. */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/signal-history/src/signal-history.ts#L157-L171
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
reset
const reset = () => { const currentRecord = undoStack()[undoStack().length - 1]; undoStack.set([currentRecord]); redoStack.set([]); };
/** * Reset the history to the current state. */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/signal-history/src/signal-history.ts#L176-L180
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
clear
const clear = () => { undoStack.set([]); redoStack.set([]); };
/** * Clear the history. This will remove all history records. */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/signal-history/src/signal-history.ts#L185-L188
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
NgxSvgSprites.register
public readonly register = (sprite: NgxSvgSprite) => { this.sprites[sprite.name] = { ...sprite, svg$: defer(() => this.ngZone.runOutsideAngular(() => ajax<SVGGraphicsElement>({ url: sprite.baseUrl, responseType: 'document', }), ), ).pipe( map(({ response }) => { const s...
/** * * @param name * @returns a registered sprite by its name or undefined if not registered. */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/svg-sprite/src/svg-sprite.ts
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
createSvgSprite
const createSvgSprite = (options: CreateNgxSvgSpriteOptions) => { if (options.url == null) options.url = (baseUrl, fragment) => `${baseUrl}#${fragment}`; return options as NgxSvgSprite; };
/** * Creates a {@link NgxSvgSprite} with a default `url` builder of `${baseUrl}#${fragment}`. * * @param options * @returns */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/svg-sprite/src/svg-sprite.ts#L157-L162
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
NgxSvgSpriteFragment.ngOnInit
public ngOnInit() { // Copy the 'viewBox' from the 'symbol' element in the sprite to this svg. // Do not launch this effect when the svg already has a 'viewBox'. if (!this.element.hasAttribute('viewBox')) this.autoEffect(() => { const element = this.element; const autoViewBox = this.autoViewBox$(); ...
/** * @ignore */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/ngxtension/svg-sprite/src/svg-sprite.ts#L318-L386
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
replaceTemplate
function replaceTemplate( template: string, replaceValue: string, start: number, end: number, offset: number, ) { return ( template.slice(0, start + offset) + replaceValue + template.slice(end + offset) ); }
/** * Replace the value in the template with the new value based on the start and end position + offset */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/plugin/src/generators/convert-to-self-closing-tag/generator.ts#L260-L272
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
ElementCollector.visitText
override visitText(ast: Text_2, context: any): any { if (ast.value.includes('{{')) { const usedVariables = collectUsedVariables(ast.value, this.variables); if (usedVariables.length) { this.elements.push({ type: 'interpolation', value: ast.value, variables: usedVariables, start: ast.sour...
// 5. animations - not supported yet
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/plugin/src/generators/shared-utils/migrate-signals-in-template.ts#L138-L153
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
replaceOnlyIfNotWrappedInQuotesOrPropertyAccess
function replaceOnlyIfNotWrappedInQuotesOrPropertyAccess( value: string, variables: string[], ): string { // replace only if not wrapped in quotes // replace only if doesn't start with . (property access) // replace only if it doesn't end with : (it's a key-value pair) variables.forEach((variable) => { const re...
/** * Replace the text only if it's not wrapped in quotes or property access */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/plugin/src/generators/shared-utils/migrate-signals-in-template.ts#L319-L332
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
ngxtension-platform
github_2023
ngxtension
typescript
replaceTemplate
function replaceTemplate( template: string, replaceValue: string, start: number, end: number, offset: number, ) { return ( template.slice(0, start + offset) + replaceValue + template.slice(end + offset) ); }
/** * Replace the value in the template with the new value based on the start and end position + offset */
https://github.com/ngxtension/ngxtension-platform/blob/e86b7ebd410cf225ec33f6e01d1b850c4f16c596/libs/plugin/src/generators/shared-utils/migrate-signals-in-template.ts#L337-L349
e86b7ebd410cf225ec33f6e01d1b850c4f16c596
agentlabs
github_2023
agentlabs-dev
typescript
AgentMessageStream.typewrite
async typewrite(message: string, options: { intervalMs?: number } = {}) { const interval = options?.intervalMs ?? DEFAULT_MESSAGE_TYPING_INTERVAL_MS; const chunks = chunk(message, DEFAULT_STREAM_TOKEN_SIZE); for (let i = 0; i < chunks.length; i++) { this.write(chunks[i])...
/** * Write the next part of the message with a typewriter animation. * Writing to the stream after calling `end` will throw an error. */
https://github.com/agentlabs-dev/agentlabs/blob/39eb66fe15d039ffb9ba4e7a4415b97e8ed7c53a/sdks/node-sdk/src/agent-message-stream.ts#L41-L53
39eb66fe15d039ffb9ba4e7a4415b97e8ed7c53a
agentlabs
github_2023
agentlabs-dev
typescript
AgentMessageStream.write
write(message: string) { if (this.isEnded) { throw new Error('Cannot write to a stream after calling end'); } this.realtime.emit('stream-chat-message-token', { text: message, conversationId: this.conversationId, messageId: this.messageId, ...
/** * Write the next part of the message. * Writing to the stream after calling `end` will throw an error. */
https://github.com/agentlabs-dev/agentlabs/blob/39eb66fe15d039ffb9ba4e7a4415b97e8ed7c53a/sdks/node-sdk/src/agent-message-stream.ts#L59-L71
39eb66fe15d039ffb9ba4e7a4415b97e8ed7c53a
agentlabs
github_2023
agentlabs-dev
typescript
AgentMessageStream.end
end() { this.isEnded = true; this.realtime.emit('stream-chat-message-end', { conversationId: this.conversationId, messageId: this.messageId, agentId: this.agentId, }); }
/** * Indicate that the message is complete, releasing the user's prompt. * This MUST be called after all the calls to `write` have been made. * Writing to the stream after calling `end` will throw an error. */
https://github.com/agentlabs-dev/agentlabs/blob/39eb66fe15d039ffb9ba4e7a4415b97e8ed7c53a/sdks/node-sdk/src/agent-message-stream.ts#L78-L85
39eb66fe15d039ffb9ba4e7a4415b97e8ed7c53a
agentlabs
github_2023
agentlabs-dev
typescript
Agent.echart
async echart({ echart, text = '', conversationId, textFormat = 'PlainText' }: SendEchartOptions): Promise<void> { this.config.realtime.emit('chat-message', { text, conversationId, format: localMessageFormatToRemote[textFormat], agentId: this.config.agentId, type: 'EC...
/** * Send a message that contains a drawn echart, with an optional text added. */
https://github.com/agentlabs-dev/agentlabs/blob/39eb66fe15d039ffb9ba4e7a4415b97e8ed7c53a/sdks/node-sdk/src/agent.ts#L50-L60
39eb66fe15d039ffb9ba4e7a4415b97e8ed7c53a
agentlabs
github_2023
agentlabs-dev
typescript
Attachment.fromBuffer
static fromBuffer(buffer: Buffer, filename: string, options: FileAttachmentOptions = {}): AttachmentItem { return new BufferFileAttachment(buffer, filename, options); }
/** * Creates an attachment from in-memory data held in a Buffer. * You need to specify the filename manually as there is no file path to infer it from. */
https://github.com/agentlabs-dev/agentlabs/blob/39eb66fe15d039ffb9ba4e7a4415b97e8ed7c53a/sdks/node-sdk/src/attachment.ts#L13-L15
39eb66fe15d039ffb9ba4e7a4415b97e8ed7c53a
agentlabs
github_2023
agentlabs-dev
typescript
MessageAttachment.download
download(): Promise<Buffer> { return this.http.download(`/attachments/downloadById/${this.id}`); }
/** * Download the contents of this attachment and put them in a Buffer. * Be aware that an attachment can be of significant size (we accept only up to 10MB per attachment) * and that using this method will load the entire attachment into memory. * If you want to download the attachment to a file directly, use ...
https://github.com/agentlabs-dev/agentlabs/blob/39eb66fe15d039ffb9ba4e7a4415b97e8ed7c53a/sdks/node-sdk/src/message-attachment.ts#L37-L39
39eb66fe15d039ffb9ba4e7a4415b97e8ed7c53a
agentlabs
github_2023
agentlabs-dev
typescript
MessageAttachment.downloadToFile
async downloadToFile(path: string): Promise<void> { const buffer = await this.download(); await writeFile(path, buffer); }
/** * Download the contents of this attachment and write them to a file. * If you want to get the contents of the attachment in a Buffer, use download() instead. */
https://github.com/agentlabs-dev/agentlabs/blob/39eb66fe15d039ffb9ba4e7a4415b97e8ed7c53a/sdks/node-sdk/src/message-attachment.ts#L45-L49
39eb66fe15d039ffb9ba4e7a4415b97e8ed7c53a
agentlabs
github_2023
agentlabs-dev
typescript
AgentsService.createAgent
async createAgent(dto: { name: string; projectId: string; creatorId: string; }): PResult<CreatedAgentDto, CreateAgentError> { const verifyResult = await this.verifyIfProjectUser({ userId: dto.creatorId, projectId: dto.projectId, }); if (!verifyResult.ok) { return err(verifyR...
/* async uploadAgentLogo( agentId: string, buffer: Buffer, mimeType: string, ): PResult<{ isUploaded: true }, UploadAgentLogoError> { const isAcceptedMimeType = this.isAcceptedAgentLogoMimeType(mimeType); if (!isAcceptedMimeType) { return err('ProhibitedMimeType'); } const attach...
https://github.com/agentlabs-dev/agentlabs/blob/39eb66fe15d039ffb9ba4e7a4415b97e8ed7c53a/server/src/agents/agents.service.ts#L135-L168
39eb66fe15d039ffb9ba4e7a4415b97e8ed7c53a
agentlabs
github_2023
agentlabs-dev
typescript
AttachmentsService.createOneSync
async createOneSync(payload: CreateAttachmentPayload) { const checksum = this.computeChecksum(payload.data); this.logger.debug(`Creating attachment with checksum ${checksum}.`); const attachment = await this.prisma.attachment.create({ data: { driver: 'LOCAL_FILE_SYSTEM', name: payloa...
/** * Designed to handle small attachments that can be held in the passed buffer. * Attachments of more consequent size would have to be handled through some kind of * streaming mechanism, which AgentLabs does not currently support. */
https://github.com/agentlabs-dev/agentlabs/blob/39eb66fe15d039ffb9ba4e7a4415b97e8ed7c53a/server/src/attachments/attachments.service.ts#L45-L74
39eb66fe15d039ffb9ba4e7a4415b97e8ed7c53a
agentlabs
github_2023
agentlabs-dev
typescript
AuthMethodsService.verifyIfProjectUser
private async verifyIfProjectUser(params: { userId: string; projectId: string; }): PResult<{ isVerified: true }, VerifyIfIsProjectUserError> { const { userId, projectId } = params; const project = await this.prisma.project.findFirst({ where: { id: projectId, }, include: { ...
// TODO: Move this to a shared service with in-memory cache
https://github.com/agentlabs-dev/agentlabs/blob/39eb66fe15d039ffb9ba4e7a4415b97e8ed7c53a/server/src/auth-methods/auth-methods.service.ts#L31-L58
39eb66fe15d039ffb9ba4e7a4415b97e8ed7c53a
agentlabs
github_2023
agentlabs-dev
typescript
Mutex.acquire
async acquire(options: AcquireOptions = {}): Promise<void> { const idx = this.idx++; if (idx === this.currentIdx) { return; } return new Promise<void>((resolve) => { let totalWaitTime = 0; const interval = setInterval(() => { if (idx === this.currentIdx) { clearInt...
/** * Returns a promise that resolves when the mutex is acquired. * No one will be able to acquire the mutex until a call to release() is made. * Acquisition requests are queued and processed in the order they are received. */
https://github.com/agentlabs-dev/agentlabs/blob/39eb66fe15d039ffb9ba4e7a4415b97e8ed7c53a/server/src/common/mutex.ts#L31-L56
39eb66fe15d039ffb9ba4e7a4415b97e8ed7c53a
YomiNinja
github_2023
matt-m-o
typescript
Dictionary.constructor
constructor( props: DictionaryConstructorProps ) { if (!props) return; // this.id = props.id || Dictionary.generateId({ dictionaryId: props.name }); this.name = props.name; this.version = props.version; this.order = props.order; this.enabled = props.enabled; th...
// two-letter ISO 639-1
https://github.com/matt-m-o/YomiNinja/blob/12464fb25e66daa0d174b81bcd41fc03216f84fe/yomininja-e/electron-src/@core/domain/dictionary/dictionary.ts#L31-L42
12464fb25e66daa0d174b81bcd41fc03216f84fe
YomiNinja
github_2023
matt-m-o
typescript
DictionaryTag.generateId
static generateId( input: { dictionary_id: DictionaryId, tag_name: string } ): DictionaryTagId { return MurmurHash3( input.dictionary_id+'/', 0x12345789 ) .hash( input.tag_name ) .result(); // return input.dictionary_id + '/' + input.tag_name; }
// ! might change to a hashing function
https://github.com/matt-m-o/YomiNinja/blob/12464fb25e66daa0d174b81bcd41fc03216f84fe/yomininja-e/electron-src/@core/domain/dictionary/dictionary_tag/dictionary_tag.ts#L53-L60
12464fb25e66daa0d174b81bcd41fc03216f84fe
YomiNinja
github_2023
matt-m-o
typescript
OcrResultScalable.addRegionResult
addRegionResult( input: { regionResult: OcrResultScalable; regionPosition: { // Percentages top: number; left: number; }; regionSize: { width: number; height: number; }, globa...
// Adds results from another OcrResultScalable as a subregion
https://github.com/matt-m-o/YomiNinja/blob/12464fb25e66daa0d174b81bcd41fc03216f84fe/yomininja-e/electron-src/@core/domain/ocr_result_scalable/ocr_result_scalable.ts#L91-L143
12464fb25e66daa0d174b81bcd41fc03216f84fe
YomiNinja
github_2023
matt-m-o
typescript
SettingsPreset.toJson
toJson(): SettingsPresetJson { return { id: this.id, ...this.props, } }
/* private ocrEngineMaxImageWidthValidation( maxImageWidth?: number ) { if ( !maxImageWidth || maxImageWidth % 32 != 0 || // Must be multiple of 32 maxImageWidth < 0 ) return this.ocr_engine.max_image_width; return maxImageWidth;...
https://github.com/matt-m-o/YomiNinja/blob/12464fb25e66daa0d174b81bcd41fc03216f84fe/yomininja-e/electron-src/@core/domain/settings_preset/settings_preset.ts#L225-L230
12464fb25e66daa0d174b81bcd41fc03216f84fe
YomiNinja
github_2023
matt-m-o
typescript
validateFurigana
function validateFurigana( headword: SimpleHeadword, furigana: AutoGeneratedFurigana[] ) { let generatedReading = headword.term; // How the original string length changed let offset = 0; furigana.forEach( item => { generatedReading = replaceSubstring( gener...
// Tests if the generated furigana is compatible with the official reading
https://github.com/matt-m-o/YomiNinja/blob/12464fb25e66daa0d174b81bcd41fc03216f84fe/yomininja-e/electron-src/@core/infra/japanese_helper.adapter/japanese_helper.adapter.spec.ts#L61-L81
12464fb25e66daa0d174b81bcd41fc03216f84fe
YomiNinja
github_2023
matt-m-o
typescript
PaddleOcrService.processStatusCheck
async processStatusCheck(): Promise< boolean > { let triesCounter = 0; while( this.status != OcrAdapterStatus.Enabled ) { // Waiting for 2 seconds await new Promise( (resolve) => setTimeout(resolve, 2000) ); triesCounter++; console.log('ppocrSe...
// Checks if the ppocrService is enabled.
https://github.com/matt-m-o/YomiNinja/blob/12464fb25e66daa0d174b81bcd41fc03216f84fe/yomininja-e/electron-src/@core/infra/ocr/ocr_services/paddle_ocr_service/paddle_ocr_service.ts#L195-L211
12464fb25e66daa0d174b81bcd41fc03216f84fe
YomiNinja
github_2023
matt-m-o
typescript
AppEventEmitter.on
on< K extends keyof TEventMap >( event: K, listener: ( data: TEventMap[K] ) => void ): this { return super.on( event.toString(), listener ); }
// Define a method that returns a typed EventEmitter for a specific event
https://github.com/matt-m-o/YomiNinja/blob/12464fb25e66daa0d174b81bcd41fc03216f84fe/yomininja-e/electron-src/app/app.event_emitter.ts#L5-L10
12464fb25e66daa0d174b81bcd41fc03216f84fe
YomiNinja
github_2023
matt-m-o
typescript
YomichanImportService.getDictionaryIndex
static async getDictionaryIndex( dictionaryPath: string ): Promise< YomichanDictionaryIndex > { const indexRaw = await fsPromises.readFile( dictionaryPath+'/index.json', 'utf-8' ); return JSON.parse( indexRaw ) as YomichanDictionaryIndex; }
// }
https://github.com/matt-m-o/YomiNinja/blob/12464fb25e66daa0d174b81bcd41fc03216f84fe/yomininja-e/electron-src/dictionaries/yomichan/yomichan_import.service.ts#L153-L158
12464fb25e66daa0d174b81bcd41fc03216f84fe
YomiNinja
github_2023
matt-m-o
typescript
BrowserExtensionsService.selectWindow
selectWindow = ( window: BrowserWindow ) => { this.extensionsApi.selectTab( window.webContents ); }
// Select tab
https://github.com/matt-m-o/YomiNinja/blob/12464fb25e66daa0d174b81bcd41fc03216f84fe/yomininja-e/electron-src/extensions/browser_extensions.service.ts#L135-L137
12464fb25e66daa0d174b81bcd41fc03216f84fe
YomiNinja
github_2023
matt-m-o
typescript
MainController.constructor
constructor() {}
// Temporary solution for reloading UI without loosing tab
https://github.com/matt-m-o/YomiNinja/blob/12464fb25e66daa0d174b81bcd41fc03216f84fe/yomininja-e/electron-src/main/main.controller.ts#L22-L22
12464fb25e66daa0d174b81bcd41fc03216f84fe
YomiNinja
github_2023
matt-m-o
typescript
OverlayService.initWebSocket
initWebSocket() { this.webSocketServer = new WebSocketServer({ port: 6677 }); this.webSocketServer.on( 'connection', ( ws ) => { ws.on( 'error', console.error ); console.log("New socket connection!"); this.wsConnections.push( ws ); ...
// Websocket to use with text extractors
https://github.com/matt-m-o/YomiNinja/blob/12464fb25e66daa0d174b81bcd41fc03216f84fe/yomininja-e/electron-src/overlay/overlay.service.ts#L23-L34
12464fb25e66daa0d174b81bcd41fc03216f84fe
YomiNinja
github_2023
matt-m-o
typescript
sendFrame
async function sendFrame( frame: Buffer ) { await global.ipcRenderer.invoke( 'screen_capturer:frame', frame ); }
// function VideoElement() {
https://github.com/matt-m-o/YomiNinja/blob/12464fb25e66daa0d174b81bcd41fc03216f84fe/yomininja-e/renderer/pages/screen-capturer.tsx#L192-L197
12464fb25e66daa0d174b81bcd41fc03216f84fe
Wasmnizer-ts
github_2023
web-devkits
typescript
readCfgFromCli
function readCfgFromCli(args: minimist.ParsedArgs) { const cfgs: Partial<ConfigMgr> = {}; for (const key in args) { // eslint-disable-next-line no-prototype-builtins if (args.hasOwnProperty(key)) { cfgs[key as keyof ConfigMgr] = args[key]; } } setConfig(cfgs); }
/** read configs from cli */
https://github.com/web-devkits/Wasmnizer-ts/blob/228cb803eb71bc7003b0e1d4faafecbc153e03fd/cli/ts2wasm.ts#L186-L195
228cb803eb71bc7003b0e1d4faafecbc153e03fd
Wasmnizer-ts
github_2023
web-devkits
typescript
Scope.getName
public getName() { return this.name; }
/* Common get/set for scope names, derived class may introduce wrapper get/set functions for more explicit semantics */
https://github.com/web-devkits/Wasmnizer-ts/blob/228cb803eb71bc7003b0e1d4faafecbc153e03fd/src/scope.ts#L91-L93
228cb803eb71bc7003b0e1d4faafecbc153e03fd
Wasmnizer-ts
github_2023
web-devkits
typescript
Scope.specialize
specialize(scope: Scope) { scope.kind = this.kind; scope.name = this.name; scope.children = new Array<Scope>(); scope.namedTypeMap = new Map<string, Type>(); scope.debugFilePath = this.debugFilePath; scope.tempVarArray = new Array<Variable>(); scope.variableArray ...
// process generic specialization
https://github.com/web-devkits/Wasmnizer-ts/blob/228cb803eb71bc7003b0e1d4faafecbc153e03fd/src/scope.ts#L588-L600
228cb803eb71bc7003b0e1d4faafecbc153e03fd
Wasmnizer-ts
github_2023
web-devkits
typescript
SemanticChecker.checkCallExpr
private checkCallExpr(expr: CallExpression) { const calleeType = expr.callExpr.exprType; if (calleeType.kind === TypeKind.FUNCTION) { const funcType = expr.callExpr.exprType as TSFunction; let paramTypes = funcType.getParamTypes(); if (funcType.hasRest()) { ...
// check arguments and parameters types
https://github.com/web-devkits/Wasmnizer-ts/blob/228cb803eb71bc7003b0e1d4faafecbc153e03fd/src/semantic_check.ts#L178-L220
228cb803eb71bc7003b0e1d4faafecbc153e03fd
Wasmnizer-ts
github_2023
web-devkits
typescript
SemanticChecker.returnTypeCheck
private returnTypeCheck(expr: Expression) { const funcScope = this.curScope!.getNearestFunctionScope() as FunctionScope; const returnType = funcScope.funcType.returnType; this.nominalClassCheck( returnType, expr.exprType, ErrorFlag.ReturnTypesAreNo...
// check return statement type and function return type
https://github.com/web-devkits/Wasmnizer-ts/blob/228cb803eb71bc7003b0e1d4faafecbc153e03fd/src/semantic_check.ts#L223-L239
228cb803eb71bc7003b0e1d4faafecbc153e03fd
Wasmnizer-ts
github_2023
web-devkits
typescript
SemanticChecker.nominalClassCheck
private nominalClassCheck( left: Type, right: Type, flag: ErrorFlag, msg: string, ) { if (left instanceof TSInterface || right instanceof TSInterface) { return; } if (!(left instanceof TSClass) || !(right instanceof TSClass)) { return; ...
/** addtional sematic checking rules */
https://github.com/web-devkits/Wasmnizer-ts/blob/228cb803eb71bc7003b0e1d4faafecbc153e03fd/src/semantic_check.ts#L264-L306
228cb803eb71bc7003b0e1d4faafecbc153e03fd
Wasmnizer-ts
github_2023
web-devkits
typescript
StatementProcessor.getClassIterPropNames
private getClassIterPropNames(classType: TSClass): Expression[] { const memberFields = classType.fields; return memberFields.map((field) => { const strLiteralExpr = new StringLiteralExpression(field.name); strLiteralExpr.setExprType(builtinTypes.get('string')!); retur...
/** it uses for for in loop, to stores property names in compile time */
https://github.com/web-devkits/Wasmnizer-ts/blob/228cb803eb71bc7003b0e1d4faafecbc153e03fd/src/statement.ts#L1525-L1532
228cb803eb71bc7003b0e1d4faafecbc153e03fd
Wasmnizer-ts
github_2023
web-devkits
typescript
TSTypeParameter.constructor
constructor(name: string, wide: Type, index: number, def?: Type) { super(); this._name = name; this._wide = wide; this._index = index; this._default = def; }
// the declaration index, important!
https://github.com/web-devkits/Wasmnizer-ts/blob/228cb803eb71bc7003b0e1d4faafecbc153e03fd/src/type.ts#L299-L305
228cb803eb71bc7003b0e1d4faafecbc153e03fd
Wasmnizer-ts
github_2023
web-devkits
typescript
TSFunction.clone
public clone(): TSFunction { const func = new TSFunction(this.funcKind); func.typeKind = this.typeKind; func._isBinaryenImpl = this._isBinaryenImpl; func._isDeclare = this._isDeclare; func._isExport = this._isExport; func._isMethod = this._isMethod; func._isOption...
// shadow copy, content of parameterTypes and returnType is not copied
https://github.com/web-devkits/Wasmnizer-ts/blob/228cb803eb71bc7003b0e1d4faafecbc153e03fd/src/type.ts#L788-L805
228cb803eb71bc7003b0e1d4faafecbc153e03fd
Wasmnizer-ts
github_2023
web-devkits
typescript
TypeResolver.visitObjectSymbolNode
private visitObjectSymbolNode(node: ts.Node) { let type: Type | undefined = undefined; let symbolNode = node; if (ts.isClassDeclaration(node)) { type = new TSClass(); } else if (ts.isInterfaceDeclaration(node)) { type = new TSInterface(); } else if (ts.is...
/** parse types with symbol value for TSClass */
https://github.com/web-devkits/Wasmnizer-ts/blob/228cb803eb71bc7003b0e1d4faafecbc153e03fd/src/type.ts#L983-L1012
228cb803eb71bc7003b0e1d4faafecbc153e03fd
Wasmnizer-ts
github_2023
web-devkits
typescript
TypeResolver.isObjectType
private isObjectType(type: ts.Type) { return ( this.isObject(type) && type.symbol && type.symbol.name === '__type' && !this.isFunction(type) ); }
// in most cases, the type has Anonymous ObjectTypeFlag
https://github.com/web-devkits/Wasmnizer-ts/blob/228cb803eb71bc7003b0e1d4faafecbc153e03fd/src/type.ts#L1802-L1809
228cb803eb71bc7003b0e1d4faafecbc153e03fd
Wasmnizer-ts
github_2023
web-devkits
typescript
createClassScope
function createClassScope( specializedClassType: TSClass, parentScope: Scope, context: ParserContext, ) { const genericClassType = specializedClassType.genericOwner; if ( !genericClassType || (genericClassType && !genericClassType.belongedScope) || !specializedClassType.speci...
/** * @describe create a new specialized classScope * @param specializedClassType the specialized class type * @param parentScope the parent scope * @param context the parser context * @returns a new specialized ClassScope */
https://github.com/web-devkits/Wasmnizer-ts/blob/228cb803eb71bc7003b0e1d4faafecbc153e03fd/src/utils.ts#L1243-L1329
228cb803eb71bc7003b0e1d4faafecbc153e03fd