repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
aibitat | github_2023 | wladpaiva | typescript | AIbitat.getHistory | private getHistory({from, to}: {from?: string; to?: string}) {
return this._chats.filter(chat => {
const isSuccess = chat.state === 'success'
// return all chats to the node
if (!from) {
return isSuccess && chat.to === to
}
// get all chats from the node
if (!to) {
... | /**
* Get the chat history between two nodes or all chats to/from a node.
*/ | https://github.com/wladpaiva/aibitat/blob/d66dfddae5c7b8c974cbee442707a04635333181/src/index.ts#L796-L822 | d66dfddae5c7b8c974cbee442707a04635333181 |
aibitat | github_2023 | wladpaiva | typescript | AIbitat.getProviderForConfig | private getProviderForConfig<T extends Provider>(config: ProviderConfig<T>) {
if (typeof config.provider === 'object') {
return config.provider
}
switch (config.provider) {
case 'openai':
return new Providers.OpenAIProvider({model: config.model})
case 'anthropic':
return n... | /**
* Get provider based on configurations.
* If the provider is a string, it will return the default provider for that string.
*
* @param config The provider configuration.
*/ | https://github.com/wladpaiva/aibitat/blob/d66dfddae5c7b8c974cbee442707a04635333181/src/index.ts#L830-L846 | d66dfddae5c7b8c974cbee442707a04635333181 |
aibitat | github_2023 | wladpaiva | typescript | AIbitat.function | public function(functionConfig: AIbitat.FunctionConfig) {
this.functions.set(functionConfig.name, functionConfig)
return this
} | /**
* Register a new function to be called by the AIbitat agents.
* You are also required to specify the which node can call the function.
* @param functionConfig The function configuration.
*/ | https://github.com/wladpaiva/aibitat/blob/d66dfddae5c7b8c974cbee442707a04635333181/src/index.ts#L853-L856 | d66dfddae5c7b8c974cbee442707a04635333181 |
aibitat | github_2023 | wladpaiva | typescript | cli | function cli({
simulateStream = true,
}: {
/**
* Simulate streaming by breaking the cached response into chunks.
* Helpful to make the conversation more realistic and faster.
* @default true
*/
simulateStream?: boolean
} = {}) {
return {
name: 'cli',
setup(aibitat) {
let printing: Prom... | /**
* Command-line Interface plugin. It prints the messages on the console and asks for feedback
* while the conversation is running in the background.
*/ | https://github.com/wladpaiva/aibitat/blob/d66dfddae5c7b8c974cbee442707a04635333181/src/plugins/cli.ts#L11-L73 | d66dfddae5c7b8c974cbee442707a04635333181 |
aibitat | github_2023 | wladpaiva | typescript | search | async function search(
query: string,
options: {
/**
* `serper.dev` API key.
* @default process.env.SERPER_API_KEY
*/
serperApiKey?: string
} = {},
) {
console.log('π₯ ~ Searching on Google...')
const url = 'https://google.serper.dev/search'
const payload = JSON.stringify({
q: qu... | /**
* Use serper.dev to search on Google.
*
* **Requires an SERPER_API_KEY environment variable**.
*
* @param query
* @param options
* @returns
*/ | https://github.com/wladpaiva/aibitat/blob/d66dfddae5c7b8c974cbee442707a04635333181/src/plugins/web-browsing.ts#L18-L47 | d66dfddae5c7b8c974cbee442707a04635333181 |
aibitat | github_2023 | wladpaiva | typescript | AnthropicProvider.complete | async complete(
messages: Provider.Message[],
functions?: AIbitat.FunctionDefinition[],
): Promise<Provider.Completion> {
// clone messages to avoid mutating the original array
const promptMessages = [...messages]
if (functions) {
const functionPrompt = this.getFunctionPrompt(functions)
... | /**
* Create a completion based on the received messages.
*
* @param messages A list of messages to send to the Anthropic API.
* @param functions
* @returns The completion.
*/ | https://github.com/wladpaiva/aibitat/blob/d66dfddae5c7b8c974cbee442707a04635333181/src/providers/anthropic.ts#L58-L156 | d66dfddae5c7b8c974cbee442707a04635333181 |
aibitat | github_2023 | wladpaiva | typescript | OpenAIProvider.complete | async complete(
messages: OpenAI.ChatCompletionMessageParam[],
functions?: AIbitat.FunctionDefinition[],
): Promise<Provider.Completion> {
try {
const response = await this.client.chat.completions.create({
model: this.model,
// stream: true,
messages,
functions,
... | /**
* Create a completion based on the received messages.
*
* @param messages A list of messages to send to the OpenAI API.
* @param functions
* @returns The completion.
*/ | https://github.com/wladpaiva/aibitat/blob/d66dfddae5c7b8c974cbee442707a04635333181/src/providers/openai.ts#L76-L138 | d66dfddae5c7b8c974cbee442707a04635333181 |
aibitat | github_2023 | wladpaiva | typescript | OpenAIProvider.getCost | getCost(usage: OpenAI.Completions.CompletionUsage | undefined) {
if (!usage) {
return Number.NaN
}
// regex to remove the version number from the model
const modelBase = this.model.replace(/-(\d{4})$/, '')
if (!(modelBase in OpenAIProvider.COST_PER_TOKEN)) {
return Number.NaN
}
... | /**
* Get the cost of the completion.
*
* @param usage The completion to get the cost for.
* @returns The cost of the completion.
*/ | https://github.com/wladpaiva/aibitat/blob/d66dfddae5c7b8c974cbee442707a04635333181/src/providers/openai.ts#L146-L167 | d66dfddae5c7b8c974cbee442707a04635333181 |
mini-canvas-editor | github_2023 | img-js | typescript | MceCanvasReplacer.replaceRectToImage | public async replaceRectToImage(
layer: MceLayer,
sourceImage: HTMLImageElement | string,
mode: 'stretch' | 'fit' | 'fill'
): Promise<void> {
const rect = this.objects[layer.realIndex] as MceRect;
if (!rect.visible) {
// If the layer is hidden, do nothing.
return;
}
if (typeof sourceImage === 'stri... | /**
* Replace rectangle to image.
* @param layer Layer.
* @param sourceImage Image element or URL (for example data URL: `data:image/png;base64,...`).
* @param mode Mode of fitting image to the rectangle.
* @returns Promise that resolves when the rect is replaced.
*/ | https://github.com/img-js/mini-canvas-editor/blob/17f21019bdac5a40d09fcdaaacd56915a8c356f6/core/src/replacer/mce-canvas-replacer.ts#L40-L71 | 17f21019bdac5a40d09fcdaaacd56915a8c356f6 |
mini-canvas-editor | github_2023 | img-js | typescript | MceImage.toObject | public toObject(propertiesToInclude: string[] = []) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return super.toObject(propertiesToInclude.concat(['label', 'selectable']) as any);
} | // @ts-expect-error TS this typing limitations | https://github.com/img-js/mini-canvas-editor/blob/17f21019bdac5a40d09fcdaaacd56915a8c356f6/core/src/shapes/mce-image.ts#L18-L21 | 17f21019bdac5a40d09fcdaaacd56915a8c356f6 |
mini-canvas-editor | github_2023 | img-js | typescript | McePath.constructor | public constructor(path: any, options: TOptions<McePathProps>) {
super(path, {
label: 'Path',
...options
});
} | // eslint-disable-next-line @typescript-eslint/no-explicit-any | https://github.com/img-js/mini-canvas-editor/blob/17f21019bdac5a40d09fcdaaacd56915a8c356f6/core/src/shapes/mce-path.ts#L15-L20 | 17f21019bdac5a40d09fcdaaacd56915a8c356f6 |
mini-canvas-editor | github_2023 | img-js | typescript | McePath.toObject | public toObject(propertiesToInclude: string[] = []) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return super.toObject(propertiesToInclude.concat(['label', 'selectable']) as any);
} | // @ts-expect-error TS this typing limitations | https://github.com/img-js/mini-canvas-editor/blob/17f21019bdac5a40d09fcdaaacd56915a8c356f6/core/src/shapes/mce-path.ts#L23-L26 | 17f21019bdac5a40d09fcdaaacd56915a8c356f6 |
mini-canvas-editor | github_2023 | img-js | typescript | MceRect.toObject | public toObject(propertiesToInclude: string[] = []) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return super.toObject(propertiesToInclude.concat(['label', 'selectable']) as any);
} | // @ts-expect-error TS this typing limitations | https://github.com/img-js/mini-canvas-editor/blob/17f21019bdac5a40d09fcdaaacd56915a8c356f6/core/src/shapes/mce-rect.ts#L33-L36 | 17f21019bdac5a40d09fcdaaacd56915a8c356f6 |
mini-canvas-editor | github_2023 | img-js | typescript | MceTextbox.toObject | public toObject(propertiesToInclude: string[] = []) {
return super.toObject(
propertiesToInclude.concat([
'label',
'selectable',
'verticalAlign',
'maxHeight',
'verticalAlign',
'textBackground',
'textBackgroundFill'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
])... | // @ts-expect-error TS this typing limitations | https://github.com/img-js/mini-canvas-editor/blob/17f21019bdac5a40d09fcdaaacd56915a8c356f6/core/src/shapes/mce-textbox.ts#L115-L128 | 17f21019bdac5a40d09fcdaaacd56915a8c356f6 |
mesop | github_2023 | google | typescript | AutocompleteComponent._filter | private _filter(
value: string,
options: readonly AutocompleteOptionSet[],
): readonly AutocompleteOptionSet[] {
if (!value) {
return options;
}
const filterValue = value.toLowerCase();
const filteredOptions = new Array<AutocompleteOptionSet>();
for (const option of options) {
... | /**
* Filters the autocomplete options based on the current input.
*
* The filtering will perform a case-insensitive substring match against the
* options labels.
*
* @param value Value of the input
* @param options Autocomplete options
* @returns
*/ | https://github.com/google/mesop/blob/270a3fa90c31cebefc2202b65ea91194d5bf255e/mesop/components/autocomplete/autocomplete.ts#L150-L182 | 270a3fa90c31cebefc2202b65ea91194d5bf255e |
mesop | github_2023 | google | typescript | DateRangePickerComponent.onChangeDebounced | onChangeDebounced(
event: MatDatepickerInputEvent<
string | undefined,
DateRange<string | undefined>
>,
): void {
if (this.dateRange.value.start && this.dateRange.value.end) {
const userEvent = new UserEvent();
userEvent.setHandlerId(this.config().getOnChangeHandlerId()!);
co... | // event if the end date is also set. | https://github.com/google/mesop/blob/270a3fa90c31cebefc2202b65ea91194d5bf255e/mesop/components/date_range_picker/date_range_picker.ts#L112-L130 | 270a3fa90c31cebefc2202b65ea91194d5bf255e |
mesop | github_2023 | google | typescript | ComponentRenderer.getStyle | getStyle(): string {
if (!this._boxType) {
return '';
}
let style = '';
if (this.component.getStyle()) {
style += formatStyle(this.component.getStyle()!);
}
return style;
} | ////////////// | https://github.com/google/mesop/blob/270a3fa90c31cebefc2202b65ea91194d5bf255e/mesop/web/src/component_renderer/component_renderer.ts#L308-L319 | 270a3fa90c31cebefc2202b65ea91194d5bf255e |
mesop | github_2023 | google | typescript | setIframeSrcImpl | function setIframeSrcImpl(iframe: HTMLIFrameElement, src: string) {
// This is a tightly controlled list of attributes that enables us to
// secure sandbox iframes. Do not add additional attributes without
// consulting a security resource.
//
// Ref:
// https://developer.mozilla.org/en-US/docs/Web/HTML/Ele... | // copybara:strip_begin(external-only) | https://github.com/google/mesop/blob/270a3fa90c31cebefc2202b65ea91194d5bf255e/mesop/web/src/safe_iframe/safe_iframe.ts#L18-L35 | 270a3fa90c31cebefc2202b65ea91194d5bf255e |
mesop | github_2023 | google | typescript | reportJavaScriptUrl | function reportJavaScriptUrl(url: string): boolean {
const hasJavascriptUrlScheme = !IS_NOT_JAVASCRIPT_URL_PATTERN.test(url);
if (hasJavascriptUrlScheme) {
console.error(`A URL with content '${url}' was sanitized away.`);
}
return hasJavascriptUrlScheme;
} | /**
* Checks whether a urls has a `javascript:` scheme.
* If the url has a `javascript:` scheme, reports it and returns true.
* Otherwise, returns false.
*/ | https://github.com/google/mesop/blob/270a3fa90c31cebefc2202b65ea91194d5bf255e/mesop/web/src/safe_iframe/sanitize_javascript_url.ts#L36-L42 | 270a3fa90c31cebefc2202b65ea91194d5bf255e |
mesop | github_2023 | google | typescript | Channel.isBusy | isBusy(): boolean {
if (this.experimentService.websocketsEnabled) {
// When WebSockets are enabled, we disable the busy indicator
// because it's possible for the server to push new data
// at any point. Apps should use their own loading indicators
// instead.
return false;
}
r... | /**
* Return true if the channel has been doing work
* triggered by a user that's been taking a while.
*/ | https://github.com/google/mesop/blob/270a3fa90c31cebefc2202b65ea91194d5bf255e/mesop/web/src/services/channel.ts#L93-L102 | 270a3fa90c31cebefc2202b65ea91194d5bf255e |
mesop | github_2023 | google | typescript | Shell.maybeExecuteScrollCommand | maybeExecuteScrollCommand() {
if (this.commandScrollKey) {
const scrollKey = this.commandScrollKey;
this.commandScrollKey = '';
const targetElements = document.querySelectorAll(
`[data-key="${scrollKey}"]`,
);
if (!targetElements.length) {
console.error(
`Coul... | // Executes the scroll command if a key has been specified. | https://github.com/google/mesop/blob/270a3fa90c31cebefc2202b65ea91194d5bf255e/mesop/web/src/shell/shell.ts#L246-L272 | 270a3fa90c31cebefc2202b65ea91194d5bf255e |
mesop | github_2023 | google | typescript | updateValue | function updateValue(root: object, path: (string | number)[], value: any) {
let objectSegment = root;
for (let i = 0; i < path.length; ++i) {
if (i + 1 === path.length) {
// @ts-ignore: Ignore type
objectSegment[path[i]] = value;
} else {
// @ts-ignore: Ignore type
objectSegment = ob... | // Updates value at path. | https://github.com/google/mesop/blob/270a3fa90c31cebefc2202b65ea91194d5bf255e/mesop/web/src/utils/diff.ts#L141-L152 | 270a3fa90c31cebefc2202b65ea91194d5bf255e |
mesop | github_2023 | google | typescript | addArrayValue | function addArrayValue(root: object, path: (string | number)[], value: any) {
const objectSegment = getLastObjectSegment(root, path);
if (objectSegment) {
// @ts-ignore: Ignore type
objectSegment.splice(path[path.length - 1], 0, value);
}
} | // Adds item to the array at path. | https://github.com/google/mesop/blob/270a3fa90c31cebefc2202b65ea91194d5bf255e/mesop/web/src/utils/diff.ts#L155-L161 | 270a3fa90c31cebefc2202b65ea91194d5bf255e |
mesop | github_2023 | google | typescript | removeArrayValue | function removeArrayValue(root: object, path: (string | number)[]) {
let objectSegment = root;
for (let i = 0; i < path.length; ++i) {
if (i + 1 === path.length) {
// @ts-ignore: Ignore type
objectSegment.splice(path[i], 1);
} else {
// @ts-ignore: Ignore type
objectSegment = objectS... | // Removes item from array at path. | https://github.com/google/mesop/blob/270a3fa90c31cebefc2202b65ea91194d5bf255e/mesop/web/src/utils/diff.ts#L164-L175 | 270a3fa90c31cebefc2202b65ea91194d5bf255e |
mesop | github_2023 | google | typescript | addSetValue | function addSetValue(root: object, path: (string | number)[], value: any) {
const objectSegment = getLastObjectSegment(root, path);
if (objectSegment) {
// @ts-ignore: Ignore type
objectSegment[path[path.length - 1]].push(value);
}
} | // Adds item from the set at path. | https://github.com/google/mesop/blob/270a3fa90c31cebefc2202b65ea91194d5bf255e/mesop/web/src/utils/diff.ts#L178-L184 | 270a3fa90c31cebefc2202b65ea91194d5bf255e |
mesop | github_2023 | google | typescript | removeSetValue | function removeSetValue(root: object, path: (string | number)[], value: any) {
const objectSegment = getLastObjectSegment(root, path);
if (objectSegment) {
// @ts-ignore: Ignore type
const set = new Set(objectSegment[path[path.length - 1]]);
set.delete(value);
// @ts-ignore: Ignore type
objectSe... | // Removes item from the set at path. | https://github.com/google/mesop/blob/270a3fa90c31cebefc2202b65ea91194d5bf255e/mesop/web/src/utils/diff.ts#L187-L196 | 270a3fa90c31cebefc2202b65ea91194d5bf255e |
mesop | github_2023 | google | typescript | updateObjectValue | function updateObjectValue(
root: object,
path: (string | number)[],
value: any,
) {
let objectSegment = root;
for (let i = 0; i < path.length; ++i) {
if (i + 1 === path.length) {
// @ts-ignore: Ignore type
objectSegment[path[i]] = value;
} else {
// @ts-ignore: Ignore type
obj... | // Adds/Updates value to object at path. | https://github.com/google/mesop/blob/270a3fa90c31cebefc2202b65ea91194d5bf255e/mesop/web/src/utils/diff.ts#L199-L214 | 270a3fa90c31cebefc2202b65ea91194d5bf255e |
mesop | github_2023 | google | typescript | removeObjectValue | function removeObjectValue(root: object, path: (string | number)[]) {
let objectSegment = root;
for (let i = 0; i < path.length; ++i) {
if (i + 1 === path.length) {
// @ts-ignore: Ignore type
delete objectSegment[path[i]];
} else {
// @ts-ignore: Ignore type
objectSegment = objectSeg... | // Removes value from object at path. | https://github.com/google/mesop/blob/270a3fa90c31cebefc2202b65ea91194d5bf255e/mesop/web/src/utils/diff.ts#L217-L228 | 270a3fa90c31cebefc2202b65ea91194d5bf255e |
mesop | github_2023 | google | typescript | getLastObjectSegment | function getLastObjectSegment(
root: object,
path: (string | number)[],
): object | null {
let objectSegment = root;
for (let i = 0; i < path.length; ++i) {
if (i + 1 === path.length) {
return objectSegment;
}
// Edge case where the array does not exist yet, so we need to create an array
/... | // Helper function for retrieving the last segment from a given path. | https://github.com/google/mesop/blob/270a3fa90c31cebefc2202b65ea91194d5bf255e/mesop/web/src/utils/diff.ts#L231-L252 | 270a3fa90c31cebefc2202b65ea91194d5bf255e |
mesop | github_2023 | google | typescript | processBuildAction | async function processBuildAction(args: string[]) {
const {loadPath, style, sourceMap, embedSources, inputExecpath, outExecpath} =
await yargs(args)
.showHelpOnFail(false)
.strict()
.parserConfiguration({'greedy-arrays': false})
.command('$0 <inputExecpath> <outExecpath>', 'Compiles a Sass... | /**
* Processes a build action expressed through command line arguments
* as composed by the `sass_binary` rule.
*/ | https://github.com/google/mesop/blob/270a3fa90c31cebefc2202b65ea91194d5bf255e/tools/sass/compiler-main.ts#L53-L78 | 270a3fa90c31cebefc2202b65ea91194d5bf255e |
UptimeFlare | github_2023 | lyc8503 | typescript | formatAndNotify | let formatAndNotify = async (
monitor: any,
isUp: boolean,
timeIncidentStart: number,
timeNow: number,
reason: string
) => {
if (workerConfig.notification?.appriseApiServer && workerConfig.notification?.recipientUrl) {
const notification = formatStatusChangeNotification(
... | // Auxiliary function to format notification and send it via apprise | https://github.com/lyc8503/UptimeFlare/blob/07618a56386ae146ee218ccf69fb3f9152bb42bb/worker/src/index.ts#L46-L71 | 07618a56386ae146ee218ccf69fb3f9152bb42bb |
shipfast | github_2023 | vietanhdev | typescript | ApplicationMultipleTargetGroupsFargateService.constructor | constructor(
scope: Construct,
id: string,
props: ApplicationMultipleTargetGroupsFargateServiceProps
) {
super(scope, id, props);
this.logGroups = [];
this.assignPublicIp = props.assignPublicIp ?? false;
if (props.taskDefinition && props.taskImageOptions) {
throw new Error(
... | /**
* Constructs a new instance of the ApplicationMultipleTargetGroupsFargateService class.
*/ | https://github.com/vietanhdev/shipfast/blob/49707acf1cf69a561f35ade112a1376a29c57e8a/packages/infra/infra-core/src/lib/patterns/applicationMultipleTargetGroupsFargateService.ts#L149-L221 | 49707acf1cf69a561f35ade112a1376a29c57e8a |
shipfast | github_2023 | vietanhdev | typescript | customRender | function customRender<
Q extends Queries = typeof queries,
Container extends Element | DocumentFragment = HTMLElement,
BaseElement extends Element | DocumentFragment = Container
>(
ui: ReactElement,
options: CustomRenderOptions<Q, Container, BaseElement> = {}
): RenderResult<Q, Container, BaseElement> & { wai... | /**
* Method that extends [`render`](https://testing-library.com/docs/react-testing-library/api#render) method from
* `@testing-library/react` package. It composes a wrapper using [`ApiTestProviders`](#apitestprovidersprops) component
* and `options` property that is passed down to parent `render` method. It also ex... | https://github.com/vietanhdev/shipfast/blob/49707acf1cf69a561f35ade112a1376a29c57e8a/packages/webapp-libs/webapp-api-client/src/tests/utils/rendering.tsx#L114-L131 | 49707acf1cf69a561f35ade112a1376a29c57e8a |
shipfast | github_2023 | vietanhdev | typescript | customRenderHook | function customRenderHook<Result, Props>(hook: (initialProps: Props) => Result, options: CustomRenderOptions = {}) {
const { wrapper, waitForApolloMocks } = getWrapper(ApiTestProviders, options);
return {
...renderHook(hook, {
...options,
wrapper,
}),
waitForApolloMocks,
};
} | /**
* Method that extends [`renderHook`](https://testing-library.com/docs/react-testing-library/api#renderhook) method from
* `@testing-library/react` package. It composes a wrapper using [`ApiTestProviders`](#apitestprovidersprops) component
* and `options` property that is passed down to parent `renderHook` method... | https://github.com/vietanhdev/shipfast/blob/49707acf1cf69a561f35ade112a1376a29c57e8a/packages/webapp-libs/webapp-api-client/src/tests/utils/rendering.tsx#L141-L151 | 49707acf1cf69a561f35ade112a1376a29c57e8a |
shipfast | github_2023 | vietanhdev | typescript | customRender | function customRender<
Q extends Queries = typeof queries,
Container extends Element | DocumentFragment = HTMLElement,
BaseElement extends Element | DocumentFragment = Container
>(
ui: ReactElement,
options: CustomRenderOptions<Q, Container, BaseElement> = {}
): RenderResult<Q, Container, BaseElement> {
con... | /**
* Method that extends [`render`](https://testing-library.com/docs/react-testing-library/api#render) method from
* `@testing-library/react` package. It composes a wrapper using [`CoreTestProviders`](#coretestproviders) component and
* `options` property that is passed down to parent `render` method.
* @param ui
... | https://github.com/vietanhdev/shipfast/blob/49707acf1cf69a561f35ade112a1376a29c57e8a/packages/webapp-libs/webapp-core/src/tests/utils/rendering.tsx#L95-L111 | 49707acf1cf69a561f35ade112a1376a29c57e8a |
shipfast | github_2023 | vietanhdev | typescript | customRenderHook | function customRenderHook<Result, Props>(hook: (initialProps: Props) => Result, options: CustomRenderOptions = {}) {
const { wrapper } = getWrapper(CoreTestProviders, options);
return {
...renderHook(hook, {
...options,
wrapper,
}),
};
} | /**
* Method that extends [`renderHook`](https://testing-library.com/docs/react-testing-library/api#renderhook) method from
* `@testing-library/react` package. It composes a wrapper using [`CoreTestProviders`](#coretestproviders) component and
* `options` property that is passed down to parent `renderHook` method.
... | https://github.com/vietanhdev/shipfast/blob/49707acf1cf69a561f35ade112a1376a29c57e8a/packages/webapp-libs/webapp-core/src/tests/utils/rendering.tsx#L120-L129 | 49707acf1cf69a561f35ade112a1376a29c57e8a |
shipfast | github_2023 | vietanhdev | typescript | updateOrCreatePaymentIntent | const updateOrCreatePaymentIntent = async (
product: TestProduct
): Promise<{ errors?: readonly GraphQLError[]; paymentIntent?: StripePaymentIntentType | null }> => {
if (!paymentIntent) {
const { data, errors } = await commitCreatePaymentIntentMutation({
variables: {
input: {
... | /**
* This function is responsible for creating a new payment intent and updating it if it has been created before.
*
* @param product This product will be passed to the payment intent create and update API endpoints. Backend should
* handle amount and currency update based on the ID of this product.
*/ | https://github.com/vietanhdev/shipfast/blob/49707acf1cf69a561f35ade112a1376a29c57e8a/packages/webapp-libs/webapp-finances/src/components/stripe/stripePayment.hooks.ts#L95-L127 | 49707acf1cf69a561f35ade112a1376a29c57e8a |
shipfast | github_2023 | vietanhdev | typescript | customRender | function customRender(ui: ReactElement, options: CustomRenderOptions = {}) {
const { wrapper, waitForApolloMocks } = getWrapper(apiUtils.ApiTestProviders, options);
return {
...render(ui, {
...options,
wrapper,
}),
waitForApolloMocks,
};
} | /**
* Method that extends [`render`](https://testing-library.com/docs/react-testing-library/api#render) method from
* `@testing-library/react` package. It composes a wrapper using `ApiTestProviders` component from
* `@shipfast/webapp-api-client/tests/utils/rendering` package and `options` property that is passed dow... | https://github.com/vietanhdev/shipfast/blob/49707acf1cf69a561f35ade112a1376a29c57e8a/packages/webapp/src/tests/utils/rendering.tsx#L70-L80 | 49707acf1cf69a561f35ade112a1376a29c57e8a |
shipfast | github_2023 | vietanhdev | typescript | customRenderHook | function customRenderHook<Result, Props>(hook: (initialProps: Props) => Result, options: CustomRenderOptions = {}) {
const { wrapper, waitForApolloMocks } = getWrapper(apiUtils.ApiTestProviders, options);
return {
...renderHook(hook, {
...options,
wrapper,
}),
waitForApolloMocks,
};
} | /**
* Method that extends [`renderHook`](https://testing-library.com/docs/react-testing-library/api#renderhook) method from
* `@testing-library/react` package. It composes a wrapper using `ApiTestProviders` component from
* `@shipfast/webapp-api-client/tests/utils/rendering` package and `options` property that is pa... | https://github.com/vietanhdev/shipfast/blob/49707acf1cf69a561f35ade112a1376a29c57e8a/packages/webapp/src/tests/utils/rendering.tsx#L92-L102 | 49707acf1cf69a561f35ade112a1376a29c57e8a |
MiniSearch | github_2023 | felladrin | typescript | cacheSearchWithIndexedDB | function cacheSearchWithIndexedDB<
T extends ImageSearchResults | TextSearchResults,
>(
fn: (query: string, limit?: number) => Promise<T>,
storeName: string,
): (query: string, limit?: number) => Promise<T> {
const databaseVersion = 2;
const timeToLive = 15 * 60 * 1000;
async function openDB(): Promise<IDB... | /**
* Creates a cached version of a search function using IndexedDB for storage.
*
* @param fn - The original search function to be cached.
* @returns A new function that wraps the original, adding caching functionality.
*
* This function implements a caching mechanism for search results using IndexedDB.
* It st... | https://github.com/felladrin/MiniSearch/blob/f757e0f61eef7d663bc5a77a27ef170aa9a97295/client/modules/search.ts#L31-L168 | f757e0f61eef7d663bc5a77a27ef170aa9a97295 |
MiniSearch | github_2023 | felladrin | typescript | hashQuery | function hashQuery(query: string): string {
return query
.split("")
.reduce((acc, char) => ((acc << 5) - acc + char.charCodeAt(0)) | 0, 0)
.toString(36);
} | /**
* Generates a hash for a given query string.
*
* This function implements a simple hash algorithm:
* 1. It iterates through each character in the query string.
* 2. For each character, it updates the hash value using bitwise operations.
* 3. The final hash is converted to a 32-bit integer.
* 4.... | https://github.com/felladrin/MiniSearch/blob/f757e0f61eef7d663bc5a77a27ef170aa9a97295/client/modules/search.ts#L114-L119 | f757e0f61eef7d663bc5a77a27ef170aa9a97295 |
MiniSearch | github_2023 | felladrin | typescript | streamTextInChunks | function streamTextInChunks(
text: string,
updateCallback: (text: string) => void,
chunkSize = 3,
delayMs = 60,
): void {
const words = text.split(" ");
let accumulatedText = "";
let i = 0;
const intervalId = setInterval(() => {
const chunk = words.slice(i, i + chunkSize).join(" ");
accumulated... | /**
* Streams text in small chunks with a delay between each chunk for a smooth reading experience.
* @param text The text to stream
* @param updateCallback Function to call with each chunk of text
* @param chunkSize Number of words per chunk (default: 3)
* @param delayMs Delay between chunks in milliseconds (defa... | https://github.com/felladrin/MiniSearch/blob/f757e0f61eef7d663bc5a77a27ef170aa9a97295/client/modules/textGenerationWithHorde.ts#L228-L247 | f757e0f61eef7d663bc5a77a27ef170aa9a97295 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | getHue | function getHue(hsv: HsvColor, i: number, isLight: boolean) {
let hue: number;
const hsvH = Math.round(hsv.h);
if (hsvH >= 60 && hsvH <= 240) {
hue = isLight ? hsvH - hueStep * i : hsvH + hueStep * i;
} else {
hue = isLight ? hsvH + hueStep * i : hsvH - hueStep * i;
}
if (hue < 0) {
hue += 36... | /**
* Get hue
*
* @param hsv - Hsv format color
* @param i - The relative distance from 6
* @param isLight - Is light color
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/packages/color/src/palette/antd.ts#L96-L116 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | getSaturation | function getSaturation(hsv: HsvColor, i: number, isLight: boolean) {
if (hsv.h === 0 && hsv.s === 0) {
return hsv.s;
}
let saturation: number;
if (isLight) {
saturation = hsv.s - saturationStep * i;
} else if (i === darkColorCount) {
saturation = hsv.s + saturationStep;
} else {
saturation... | /**
* Get saturation
*
* @param hsv - Hsv format color
* @param i - The relative distance from 6
* @param isLight - Is light color
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/packages/color/src/palette/antd.ts#L125-L153 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | getValue | function getValue(hsv: HsvColor, i: number, isLight: boolean) {
let value: number;
if (isLight) {
value = hsv.v + brightnessStep1 * i;
} else {
value = hsv.v - brightnessStep2 * i;
}
if (value > 100) {
value = 100;
}
return value;
} | /**
* Get value of hsv
*
* @param hsv - Hsv format color
* @param i - The relative distance from 6
* @param isLight - Is light color
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/packages/color/src/palette/antd.ts#L162-L176 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | getNearestColorPaletteFamily | function getNearestColorPaletteFamily(color: string, families: ColorPaletteFamily[]) {
const familyWithConfig = families.map(family => {
const palettes = family.palettes.map(palette => {
return {
...palette,
delta: getDeltaE(color, palette.hex)
};
});
const nearestPalette = pa... | /**
* get nearest color palette family
*
* @param color color
* @param families color palette families
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/packages/color/src/palette/recommend.ts#L114-L152 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | createContext | function createContext<T>(contextName: string) {
const injectKey: InjectionKey<T> = Symbol(contextName);
function useProvide(context: T) {
provide(injectKey, context);
return context;
}
function useInject() {
return inject(injectKey) as T;
}
return {
useProvide,
useInject
};
} | /** Create context */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/packages/hooks/src/use-context.ts#L79-L96 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | SvgIconVNode | const SvgIconVNode = (config: IconConfig) => {
const { color, fontSize, icon, localIcon } = config;
const style: IconStyle = {};
if (color) {
style.color = color;
}
if (fontSize) {
style.fontSize = `${fontSize}px`;
}
if (!icon && !localIcon) {
return undefined;
}
... | /**
* Svg icon VNode
*
* @param config
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/packages/hooks/src/use-svg-icon-render.ts#L28-L45 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | updateSearchParams | function updateSearchParams(params: Partial<Parameters<A>[0]>) {
Object.assign(searchParams, params);
} | /**
* update search params
*
* @param params
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/packages/hooks/src/use-table.ts#L127-L129 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | resetSearchParams | function resetSearchParams() {
Object.assign(searchParams, jsonClone(apiParams));
} | /** reset search params */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/packages/hooks/src/use-table.ts#L132-L134 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | createLayoutCssVarsByCssVarsProps | function createLayoutCssVarsByCssVarsProps(props: LayoutCssVarsProps) {
const cssVars: LayoutCssVars = {
'--soy-header-height': `${props.headerHeight}px`,
'--soy-header-z-index': props.headerZIndex,
'--soy-tab-height': `${props.tabHeight}px`,
'--soy-tab-z-index': props.tabZIndex,
'--soy-sider-widt... | /**
* Create layout css vars by css vars props
*
* @param props Css vars props
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/packages/materials/src/libs/admin-layout/shared.ts#L14-L29 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | getHue | function getHue(hsv: HsvColor, i: number, isLight: boolean) {
let hue: number;
const hsvH = Math.round(hsv.h);
if (hsvH >= 60 && hsvH <= 240) {
hue = isLight ? hsvH - hueStep * i : hsvH + hueStep * i;
} else {
hue = isLight ? hsvH + hueStep * i : hsvH - hueStep * i;
}
if (hue < 0) {
hue += 36... | /**
* Get hue
*
* @param hsv - Hsv format color
* @param i - The relative distance from 6
* @param isLight - Is light color
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/packages/utils/src/color.ts#L172-L192 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | getSaturation | function getSaturation(hsv: HsvColor, i: number, isLight: boolean) {
if (hsv.h === 0 && hsv.s === 0) {
return hsv.s;
}
let saturation: number;
if (isLight) {
saturation = hsv.s - saturationStep * i;
} else if (i === darkColorCount) {
saturation = hsv.s + saturationStep;
} else {
saturation... | /**
* Get saturation
*
* @param hsv - Hsv format color
* @param i - The relative distance from 6
* @param isLight - Is light color
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/packages/utils/src/color.ts#L201-L229 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | getValue | function getValue(hsv: HsvColor, i: number, isLight: boolean) {
let value: number;
if (isLight) {
value = hsv.v + brightnessStep1 * i;
} else {
value = hsv.v - brightnessStep2 * i;
}
if (value > 100) {
value = 100;
}
return value;
} | /**
* Get value of hsv
*
* @param hsv - Hsv format color
* @param i - The relative distance from 6
* @param isLight - Is light color
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/packages/utils/src/color.ts#L238-L252 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | canRender | function canRender() {
return domRef.value && initialSize.width > 0 && initialSize.height > 0;
} | /**
* whether can render chart
*
* when domRef is ready and initialSize is valid
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/hooks/common/echarts.ts#L119-L121 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | isRendered | function isRendered() {
return Boolean(domRef.value && chart);
} | /** is chart rendered */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/hooks/common/echarts.ts#L124-L126 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | updateOptions | async function updateOptions(callback: (opts: T, optsFactory: () => T) => ECOption = () => chartOptions) {
if (!isRendered()) return;
const updatedOpts = callback(chartOptions, optionsFactory);
Object.assign(chartOptions, updatedOpts);
if (isRendered()) {
chart?.clear();
}
chart?.setOp... | /**
* update chart options
*
* @param callback callback function
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/hooks/common/echarts.ts#L133-L147 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | render | async function render() {
if (!isRendered()) {
const chartTheme = darkMode.value ? 'dark' : 'light';
await nextTick();
chart = echarts.init(domRef.value, chartTheme);
chart.setOption({ ...chartOptions, backgroundColor: 'transparent' });
await onRender?.(chart);
}
} | /** render chart */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/hooks/common/echarts.ts#L154-L166 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | resize | function resize() {
chart?.resize();
} | /** resize chart */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/hooks/common/echarts.ts#L169-L171 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | destroy | async function destroy() {
if (!chart) return;
await onDestroy?.(chart);
chart?.dispose();
chart = null;
} | /** destroy chart */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/hooks/common/echarts.ts#L174-L180 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | changeTheme | async function changeTheme() {
await destroy();
await render();
await onUpdated?.(chart!);
} | /** change chart theme */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/hooks/common/echarts.ts#L183-L187 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | renderChartBySize | async function renderChartBySize(w: number, h: number) {
initialSize.width = w;
initialSize.height = h;
// size is abnormal, destroy chart
if (!canRender()) {
await destroy();
return;
}
// resize chart
if (isRendered()) {
resize();
}
// render chart
await re... | /**
* render chart by size
*
* @param w width
* @param h height
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/hooks/common/echarts.ts#L195-L213 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | createConfirmPwdRule | function createConfirmPwdRule(pwd: string | Ref<string> | ComputedRef<string>) {
const confirmPwdRule: App.Global.FormRule[] = [
{ required: true, message: $t('form.confirmPwd.required') },
{
validator: (rule, value) => {
if (value.trim() !== '' && value !== toValue(pwd)) {
... | /** create a rule for confirming the password */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/hooks/common/form.ts#L55-L70 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | toLogin | async function toLogin(loginModule?: UnionKey.LoginModule, redirectUrl?: string) {
const module = loginModule || 'pwd-login';
const options: RouterPushOptions = {
params: {
module
}
};
const redirect = redirectUrl || route.value.fullPath;
options.query = {
redirect
}... | /**
* Navigate to login page
*
* @param loginModule The login module
* @param redirectUrl The redirect url, if not specified, it will be the current route fullPath
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/hooks/common/router.ts#L67-L83 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | toggleLoginModule | async function toggleLoginModule(module: UnionKey.LoginModule) {
const query = route.value.query as Record<string, string>;
return routerPushByKey('login', { query, params: { module } });
} | /**
* Toggle login module
*
* @param module
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/hooks/common/router.ts#L90-L94 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | redirectFromLogin | async function redirectFromLogin(needRedirect = true) {
const redirect = route.value.query?.redirect as string;
if (needRedirect && redirect) {
await routerPush(redirect);
} else {
await toHome();
}
} | /**
* Redirect from login
*
* @param [needRedirect=true] Whether to redirect after login. Default is `true`
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/hooks/common/router.ts#L101-L109 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | getDataByPage | async function getDataByPage(pageNum: number = 1) {
updatePagination({
current: pageNum
});
updateSearchParams({
current: pageNum,
size: pagination.pageSize!
});
await getData();
} | /**
* get data by page number
*
* @param pageNum the page number. default is 1
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/hooks/common/table.ts#L135-L146 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | onBatchDeleted | async function onBatchDeleted() {
window.$message?.success($t('common.deleteSuccess'));
checkedRowKeys.value = [];
await getData();
} | /** the hook after the batch delete operation is completed */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/hooks/common/table.ts#L217-L223 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | onDeleted | async function onDeleted() {
window.$message?.success($t('common.deleteSuccess'));
await getData();
} | /** the hook after the delete operation is completed */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/hooks/common/table.ts#L226-L230 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | transformElegantRouteToVueRoute | function transformElegantRouteToVueRoute(
route: ElegantConstRoute,
layouts: Record<string, RouteComponent | (() => Promise<RouteComponent>)>,
views: Record<string, RouteComponent | (() => Promise<RouteComponent>)>
) {
const LAYOUT_PREFIX = 'layout.';
const VIEW_PREFIX = 'view.';
const ROUTE_DEGREE_SPLITTER... | /**
* transform elegant route to vue route
* @param route elegant const route
* @param layouts layout components
* @param views view components
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/router/elegant/transform.ts#L30-L158 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | initRoute | async function initRoute(to: RouteLocationNormalized): Promise<RouteLocationRaw | null> {
const routeStore = useRouteStore();
const notFoundRoute: RouteKey = 'not-found';
const isNotFoundRoute = to.name === notFoundRoute;
// if the constant route is not initialized, then initialize the constant route
if (!r... | /**
* initialize route
*
* @param to to route
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/router/guard/route.ts#L75-L162 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | handleRefreshToken | async function handleRefreshToken() {
const { resetStore } = useAuthStore();
const rToken = localStg.get('refreshToken') || '';
const { error, data } = await fetchRefreshToken(rToken);
if (!error) {
localStg.set('token', data.token);
localStg.set('refreshToken', data.refreshToken);
return true;
}... | /** refresh token */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/service/request/shared.ts#L14-L28 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | reloadPage | async function reloadPage(duration = 300) {
setReloadFlag(false);
const d = themeStore.page.animate ? duration : 40;
await new Promise(resolve => {
setTimeout(resolve, d);
});
setReloadFlag(true);
if (themeStore.resetCacheStrategy === 'refresh') {
routeStore.resetRouteCache();
... | /**
* Reload page
*
* @param duration Duration time
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/app/index.ts#L39-L53 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | updateDocumentTitleByLocale | function updateDocumentTitleByLocale() {
const { i18nKey, title } = router.currentRoute.value.meta;
const documentTitle = i18nKey ? $t(i18nKey) : title;
useTitle(documentTitle);
} | /** Update document title by locale */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/app/index.ts#L75-L81 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | resetStore | async function resetStore() {
const authStore = useAuthStore();
clearAuthStorage();
authStore.$reset();
if (!route.meta.constant) {
await toLogin();
}
tabStore.cacheTabs();
routeStore.resetStore();
} | /** Reset auth store */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/auth/index.ts#L41-L54 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | login | async function login(userName: string, password: string, redirect = true) {
startLoading();
const { data: loginToken, error } = await fetchLogin(userName, password);
if (!error) {
const pass = await loginByToken(loginToken);
if (pass) {
await redirectFromLogin(redirect);
wind... | /**
* Login
*
* @param userName User name
* @param password Password
* @param [redirect=true] Whether to redirect after login. Default is `true`
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/auth/index.ts#L63-L84 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | setRouteHome | function setRouteHome(routeKey: LastLevelRouteKey) {
routeHome.value = routeKey;
} | /**
* Set route home
*
* @param routeKey Route key
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/route/index.ts#L49-L51 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | getGlobalMenus | function getGlobalMenus(routes: ElegantConstRoute[]) {
menus.value = getGlobalMenusByAuthRoutes(routes);
} | /** Get global menus */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/route/index.ts#L86-L88 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | updateGlobalMenusByLocale | function updateGlobalMenusByLocale() {
menus.value = updateLocaleOfGlobalMenus(menus.value);
} | /** Update global menus by locale */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/route/index.ts#L91-L93 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | getCacheRoutes | function getCacheRoutes(routes: RouteRecordRaw[]) {
cacheRoutes.value = getCacheRouteNames(routes);
} | /**
* Get cache routes
*
* @param routes Vue routes
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/route/index.ts#L110-L112 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | resetRouteCache | async function resetRouteCache(routeKey?: RouteKey) {
const routeName = routeKey || (router.currentRoute.value.name as RouteKey);
excludeCacheRoutes.value.push(routeName);
await nextTick();
excludeCacheRoutes.value = [];
} | /**
* Reset route cache
*
* @default router.currentRoute.value.name current route name
* @param routeKey
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/route/index.ts#L120-L128 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | resetStore | async function resetStore() {
const routeStore = useRouteStore();
routeStore.$reset();
resetVueRoutes();
// after reset store, need to re-init constant route
await initConstantRoute();
} | /** Reset store */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/route/index.ts#L134-L143 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | resetVueRoutes | function resetVueRoutes() {
removeRouteFns.forEach(fn => fn());
removeRouteFns.length = 0;
} | /** Reset vue routes */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/route/index.ts#L146-L149 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | initConstantRoute | async function initConstantRoute() {
if (isInitConstantRoute.value) return;
const staticRoute = createStaticRoutes();
if (authRouteMode.value === 'static') {
addConstantRoutes(staticRoute.constantRoutes);
} else {
const { data, error } = await fetchGetConstantRoutes();
if (!error) {... | /** init constant route */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/route/index.ts#L152-L175 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | initAuthRoute | async function initAuthRoute() {
// check if user info is initialized
if (!authStore.userInfo.userId) {
await authStore.initUserInfo();
}
if (authRouteMode.value === 'static') {
initStaticAuthRoute();
} else {
await initDynamicAuthRoute();
}
tabStore.initHomeTab();
} | /** Init auth route */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/route/index.ts#L178-L191 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | initStaticAuthRoute | function initStaticAuthRoute() {
const { authRoutes: staticAuthRoutes } = createStaticRoutes();
if (authStore.isStaticSuper) {
addAuthRoutes(staticAuthRoutes);
} else {
const filteredAuthRoutes = filterAuthRoutesByRoles(staticAuthRoutes, authStore.userInfo.roles);
addAuthRoutes(filteredA... | /** Init static auth route */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/route/index.ts#L194-L208 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | initDynamicAuthRoute | async function initDynamicAuthRoute() {
const { data, error } = await fetchGetUserRoutes();
if (!error) {
const { routes, home } = data;
addAuthRoutes(routes);
handleConstantAndAuthRoutes();
setRouteHome(home);
handleUpdateRootRouteRedirect(home);
setIsInitAuthRoute(tru... | /** Init dynamic auth route */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/route/index.ts#L211-L230 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | handleConstantAndAuthRoutes | function handleConstantAndAuthRoutes() {
const allRoutes = [...constantRoutes.value, ...authRoutes.value];
const sortRoutes = sortRoutesByOrder(allRoutes);
const vueRoutes = getAuthVueRoutes(sortRoutes);
resetVueRoutes();
addRoutesToVueRouter(vueRoutes);
getGlobalMenus(sortRoutes);
get... | /** handle constant and auth routes */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/route/index.ts#L233-L247 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | addRoutesToVueRouter | function addRoutesToVueRouter(routes: RouteRecordRaw[]) {
routes.forEach(route => {
const removeFn = router.addRoute(route);
addRemoveRouteFn(removeFn);
});
} | /**
* Add routes to vue router
*
* @param routes Vue routes
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/route/index.ts#L254-L259 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | addRemoveRouteFn | function addRemoveRouteFn(fn: () => void) {
removeRouteFns.push(fn);
} | /**
* Add remove route fn
*
* @param fn
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/route/index.ts#L266-L268 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | handleUpdateRootRouteRedirect | function handleUpdateRootRouteRedirect(redirectKey: LastLevelRouteKey) {
const redirect = getRoutePath(redirectKey);
if (redirect) {
const rootRoute: CustomRoute = { ...ROOT_ROUTE, redirect };
router.removeRoute(rootRoute.name);
const [rootVueRoute] = getAuthVueRoutes([rootRoute]);
r... | /**
* Update root route redirect when auth route mode is dynamic
*
* @param redirectKey Redirect route key
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/route/index.ts#L275-L287 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | getIsAuthRouteExist | async function getIsAuthRouteExist(routePath: RouteMap[RouteKey]) {
const routeName = getRouteName(routePath);
if (!routeName) {
return false;
}
if (authRouteMode.value === 'static') {
const { authRoutes: staticAuthRoutes } = createStaticRoutes();
return isRouteExistByRouteName(route... | /**
* Get is auth route exist
*
* @param routePath Route path
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/route/index.ts#L294-L309 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | getSelectedMenuKeyPath | function getSelectedMenuKeyPath(selectedKey: string) {
return getSelectedMenuKeyPathByKey(selectedKey, menus.value);
} | /**
* Get selected menu key path
*
* @param selectedKey Selected menu key
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/route/index.ts#L316-L318 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | filterAuthRouteByRoles | function filterAuthRouteByRoles(route: ElegantConstRoute, roles: string[]): ElegantConstRoute[] {
const routeRoles = (route.meta && route.meta.roles) || [];
// if the route's "roles" is empty, then it is allowed to access
const isEmptyRoles = !routeRoles.length;
// if the user's role is included in the route'... | /**
* Filter auth route by roles
*
* @param route Auth route
* @param roles Roles
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/route/shared.ts#L22-L43 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | sortRouteByOrder | function sortRouteByOrder(route: ElegantConstRoute) {
if (route.children?.length) {
route.children.sort((next, prev) => (Number(next.meta?.order) || 0) - (Number(prev.meta?.order) || 0));
route.children.forEach(sortRouteByOrder);
}
return route;
} | /**
* sort route by order
*
* @param route route
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/route/shared.ts#L50-L57 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | getGlobalMenuByBaseRoute | function getGlobalMenuByBaseRoute(route: RouteLocationNormalizedLoaded | ElegantConstRoute) {
const { SvgIconVNode } = useSvgIcon();
const { name, path } = route;
const { title, i18nKey, icon = import.meta.env.VITE_MENU_ICON, localIcon, iconFontSize } = route.meta ?? {};
const label = i18nKey ? $t(i18nKey) : ... | /**
* Get global menu by route
*
* @param route
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/route/shared.ts#L128-L147 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | recursiveGetIsRouteExistByRouteName | function recursiveGetIsRouteExistByRouteName(route: ElegantConstRoute, routeName: RouteKey) {
let isExist = route.name === routeName;
if (isExist) {
return true;
}
if (route.children && route.children.length) {
isExist = route.children.some(item => recursiveGetIsRouteExistByRouteName(item, routeName))... | /**
* Recursive get is route exist by route name
*
* @param route
* @param routeName
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/route/shared.ts#L185-L197 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | findMenuPath | function findMenuPath(targetKey: string, menu: App.Global.Menu): string[] | null {
const path: string[] = [];
function dfs(item: App.Global.Menu): boolean {
path.push(item.key);
if (item.key === targetKey) {
return true;
}
if (item.children) {
for (const child of item.children) {
... | /**
* Find menu path
*
* @param targetKey Target menu key
* @param menu Menu
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/route/shared.ts#L229-L257 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | initHomeTab | function initHomeTab() {
homeTab.value = getDefaultHomeTab(router, routeStore.routeHome);
} | /** Init home tab */ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/tab/index.ts#L38-L40 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
soybean-admin-antd | github_2023 | soybeanjs | typescript | setActiveTabId | function setActiveTabId(id: string) {
activeTabId.value = id;
} | /**
* Set active tab id
*
* @param id Tab id
*/ | https://github.com/soybeanjs/soybean-admin-antd/blob/6bd3e89e710836beb14b1a3381532a3eb7cc3a75/src/store/modules/tab/index.ts#L53-L55 | 6bd3e89e710836beb14b1a3381532a3eb7cc3a75 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.