repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
three.ez | github_2023 | agargaro | typescript | Utils.getNodes | public static getNodes(target: Object3D): Nodes {
return this.generateNodesFromObject(target, {}, {});
} | /**
* Retrieves a map of objects in the scene graph (Object3D) starting from a root object.
* Each object is mapped using its unique name as the key in the resulting object.
* @param target - The root object to begin generating the object map from.
* @returns An object containing objects mapped by their nam... | https://github.com/agargaro/three.ez/blob/7da9727b605f49314016a99561b8d797ca0519b6/src/utils/Utils.ts#L60-L62 | 7da9727b605f49314016a99561b8d797ca0519b6 |
three.ez | github_2023 | agargaro | typescript | VectorUtils.angleSignedFromOrigin | public static angleSignedFromOrigin(a: Vector3, b: Vector3, normal = this.DEFAULT_NORMAL): number {
return Math.atan2(TEMP[0].crossVectors(a, b).dot(normal), a.dot(b));
} | // normal must be normalized | https://github.com/agargaro/three.ez/blob/7da9727b605f49314016a99561b8d797ca0519b6/src/utils/VectorUtils.ts#L86-L88 | 7da9727b605f49314016a99561b8d797ca0519b6 |
chatait-free | github_2023 | anlityli | typescript | permissionMenuHandle | const permissionMenuHandle = (routes: RouteRecordRaw[], apiMenu: any): RouteRecordRaw[] => {
const reRoutes = <RouteRecordRaw[]>[]
for (let apiIndex = 0; apiIndex < apiMenu.length; apiIndex++) {
for (let i = 0; i < routes.length; i++) {
if (apiMenu[apiIndex].key === routes[i].name) {
const tempMen... | /**
* 权限菜单处理
* @param routes
* @param apiMenu
*/ | https://github.com/anlityli/chatait-free/blob/b9c356b12db1cb37ad4fb090a62024bba207b96a/chatait-backend-vue/src/store/modules/permission.ts#L18-L45 | b9c356b12db1cb37ad4fb090a62024bba207b96a |
activation-script | github_2023 | UniAlternative | typescript | matchModuleFunc | async function matchModuleFunc(moduleFunc: Omit<ActivatorObjFunc, 'base'> & { base: string | string[] }) {
if (Array.isArray(moduleFunc.base)) {
for (let base of moduleFunc.base) {
base = base.replace(/\/$/, '')
const res = await matchModuleFunc({ ...moduleFunc, base }) as any
if (!res... | /**
* 匹配模块函数
* @description 这会根据模块函数的 base 属性来匹配 url,如果匹配成功则执行模块函数的 func 属性
*
* @param moduleFunc 模块函数
* @returns 匹配结果
*
*/ | https://github.com/UniAlternative/activation-script/blob/1232786bacedc7a818ee7e9e073c7c97a6c228d8/packages/core/src/launch.ts#L46-L64 | 1232786bacedc7a818ee7e9e073c7c97a6c228d8 |
activation-script | github_2023 | UniAlternative | typescript | handleModuleFunc | async function handleModuleFunc(moduleFunc: Omit<ActivatorObjFunc, 'base'> & { base: string | string[] }) {
if (typeof moduleFunc === 'object') {
const match = await matchModuleFunc(moduleFunc)
if (match)
return match
}
} | /**
* 处理模块函数
* @description 这会根据模块函数的类型来执行对应的处理
*
* @param moduleFunc 模块函数
* @returns 匹配结果
*
*/ | https://github.com/UniAlternative/activation-script/blob/1232786bacedc7a818ee7e9e073c7c97a6c228d8/packages/core/src/launch.ts#L74-L80 | 1232786bacedc7a818ee7e9e073c7c97a6c228d8 |
activation-script | github_2023 | UniAlternative | typescript | _genMsg | function _genMsg(str: string) {
return Buffer.from(str).toString('base64')
} | // console.log( | https://github.com/UniAlternative/activation-script/blob/1232786bacedc7a818ee7e9e073c7c97a6c228d8/packages/modules/typora/alogrithm/others.ts#L18-L20 | 1232786bacedc7a818ee7e9e073c7c97a6c228d8 |
activation-script | github_2023 | UniAlternative | typescript | ASModuleStorage.getValue | getValue(key?: keyof T) {
const modules = getStorage(this.getStorageKey())
return modules && key ? getDeepKeyInAnObject(modules[this.key], String(key)) : undefined
} | /**
* Get value from storage
*
* @example
* You can pass a dot-separated key to get a deep value, for example:
*
* ```ts
* const storage = new ASModuleStorage({ key: 'global' })
* storage.getValue('a.b.c') // Get global.a.b.c
* ```
* @param key
*/ | https://github.com/UniAlternative/activation-script/blob/1232786bacedc7a818ee7e9e073c7c97a6c228d8/packages/shared/src/class/ASModuleStorage.ts#L56-L59 | 1232786bacedc7a818ee7e9e073c7c97a6c228d8 |
activation-script | github_2023 | UniAlternative | typescript | ASModuleStorage.setValue | setValue(key: keyof T, value: T[keyof T]) {
const modules = getStorage(this.getStorageKey())
if (modules) {
modules[this.key] = modules[this.key] || {}
modules[this.key] = { ...modules[this.key], [key]: value }
return setStorage(this.getStorageKey(), modules)
}
return false
} | /**
* Set value to storage
*
* @example
* You can pass a dot-separated key to set a deep value, for example:
*
* ```ts
* const storage = new ASModuleStorage({ key: 'global' })
* storage.setValue('a.b.c', 1) // Set global.a.b.c = 1
* ```
* @param key
* @param value
*/ | https://github.com/UniAlternative/activation-script/blob/1232786bacedc7a818ee7e9e073c7c97a6c228d8/packages/shared/src/class/ASModuleStorage.ts#L74-L82 | 1232786bacedc7a818ee7e9e073c7c97a6c228d8 |
activation-script | github_2023 | UniAlternative | typescript | ASModuleStorage.clear | clear() {
const modules = getStorage(`modules`)
if (modules) {
delete modules[this.key]
return setStorage(`modules`, modules)
}
return false
} | /**
* Clear all data in storage
*
* @description
* It will clear all module data, use with caution. (But it will not clear global data)
*/ | https://github.com/UniAlternative/activation-script/blob/1232786bacedc7a818ee7e9e073c7c97a6c228d8/packages/shared/src/class/ASModuleStorage.ts#L90-L97 | 1232786bacedc7a818ee7e9e073c7c97a6c228d8 |
activation-script | github_2023 | UniAlternative | typescript | Timer.startTimer | public startTimer() {
this.start = Date.now()
} | /**
* Start the timer
*
* @memberof Timer
*/ | https://github.com/UniAlternative/activation-script/blob/1232786bacedc7a818ee7e9e073c7c97a6c228d8/packages/shared/src/class/Timer.ts#L18-L20 | 1232786bacedc7a818ee7e9e073c7c97a6c228d8 |
activation-script | github_2023 | UniAlternative | typescript | Timer.endTimer | public endTimer() {
this.end = Date.now()
} | /**
* End the timer
*
* @memberof Timer
*/ | https://github.com/UniAlternative/activation-script/blob/1232786bacedc7a818ee7e9e073c7c97a6c228d8/packages/shared/src/class/Timer.ts#L27-L29 | 1232786bacedc7a818ee7e9e073c7c97a6c228d8 |
activation-script | github_2023 | UniAlternative | typescript | Timer.getDuration | public getDuration() {
if (this.end)
return this.end - this.start
return Date.now() - this.start
} | /**
* Get the duration of the timer
*
* @memberof Timer
*/ | https://github.com/UniAlternative/activation-script/blob/1232786bacedc7a818ee7e9e073c7c97a6c228d8/packages/shared/src/class/Timer.ts#L36-L41 | 1232786bacedc7a818ee7e9e073c7c97a6c228d8 |
activation-script | github_2023 | UniAlternative | typescript | Timer.getDurationInSeconds | public getDurationInSeconds() {
return this.getDuration() / 1000
} | /**
* Get the duration of the timer in seconds
*
* @memberof Timer
*/ | https://github.com/UniAlternative/activation-script/blob/1232786bacedc7a818ee7e9e073c7c97a6c228d8/packages/shared/src/class/Timer.ts#L48-L50 | 1232786bacedc7a818ee7e9e073c7c97a6c228d8 |
watermark | github_2023 | watermark-design | typescript | WatermarkCanvas.createCanvas | static createCanvas(width: number, height: number): HTMLCanvasElement {
const ratio = window.devicePixelRatio || 1;
const canvas = document.createElement('canvas');
canvas.width = width * ratio; // actual rendered pixel
canvas.height = height * ratio; // actual rendered pixel
canvas.style.width = `$... | /**
* Create an HD canvas.
* @param width - width of canvas
* @param height - height of canvas
*/ | https://github.com/watermark-design/watermark/blob/03f794e000ad11f8acf4fcea6203b4848a315cee/packages/core/src/watermark-canvas.ts#L24-L33 | 03f794e000ad11f8acf4fcea6203b4848a315cee |
watermark | github_2023 | watermark-design | typescript | WatermarkCanvas.clearCanvas | static clearCanvas(canvas: HTMLCanvasElement): void {
const ctx = canvas.getContext('2d');
if (ctx === null) {
throw new Error('get context error');
}
ctx.restore();
ctx.resetTransform();
ctx.clearRect(0, 0, canvas.width, canvas.height);
const ratio = window.devicePixelRatio || 1;
... | /**
* Clean the canvas
* @param canvas
*/ | https://github.com/watermark-design/watermark/blob/03f794e000ad11f8acf4fcea6203b4848a315cee/packages/core/src/watermark-canvas.ts#L39-L49 | 03f794e000ad11f8acf4fcea6203b4848a315cee |
watermark | github_2023 | watermark-design | typescript | BlindWatermark.constructor | constructor(props: Partial<WatermarkOptions> = {}) {
props.globalAlpha = 0.005;
props.mode = 'blind';
super(props);
} | /**
* BlindWatermark constructor
* @param props - blind watermark options
*/ | https://github.com/watermark-design/watermark/blob/03f794e000ad11f8acf4fcea6203b4848a315cee/packages/dom/src/blind.ts#L14-L18 | 03f794e000ad11f8acf4fcea6203b4848a315cee |
watermark | github_2023 | watermark-design | typescript | BlindWatermark.decode | static decode(props: Partial<DecodeBlindWatermarkOptions>): void {
const options = Object.assign(
{
url: '',
fillColor: '#000',
compositeOperation: 'color-burn',
mode: 'canvas',
compositeTimes: 3,
},
props
);
if (!options.url) {
return;
}
... | /**
* Decode blind watermark.
* @param props - decode options
*/ | https://github.com/watermark-design/watermark/blob/03f794e000ad11f8acf4fcea6203b4848a315cee/packages/dom/src/blind.ts#L24-L60 | 03f794e000ad11f8acf4fcea6203b4848a315cee |
watermark | github_2023 | watermark-design | typescript | ImageWatermark.constructor | constructor(args: Partial<ImageWatermarkOptions> = {}) {
this.props = args;
this.options = {
...initialOptions,
...args,
};
this.watermarkCanvas = new WatermarkCanvas(this.props, this.options);
this.originalSrc = this.props.dom?.src;
this.backgroundImage = this.getBackgroundImage();
... | /**
* ImageWatermark constructor
* @param args - image watermark args
*/ | https://github.com/watermark-design/watermark/blob/03f794e000ad11f8acf4fcea6203b4848a315cee/packages/dom/src/image.ts#L25-L34 | 03f794e000ad11f8acf4fcea6203b4848a315cee |
watermark | github_2023 | watermark-design | typescript | Watermark.constructor | constructor(args: Partial<WatermarkOptions> = {}) {
this.props = args;
this.options = {
...initialOptions,
...args,
};
this.changeParentElement(this.options.parent);
this.watermarkCanvas = new WatermarkCanvas(this.props, this.options);
protection(this.options.monitorProtection);
} | /**
* Watermark constructor
* @param args - watermark args
*/ | https://github.com/watermark-design/watermark/blob/03f794e000ad11f8acf4fcea6203b4848a315cee/packages/dom/src/watermark.ts#L31-L40 | 03f794e000ad11f8acf4fcea6203b4848a315cee |
watermark | github_2023 | watermark-design | typescript | Watermark.changeOptions | async changeOptions(
args: Partial<WatermarkOptions> = {},
mode: ChangeOptionsMode = 'overwrite',
redraw: boolean = true
): Promise<void> {
this.initConfigData(args, mode);
protection(this.options.monitorProtection);
if (redraw) {
this.remove();
await this.create();
}
} | /**
* Change watermark options
* @param args
* @param mode
* @param redraw
*/ | https://github.com/watermark-design/watermark/blob/03f794e000ad11f8acf4fcea6203b4848a315cee/packages/dom/src/watermark.ts#L48-L59 | 03f794e000ad11f8acf4fcea6203b4848a315cee |
watermark | github_2023 | watermark-design | typescript | Watermark.create | async create(): Promise<void> {
if (this.isCreating) {
return;
}
this.isCreating = true;
if (!this.validateUnique()) {
this.isCreating = false;
return;
}
if (!this.validateContent()) {
this.isCreating = false;
return;
}
const firstDraw = isUndefined(this.wa... | /**
* Creating a watermark.
*/ | https://github.com/watermark-design/watermark/blob/03f794e000ad11f8acf4fcea6203b4848a315cee/packages/dom/src/watermark.ts#L64-L133 | 03f794e000ad11f8acf4fcea6203b4848a315cee |
watermark | github_2023 | watermark-design | typescript | Watermark.destroy | destroy(): void {
this.remove();
this.watermarkDom = undefined;
} | /**
* Delete this watermark.
*/ | https://github.com/watermark-design/watermark/blob/03f794e000ad11f8acf4fcea6203b4848a315cee/packages/dom/src/watermark.ts#L138-L141 | 03f794e000ad11f8acf4fcea6203b4848a315cee |
obsidian-recipe-view | github_2023 | lachholden | typescript | quantityStringsToValue | function quantityStringsToValue(str: string, unit?: string) {
return {
value: new Fraction(str.replace(/[-\s]+/g, " ")),
format: (str.includes("/") ||
unit?.match(/tablespoons?|teaspoons?|tb?sp?s?\.?|cups?|sticks?/i) ||
(!unit && !str.includes(".")))
? QtyFormatTy... | /**
* Take a string of one of the forms matched by the NUMBER regex and an optional unit,
* and return an object with the Fraction value of the number and whether, when scaled,
* it should be represented as a fraction or decimal.
*
* The preferred format will match the input. If the input is an integer, then
* t... | https://github.com/lachholden/obsidian-recipe-view/blob/a1b92eb0c078994e4493a53f22c8bef70ef812fc/src/quantities.ts#L64-L72 | a1b92eb0c078994e4493a53f22c8bef70ef812fc |
envy | github_2023 | FormidableLabs | typescript | Retry.attempts | get attempts() {
return this.retryAttempts;
} | /**
* The number of attempts
*/ | https://github.com/FormidableLabs/envy/blob/ea1bb24cbfece740093868bf120c170b122c380a/packages/core/src/time.ts#L16-L18 | ea1bb24cbfece740093868bf120c170b122c380a |
envy | github_2023 | FormidableLabs | typescript | Retry.delay | get delay() {
return this.retryDelay;
} | /**
* The current delay in ms
*/ | https://github.com/FormidableLabs/envy/blob/ea1bb24cbfece740093868bf120c170b122c380a/packages/core/src/time.ts#L23-L25 | ea1bb24cbfece740093868bf120c170b122c380a |
envy | github_2023 | FormidableLabs | typescript | Retry.shouldRetry | get shouldRetry() {
return this.retryAttempts >= DEFAULT_RETRY_MAX_ATTEMPTS;
} | /**
* Returns true if the max attempts has not been exceeded
*/ | https://github.com/FormidableLabs/envy/blob/ea1bb24cbfece740093868bf120c170b122c380a/packages/core/src/time.ts#L30-L32 | ea1bb24cbfece740093868bf120c170b122c380a |
envy | github_2023 | FormidableLabs | typescript | Retry.getNextDelay | getNextDelay() {
const jitter = Math.random() * 1000;
const exp = Math.pow(this.retryAttempts++ / DEFAULT_RETRY_FLATTEN, DEFAULT_RETRY_FACTOR) * 1000;
this.retryDelay = jitter + exp;
return this.retryDelay;
} | /**
* Increments the attempts and returns a new delay in ms
* @returns the delay in ms
*/ | https://github.com/FormidableLabs/envy/blob/ea1bb24cbfece740093868bf120c170b122c380a/packages/core/src/time.ts#L38-L43 | ea1bb24cbfece740093868bf120c170b122c380a |
envy | github_2023 | FormidableLabs | typescript | Retry.reset | reset() {
this.retryDelay = DEFAULT_RETRY_DELAY;
this.retryAttempts = 0;
} | /**
* Reset the attempts and delay to defaults
*/ | https://github.com/FormidableLabs/envy/blob/ea1bb24cbfece740093868bf120c170b122c380a/packages/core/src/time.ts#L48-L51 | ea1bb24cbfece740093868bf120c170b122c380a |
envy | github_2023 | FormidableLabs | typescript | CollectorClient._setHttpTimeout | private _setHttpTimeout(id: string) {
const timeoutId = setTimeout(() => {
const trace = this._traces.get(id);
if (trace?.http?.state === 'sent') {
trace.http.state = HttpRequestState.Timeout;
trace.http.statusMessage = 'TIMEOUT';
trace.http.statusCode = -1;
trace.http.du... | // where we don't receive a response in a timely manner | https://github.com/FormidableLabs/envy/blob/ea1bb24cbfece740093868bf120c170b122c380a/packages/webui/src/collector/CollectorClient.ts#L96-L110 | ea1bb24cbfece740093868bf120c170b122c380a |
react-tv-player | github_2023 | lewhunt | typescript | handleError | const handleError = (
error: any,
data: any,
hlsInstance: any,
hlsGlobal: any
) => {
console.log("error: ", error);
console.log("data (optional): ", data);
console.log("hlsInstance (optional): ", hlsInstance);
console.log("hlsGlobal (optional): ", hlsGlobal);
}; | // Called when an error occurs whilst attempting to play media | https://github.com/lewhunt/react-tv-player/blob/4f4d3463db1a071c3259ffeda04291f1f37443c4/src/App.tsx#L70-L80 | 4f4d3463db1a071c3259ffeda04291f1f37443c4 |
gui | github_2023 | acrodata | typescript | StyleManager.setStyle | setStyle(key: string, href: string) {
getLinkElementForKey(key).setAttribute('href', href);
} | /**
* Set the stylesheet with the specified key.
*/ | https://github.com/acrodata/gui/blob/138b7c4e044a524c08bd4a4fea2ffaef6130a147/projects/docs/src/app/shared/style-manager/style-manager.ts#L12-L14 | 138b7c4e044a524c08bd4a4fea2ffaef6130a147 |
gui | github_2023 | acrodata | typescript | StyleManager.removeStyle | removeStyle(key: string) {
const existingLinkElement = getExistingLinkElementByKey(key);
if (existingLinkElement) {
document.head.removeChild(existingLinkElement);
}
} | /**
* Remove the stylesheet with the specified key.
*/ | https://github.com/acrodata/gui/blob/138b7c4e044a524c08bd4a4fea2ffaef6130a147/projects/docs/src/app/shared/style-manager/style-manager.ts#L19-L24 | 138b7c4e044a524c08bd4a4fea2ffaef6130a147 |
gui | github_2023 | acrodata | typescript | GuiForm.getFormFieldArray | getFormFieldArray(
form: FormGroup | FormArray,
config: GuiFields | GuiControl[] = {},
model: Record<string, any> = {},
defaultValue: any = null,
parentType: GuiFieldType = 'group'
) {
const tempArr = [];
for (const key of Object.keys(config)) {
// Inferring the form type by the dat... | /**
* Convert the object config to array config and register into the reactive form.
*
* @param form The reactive form instance
* @param config The config of the form fields
* @param model The value of the form control
* @param defaultValue The default value of the form field
*... | https://github.com/acrodata/gui/blob/138b7c4e044a524c08bd4a4fea2ffaef6130a147/projects/gui/gui-form.ts#L154-L292 | 138b7c4e044a524c08bd4a4fea2ffaef6130a147 |
gui | github_2023 | acrodata | typescript | GuiForm.addTab | addTab(e: MouseEvent, formArray: FormArray, tabs: GuiControl, copy?: boolean, index?: number) {
e.stopPropagation();
const insertIndex =
index !== void 0 ? index + 1 : copy ? tabs.selectedIndex! + 1 : tabs.children!.length;
// Save the index of the insertion in the config
tabs.template!.index = in... | /**
* Add a tab item.
*
* @param e The mouse event
* @param formArray The reactive form instance
* @param tabs The config of the tabs field
* @param copy Whether to copy the current tab
* @param index The index of the tabs array
*/ | https://github.com/acrodata/gui/blob/138b7c4e044a524c08bd4a4fea2ffaef6130a147/projects/gui/gui-form.ts#L303-L331 | 138b7c4e044a524c08bd4a4fea2ffaef6130a147 |
gui | github_2023 | acrodata | typescript | GuiForm.removeTab | removeTab(e: MouseEvent, formArray: FormArray, tabs: GuiControl, index?: number) {
e.stopPropagation();
const removeIndex = index === void 0 ? tabs.selectedIndex! : index;
tabs.children!.forEach((child, index) => {
if (index > removeIndex) {
child.index! -= 1;
child.key = child.index +... | /**
* Remove a tab item.
*
* @param e The mouse event
* @param formArray The reactive form instance
* @param tabs The config of the tabs field
* @param index The index of the tabs array
*/ | https://github.com/acrodata/gui/blob/138b7c4e044a524c08bd4a4fea2ffaef6130a147/projects/gui/gui-form.ts#L341-L352 | 138b7c4e044a524c08bd4a4fea2ffaef6130a147 |
gui | github_2023 | acrodata | typescript | GuiForm.changeTabsMode | changeTabsMode(e: MouseEvent, tabs: GuiControl, mode?: GuiTabsMode) {
e.stopPropagation();
tabs.mode = mode;
} | /**
* Change the display mode of tabs.
*
* @param e The mouse event
* @param tabs The config of the tabs field
* @param mode The display mode of tabs
*/ | https://github.com/acrodata/gui/blob/138b7c4e044a524c08bd4a4fea2ffaef6130a147/projects/gui/gui-form.ts#L361-L364 | 138b7c4e044a524c08bd4a4fea2ffaef6130a147 |
gui | github_2023 | acrodata | typescript | GuiFileUploaderConfig.upload | upload(file: FormData) {
return this.http.post<any>(this.url, file, {
reportProgress: true,
observe: 'events',
params: this.params,
});
} | /**
* The File upload API
*
* @param file file data
* @returns
*/ | https://github.com/acrodata/gui/blob/138b7c4e044a524c08bd4a4fea2ffaef6130a147/projects/gui/file-uploader/file-uploader-config.ts#L26-L32 | 138b7c4e044a524c08bd4a4fea2ffaef6130a147 |
hyperdx | github_2023 | hyperdxio | typescript | SQLSerializer.getColumnForField | async getColumnForField(field: string) {
const customField = this.getCustomFieldOnly(field);
if (customField.found) {
return customField;
}
let propertyType = this.propertyTypeMapModel.get(field);
// TODO: Deal with ambiguous fields
let column: string | null = field;
// refresh cache ... | // In the future this may trigger network calls against a property mapping cache | https://github.com/hyperdxio/hyperdx/blob/dacc630320adc0fb0e024d55a8496742f9364507/packages/api/src/clickhouse/searchQueryParser.ts#L171-L198 | dacc630320adc0fb0e024d55a8496742f9364507 |
hyperdx | github_2023 | hyperdxio | typescript | SQLSerializer.eq | async eq(field: string, term: string, isNegatedField: boolean) {
const { column, found, propertyType } = await this.getColumnForField(field);
if (!found) {
return this.NOT_FOUND_QUERY;
}
if (propertyType === 'bool') {
// numeric and boolean fields must be equality matched
const normTer... | // Only for exact string matches | https://github.com/hyperdxio/hyperdx/blob/dacc630320adc0fb0e024d55a8496742f9364507/packages/api/src/clickhouse/searchQueryParser.ts#L222-L242 | dacc630320adc0fb0e024d55a8496742f9364507 |
hyperdx | github_2023 | hyperdxio | typescript | SQLSerializer.attemptToParseNumber | private attemptToParseNumber(term: string): string | number {
const number = Number.parseFloat(term);
if (Number.isNaN(number)) {
return term;
}
return number;
} | // TODO: Not sure if SQL really needs this or if it'll coerce itself | https://github.com/hyperdxio/hyperdx/blob/dacc630320adc0fb0e024d55a8496742f9364507/packages/api/src/clickhouse/searchQueryParser.ts#L305-L311 | dacc630320adc0fb0e024d55a8496742f9364507 |
hyperdx | github_2023 | hyperdxio | typescript | SQLSerializer.tokenizeTerm | private tokenizeTerm(term: string): string[] {
return term.split(/[ -/:-@[-`{-~\t\n\r]+/).filter(t => t.length > 0);
} | // Split by anything that's ascii 0-128, that's not a letter or a number | https://github.com/hyperdxio/hyperdx/blob/dacc630320adc0fb0e024d55a8496742f9364507/packages/api/src/clickhouse/searchQueryParser.ts#L315-L317 | dacc630320adc0fb0e024d55a8496742f9364507 |
hyperdx | github_2023 | hyperdxio | typescript | SearchQueryBuilder.timestampInBetween | timestampInBetween(startTime: number, endTime: number) {
this.and(SearchQueryBuilder.timestampInBetween(startTime, endTime));
return this;
} | // startTime and endTime are unix in ms | https://github.com/hyperdxio/hyperdx/blob/dacc630320adc0fb0e024d55a8496742f9364507/packages/api/src/clickhouse/searchQueryParser.ts#L639-L642 | dacc630320adc0fb0e024d55a8496742f9364507 |
hyperdx | github_2023 | hyperdxio | typescript | implicitLike | function implicitLike(column: string, term: string) {
return `(lower(${column}) LIKE lower('${term}'))`;
} | // for implicit field | https://github.com/hyperdxio/hyperdx/blob/dacc630320adc0fb0e024d55a8496742f9364507/packages/api/src/clickhouse/__tests__/searchQueryParser.test.ts#L20-L22 | dacc630320adc0fb0e024d55a8496742f9364507 |
hyperdx | github_2023 | hyperdxio | typescript | validateGroupBy | const validateGroupBy = async (
req: Request,
res: Response,
next: NextFunction,
) => {
const { groupBy, source } = req.body || {};
if (source === 'LOG' && groupBy) {
const teamId = req.user?.team;
if (teamId == null) {
return res.sendStatus(403);
}
const team = await getTeam(teamId);
... | // Validate groupBy property | https://github.com/hyperdxio/hyperdx/blob/dacc630320adc0fb0e024d55a8496742f9364507/packages/api/src/routers/api/alerts.ts#L21-L49 | dacc630320adc0fb0e024d55a8496742f9364507 |
hyperdx | github_2023 | hyperdxio | typescript | scaleSampleCounts | const scaleSampleCounts = (count: number) =>
Math.round(count / SAMPLE_RATE); | // TODO: compute this dynamically | https://github.com/hyperdxio/hyperdx/blob/dacc630320adc0fb0e024d55a8496742f9364507/packages/api/src/routers/api/logs.ts#L91-L92 | dacc630320adc0fb0e024d55a8496742f9364507 |
hyperdx | github_2023 | hyperdxio | typescript | validateGroupBy | const validateGroupBy = async (
req: Request,
res: Response,
next: NextFunction,
) => {
const { groupBy, source } = req.body || {};
if (source === 'LOG' && groupBy) {
const teamId = req.user?.team;
if (teamId == null) {
return res.sendStatus(403);
}
const team = await getTeam(teamId);
... | // TODO: Dedup with private API router | https://github.com/hyperdxio/hyperdx/blob/dacc630320adc0fb0e024d55a8496742f9364507/packages/api/src/routers/external-api/v1/alerts.ts#L26-L54 | dacc630320adc0fb0e024d55a8496742f9364507 |
hyperdx | github_2023 | hyperdxio | typescript | fireChannelEvent | const fireChannelEvent = async ({
alert,
attributes,
dashboard,
endTime,
group,
logView,
startTime,
totalCount,
windowSizeInMins,
}: {
alert: AlertDocument;
attributes: Record<string, string>; // TODO: support other types than string
dashboard: EnhancedDashboard | null;
endTime: Date;
group?... | // ------------------------------------------------------------ | https://github.com/hyperdxio/hyperdx/blob/dacc630320adc0fb0e024d55a8496742f9364507/packages/api/src/tasks/checkAlerts.ts#L567-L645 | dacc630320adc0fb0e024d55a8496742f9364507 |
hyperdx | github_2023 | hyperdxio | typescript | onMouseDown | const onMouseDown: MouseEventHandler<HTMLDivElement> = e => {
e.preventDefault();
e.stopPropagation();
}; | // this prevents the menu from being opened/closed when the user clicks | https://github.com/hyperdxio/hyperdx/blob/dacc630320adc0fb0e024d55a8496742f9364507/packages/app/src/FieldMultiSelect.tsx#L36-L39 | dacc630320adc0fb0e024d55a8496742f9364507 |
hyperdx | github_2023 | hyperdxio | typescript | onColumnSizingChange | const onColumnSizingChange = (updaterOrValue: any) => {
const state =
updaterOrValue instanceof Function
? updaterOrValue()
: updaterOrValue;
setColumnSizeStorage({ ...columnSizeStorage, ...state });
}; | //TODO: fix any | https://github.com/hyperdxio/hyperdx/blob/dacc630320adc0fb0e024d55a8496742f9364507/packages/app/src/LogTable.tsx#L459-L465 | dacc630320adc0fb0e024d55a8496742f9364507 |
hyperdx | github_2023 | hyperdxio | typescript | escapeStringPosix | function escapeStringPosix(str: string): string {
function escapeCharacter(x: string): string {
const code = x.charCodeAt(0);
let hexString = code.toString(16);
// Zero pad to four digits to comply with ANSI-C Quoting:
// http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
wh... | // From chrome dev tools | https://github.com/hyperdxio/hyperdx/blob/dacc630320adc0fb0e024d55a8496742f9364507/packages/app/src/curlGenerator.ts#L127-L158 | dacc630320adc0fb0e024d55a8496742f9364507 |
hyperdx | github_2023 | hyperdxio | typescript | EnglishSerializer.fieldSearch | async fieldSearch(
field: string,
term: string,
isNegatedField: boolean,
prefixWildcard: boolean,
suffixWildcard: boolean,
) {
if (field === IMPLICIT_FIELD) {
return `${this.translateField(field)} ${
prefixWildcard && suffixWildcard
? isNegatedField
? 'does ... | // } | https://github.com/hyperdxio/hyperdx/blob/dacc630320adc0fb0e024d55a8496742f9364507/packages/app/src/queryv2.ts#L115-L145 | dacc630320adc0fb0e024d55a8496742f9364507 |
hyperdx | github_2023 | hyperdxio | typescript | handleResize | function handleResize() {
// Set window width/height to state
setWindowSize({
width: window.innerWidth,
height: window.innerHeight,
});
} | // Handler to call on window resize | https://github.com/hyperdxio/hyperdx/blob/dacc630320adc0fb0e024d55a8496742f9364507/packages/app/src/utils.tsx#L73-L79 | dacc630320adc0fb0e024d55a8496742f9364507 |
hyperdx | github_2023 | hyperdxio | typescript | setValue | const setValue = (value: T | Function) => {
if (typeof window === 'undefined') {
return;
}
try {
// Allow value to be a function so we have same API as useState
const valueToStore =
value instanceof Function ? value(storedValue) : value;
// Save state
setStoredValue(val... | // Return a wrapped version of useState's setter function that ... | https://github.com/hyperdxio/hyperdx/blob/dacc630320adc0fb0e024d55a8496742f9364507/packages/app/src/utils.tsx#L202-L218 | dacc630320adc0fb0e024d55a8496742f9364507 |
ollama-js | github_2023 | ollama | typescript | addTwoNumbers | function addTwoNumbers(args: { a: number, b: number }): number {
return args.a + args.b;
} | // Add two numbers function | https://github.com/ollama/ollama-js/blob/9320655174ff83a5490fafc30a0e37ad52140c17/examples/tools/calculator.ts#L4-L6 | 9320655174ff83a5490fafc30a0e37ad52140c17 |
ollama-js | github_2023 | ollama | typescript | subtractTwoNumbers | function subtractTwoNumbers(args: { a: number, b: number }): number {
return args.a - args.b;
} | // Subtract two numbers function | https://github.com/ollama/ollama-js/blob/9320655174ff83a5490fafc30a0e37ad52140c17/examples/tools/calculator.ts#L9-L11 | 9320655174ff83a5490fafc30a0e37ad52140c17 |
ollama-js | github_2023 | ollama | typescript | getFlightTimes | function getFlightTimes(args: { [key: string]: any }) {
// this is where you would validate the arguments you received
const departure = args.departure;
const arrival = args.arrival;
const flights = {
"LGA-LAX": { departure: "08:00 AM", arrival: "11:30 AM", duration: "5h 30m" },
"LAX-LG... | // Simulates an API call to get flight times | https://github.com/ollama/ollama-js/blob/9320655174ff83a5490fafc30a0e37ad52140c17/examples/tools/flight-tracker.ts#L5-L21 | 9320655174ff83a5490fafc30a0e37ad52140c17 |
ollama-js | github_2023 | ollama | typescript | Ollama.abort | public abort() {
for (const request of this.ongoingStreamedRequests) {
request.abort()
}
this.ongoingStreamedRequests.length = 0
} | // Abort any ongoing streamed requests to Ollama | https://github.com/ollama/ollama-js/blob/9320655174ff83a5490fafc30a0e37ad52140c17/src/browser.ts#L49-L54 | 9320655174ff83a5490fafc30a0e37ad52140c17 |
ollama-js | github_2023 | ollama | typescript | Ollama.processStreamableRequest | protected async processStreamableRequest<T extends object>(
endpoint: string,
request: { stream?: boolean } & Record<string, any>,
): Promise<T | AbortableAsyncIterator<T>> {
request.stream = request.stream ?? false
const host = `${this.config.host}/api/${endpoint}`
if (request.stream) {
con... | /**
* Processes a request to the Ollama server. If the request is streamable, it will return a
* AbortableAsyncIterator that yields the response messages. Otherwise, it will return the response
* object.
* @param endpoint {string} - The endpoint to send the request to.
* @param request {object} - The req... | https://github.com/ollama/ollama-js/blob/9320655174ff83a5490fafc30a0e37ad52140c17/src/browser.ts#L67-L102 | 9320655174ff83a5490fafc30a0e37ad52140c17 |
ollama-js | github_2023 | ollama | typescript | Ollama.encodeImage | async encodeImage(image: Uint8Array | string): Promise<string> {
if (typeof image !== 'string') {
// image is Uint8Array, convert it to base64
const uint8Array = new Uint8Array(image);
let byteString = '';
const len = uint8Array.byteLength;
for (let i = 0; i < len; i++) {
byteString += Strin... | /**
* Encodes an image to base64 if it is a Uint8Array.
* @param image {Uint8Array | string} - The image to encode.
* @returns {Promise<string>} - The base64 encoded image.
*/ | https://github.com/ollama/ollama-js/blob/9320655174ff83a5490fafc30a0e37ad52140c17/src/browser.ts#L109-L122 | 9320655174ff83a5490fafc30a0e37ad52140c17 |
ollama-js | github_2023 | ollama | typescript | Ollama.generate | async generate(
request: GenerateRequest,
): Promise<GenerateResponse | AbortableAsyncIterator<GenerateResponse>> {
if (request.images) {
request.images = await Promise.all(request.images.map(this.encodeImage.bind(this)))
}
return this.processStreamableRequest<GenerateResponse>('generate', reque... | /**
* Generates a response from a text prompt.
* @param request {GenerateRequest} - The request object.
* @returns {Promise<GenerateResponse | AbortableAsyncIterator<GenerateResponse>>} - The response object or
* an AbortableAsyncIterator that yields response messages.
*/ | https://github.com/ollama/ollama-js/blob/9320655174ff83a5490fafc30a0e37ad52140c17/src/browser.ts#L134-L141 | 9320655174ff83a5490fafc30a0e37ad52140c17 |
ollama-js | github_2023 | ollama | typescript | Ollama.chat | async chat(
request: ChatRequest,
): Promise<ChatResponse | AbortableAsyncIterator<ChatResponse>> {
if (request.messages) {
for (const message of request.messages) {
if (message.images) {
message.images = await Promise.all(
message.images.map(this.encodeImage.bind(this)),
... | /**
* Chats with the model. The request object can contain messages with images that are either
* Uint8Arrays or base64 encoded strings. The images will be base64 encoded before sending the
* request.
* @param request {ChatRequest} - The request object.
* @returns {Promise<ChatResponse | AbortableAsyncIt... | https://github.com/ollama/ollama-js/blob/9320655174ff83a5490fafc30a0e37ad52140c17/src/browser.ts#L155-L168 | 9320655174ff83a5490fafc30a0e37ad52140c17 |
ollama-js | github_2023 | ollama | typescript | Ollama.create | async create(
request: CreateRequest
): Promise<ProgressResponse | AbortableAsyncIterator<ProgressResponse>> {
return this.processStreamableRequest<ProgressResponse>('create', {
...request
})
} | /**
* Creates a new model from a stream of data.
* @param request {CreateRequest} - The request object.
* @returns {Promise<ProgressResponse | AbortableAsyncIterator<ProgressResponse>>} - The response object or a stream of progress responses.
*/ | https://github.com/ollama/ollama-js/blob/9320655174ff83a5490fafc30a0e37ad52140c17/src/browser.ts#L179-L185 | 9320655174ff83a5490fafc30a0e37ad52140c17 |
ollama-js | github_2023 | ollama | typescript | Ollama.pull | async pull(
request: PullRequest,
): Promise<ProgressResponse | AbortableAsyncIterator<ProgressResponse>> {
return this.processStreamableRequest<ProgressResponse>('pull', {
name: request.model,
stream: request.stream,
insecure: request.insecure,
})
} | /**
* Pulls a model from the Ollama registry. The request object can contain a stream flag to indicate if the
* response should be streamed.
* @param request {PullRequest} - The request object.
* @returns {Promise<ProgressResponse | AbortableAsyncIterator<ProgressResponse>>} - The response object or
* an... | https://github.com/ollama/ollama-js/blob/9320655174ff83a5490fafc30a0e37ad52140c17/src/browser.ts#L198-L206 | 9320655174ff83a5490fafc30a0e37ad52140c17 |
ollama-js | github_2023 | ollama | typescript | Ollama.push | async push(
request: PushRequest,
): Promise<ProgressResponse | AbortableAsyncIterator<ProgressResponse>> {
return this.processStreamableRequest<ProgressResponse>('push', {
name: request.model,
stream: request.stream,
insecure: request.insecure,
})
} | /**
* Pushes a model to the Ollama registry. The request object can contain a stream flag to indicate if the
* response should be streamed.
* @param request {PushRequest} - The request object.
* @returns {Promise<ProgressResponse | AbortableAsyncIterator<ProgressResponse>>} - The response object or
* an ... | https://github.com/ollama/ollama-js/blob/9320655174ff83a5490fafc30a0e37ad52140c17/src/browser.ts#L219-L227 | 9320655174ff83a5490fafc30a0e37ad52140c17 |
ollama-js | github_2023 | ollama | typescript | Ollama.delete | async delete(request: DeleteRequest): Promise<StatusResponse> {
await utils.del(
this.fetch,
`${this.config.host}/api/delete`,
{ name: request.model },
{ headers: this.config.headers }
)
return { status: 'success' }
} | /**
* Deletes a model from the server. The request object should contain the name of the model to
* delete.
* @param request {DeleteRequest} - The request object.
* @returns {Promise<StatusResponse>} - The response object.
*/ | https://github.com/ollama/ollama-js/blob/9320655174ff83a5490fafc30a0e37ad52140c17/src/browser.ts#L235-L243 | 9320655174ff83a5490fafc30a0e37ad52140c17 |
ollama-js | github_2023 | ollama | typescript | Ollama.copy | async copy(request: CopyRequest): Promise<StatusResponse> {
await utils.post(this.fetch, `${this.config.host}/api/copy`, { ...request }, {
headers: this.config.headers
})
return { status: 'success' }
} | /**
* Copies a model from one name to another. The request object should contain the name of the
* model to copy and the new name.
* @param request {CopyRequest} - The request object.
* @returns {Promise<StatusResponse>} - The response object.
*/ | https://github.com/ollama/ollama-js/blob/9320655174ff83a5490fafc30a0e37ad52140c17/src/browser.ts#L251-L256 | 9320655174ff83a5490fafc30a0e37ad52140c17 |
ollama-js | github_2023 | ollama | typescript | Ollama.list | async list(): Promise<ListResponse> {
const response = await utils.get(this.fetch, `${this.config.host}/api/tags`, {
headers: this.config.headers
})
return (await response.json()) as ListResponse
} | /**
* Lists the models on the server.
* @returns {Promise<ListResponse>} - The response object.
* @throws {Error} - If the response body is missing.
*/ | https://github.com/ollama/ollama-js/blob/9320655174ff83a5490fafc30a0e37ad52140c17/src/browser.ts#L263-L268 | 9320655174ff83a5490fafc30a0e37ad52140c17 |
ollama-js | github_2023 | ollama | typescript | Ollama.show | async show(request: ShowRequest): Promise<ShowResponse> {
const response = await utils.post(this.fetch, `${this.config.host}/api/show`, {
...request,
}, {
headers: this.config.headers
})
return (await response.json()) as ShowResponse
} | /**
* Shows the metadata of a model. The request object should contain the name of the model.
* @param request {ShowRequest} - The request object.
* @returns {Promise<ShowResponse>} - The response object.
*/ | https://github.com/ollama/ollama-js/blob/9320655174ff83a5490fafc30a0e37ad52140c17/src/browser.ts#L275-L282 | 9320655174ff83a5490fafc30a0e37ad52140c17 |
ollama-js | github_2023 | ollama | typescript | Ollama.embed | async embed(request: EmbedRequest): Promise<EmbedResponse> {
const response = await utils.post(this.fetch, `${this.config.host}/api/embed`, {
...request,
}, {
headers: this.config.headers
})
return (await response.json()) as EmbedResponse
} | /**
* Embeds text input into vectors.
* @param request {EmbedRequest} - The request object.
* @returns {Promise<EmbedResponse>} - The response object.
*/ | https://github.com/ollama/ollama-js/blob/9320655174ff83a5490fafc30a0e37ad52140c17/src/browser.ts#L289-L296 | 9320655174ff83a5490fafc30a0e37ad52140c17 |
ollama-js | github_2023 | ollama | typescript | Ollama.embeddings | async embeddings(request: EmbeddingsRequest): Promise<EmbeddingsResponse> {
const response = await utils.post(this.fetch, `${this.config.host}/api/embeddings`, {
...request,
}, {
headers: this.config.headers
})
return (await response.json()) as EmbeddingsResponse
} | /**
* Embeds a text prompt into a vector.
* @param request {EmbeddingsRequest} - The request object.
* @returns {Promise<EmbeddingsResponse>} - The response object.
*/ | https://github.com/ollama/ollama-js/blob/9320655174ff83a5490fafc30a0e37ad52140c17/src/browser.ts#L303-L310 | 9320655174ff83a5490fafc30a0e37ad52140c17 |
ollama-js | github_2023 | ollama | typescript | Ollama.ps | async ps(): Promise<ListResponse> {
const response = await utils.get(this.fetch, `${this.config.host}/api/ps`, {
headers: this.config.headers
})
return (await response.json()) as ListResponse
} | /**
* Lists the running models on the server
* @returns {Promise<ListResponse>} - The response object.
* @throws {Error} - If the response body is missing.
*/ | https://github.com/ollama/ollama-js/blob/9320655174ff83a5490fafc30a0e37ad52140c17/src/browser.ts#L317-L322 | 9320655174ff83a5490fafc30a0e37ad52140c17 |
ollama-js | github_2023 | ollama | typescript | Ollama.fileExists | private async fileExists(path: string): Promise<boolean> {
try {
await promises.access(path)
return true
} catch {
return false
}
} | /**
* checks if a file exists
* @param path {string} - The path to the file
* @private @internal
* @returns {Promise<boolean>} - Whether the file exists or not
*/ | https://github.com/ollama/ollama-js/blob/9320655174ff83a5490fafc30a0e37ad52140c17/src/index.ts#L34-L41 | 9320655174ff83a5490fafc30a0e37ad52140c17 |
ollama-js | github_2023 | ollama | typescript | checkOk | const checkOk = async (response: Response): Promise<void> => {
if (response.ok) {
return
}
let message = `Error ${response.status}: ${response.statusText}`
let errorData: ErrorResponse | null = null
if (response.headers.get('content-type')?.includes('application/json')) {
try {
errorData = (awa... | /**
* Checks if the response is ok, if not throws an error.
* If the response is not ok, it will try to parse the response as JSON and use the error field as the error message.
* @param response {Response} - The response object to check
*/ | https://github.com/ollama/ollama-js/blob/9320655174ff83a5490fafc30a0e37ad52140c17/src/utils.ts#L63-L88 | 9320655174ff83a5490fafc30a0e37ad52140c17 |
ollama-js | github_2023 | ollama | typescript | getPlatform | function getPlatform(): string {
if (typeof window !== 'undefined' && window.navigator) {
return `${window.navigator.platform.toLowerCase()} Browser/${navigator.userAgent};`
} else if (typeof process !== 'undefined') {
return `${process.arch} ${process.platform} Node.js/${process.version}`
}
return '' /... | /**
* Returns the platform string based on the environment.
* @returns {string} - The platform string
*/ | https://github.com/ollama/ollama-js/blob/9320655174ff83a5490fafc30a0e37ad52140c17/src/utils.ts#L94-L101 | 9320655174ff83a5490fafc30a0e37ad52140c17 |
ollama-js | github_2023 | ollama | typescript | fetchWithHeaders | const fetchWithHeaders = async (
fetch: Fetch,
url: string,
options: RequestInit = {},
): Promise<Response> => {
const defaultHeaders = {
'Content-Type': 'application/json',
Accept: 'application/json',
'User-Agent': `ollama-js/${version} (${getPlatform()})`,
} as HeadersInit
if (!options.header... | /**
* A wrapper around fetch that adds default headers.
* @param fetch {Fetch} - The fetch function to use
* @param url {string} - The URL to fetch
* @param options {RequestInit} - The fetch options
* @returns {Promise<Response>} - The fetch response
*/ | https://github.com/ollama/ollama-js/blob/9320655174ff83a5490fafc30a0e37ad52140c17/src/utils.ts#L110-L136 | 9320655174ff83a5490fafc30a0e37ad52140c17 |
cortex.cpp | github_2023 | janhq | typescript | createDefaultScalarOptions | const createDefaultScalarOptions = (options: ScalarOptions): ScalarOptions => ({
showNavLink: true,
...options,
}); | /**
* Used to set default options from the user-provided options
* This is also useful to ensure backwards compatibility with older configs that don't have the new options
*/ | https://github.com/janhq/cortex.cpp/blob/f9364aa5e45c587684ca15e7875737bb5aa6c0fb/docs/src/plugins/scalar/index.ts#L14-L17 | f9364aa5e45c587684ca15e7875737bb5aa6c0fb |
cortex.cpp | github_2023 | janhq | typescript | ScalarDocusaurusCustomPlugin | function ScalarDocusaurusCustomPlugin(
context: LoadContext,
options: ScalarOptions
): Plugin<ReferenceProps> {
const defaultOptions = createDefaultScalarOptions(options);
return {
name: "@scalar/docusaurus",
async loadContent() {
return defaultOptions;
},
async contentLoaded({ content,... | /**
* Scalar's Docusaurus plugin for Api References
*/ | https://github.com/janhq/cortex.cpp/blob/f9364aa5e45c587684ca15e7875737bb5aa6c0fb/docs/src/plugins/scalar/index.ts#L22-L60 | f9364aa5e45c587684ca15e7875737bb5aa6c0fb |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | normalizeOptionValue | function normalizeOptionValue(option: RuleOptions[0]) {
let consistent = false
let multiline = false
let minItems = 0
if (option) {
if (option === 'consistent') {
consistent = true
minItems = Number.POSITIVE_INFINITY
}
else if (option === 'always' || ... | /**
* Normalizes a given option value.
* @param option An option value to parse.
* @returns Normalized option object.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/array-bracket-newline/array-bracket-newline._js_.ts#L63-L91 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | normalizeOptions | function normalizeOptions(options: RuleOptions[0]) {
const value = normalizeOptionValue(options)
return { ArrayExpression: value, ArrayPattern: value }
} | /**
* Normalizes a given option value.
* @param options An option value to parse.
* @returns Normalized option object.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/array-bracket-newline/array-bracket-newline._js_.ts#L98-L102 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | reportNoBeginningLinebreak | function reportNoBeginningLinebreak(node: ASTNode, token: Token) {
context.report({
node,
loc: token.loc,
messageId: 'unexpectedOpeningLinebreak',
fix(fixer) {
const nextToken = sourceCode.getTokenAfter(token, { includeComments: true })
if (!nextToken || isComm... | /**
* Reports that there shouldn't be a linebreak after the first token
* @param node The node to report in the event of an error.
* @param token The token to use for the report.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/array-bracket-newline/array-bracket-newline._js_.ts#L109-L123 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | reportNoEndingLinebreak | function reportNoEndingLinebreak(node: ASTNode, token: Token) {
context.report({
node,
loc: token.loc,
messageId: 'unexpectedClosingLinebreak',
fix(fixer) {
const previousToken = sourceCode.getTokenBefore(token, { includeComments: true })
if (!previousToken || ... | /**
* Reports that there shouldn't be a linebreak before the last token
* @param node The node to report in the event of an error.
* @param token The token to use for the report.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/array-bracket-newline/array-bracket-newline._js_.ts#L130-L144 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | reportRequiredBeginningLinebreak | function reportRequiredBeginningLinebreak(node: ASTNode, token: Token) {
context.report({
node,
loc: token.loc,
messageId: 'missingOpeningLinebreak',
fix(fixer) {
return fixer.insertTextAfter(token, '\n')
},
})
} | /**
* Reports that there should be a linebreak after the first token
* @param node The node to report in the event of an error.
* @param token The token to use for the report.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/array-bracket-newline/array-bracket-newline._js_.ts#L151-L160 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | reportRequiredEndingLinebreak | function reportRequiredEndingLinebreak(node: ASTNode, token: Token) {
context.report({
node,
loc: token.loc,
messageId: 'missingClosingLinebreak',
fix(fixer) {
return fixer.insertTextBefore(token, '\n')
},
})
} | /**
* Reports that there should be a linebreak before the last token
* @param node The node to report in the event of an error.
* @param token The token to use for the report.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/array-bracket-newline/array-bracket-newline._js_.ts#L167-L176 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | check | function check(node: ASTNode) {
// @ts-expect-error type cast
const elements = node.elements
const normalizedOptions = normalizeOptions(context.options[0])
// @ts-expect-error type cast
const options = normalizedOptions[node.type]
const openBracket = sourceCode.getFirstToken(node)!
... | /**
* Reports a given node if it violated this rule.
* @param node A node to check. This is an ArrayExpression node or an ArrayPattern node.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/array-bracket-newline/array-bracket-newline._js_.ts#L182-L234 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isOptionSet | function isOptionSet(option: keyof NonNullable<RuleOptions[1]>) {
return context.options[1] ? context.options[1][option] === !spaced : false
} | /**
* Determines whether an option is set, relative to the spacing option.
* If spaced is "always", then check whether option is set to false.
* If spaced is "never", then check whether option is set to true.
* @param option The option to exclude.
* @returns Whether or not the property is exclu... | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/array-bracket-spacing/array-bracket-spacing._js_.ts#L63-L65 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | reportNoBeginningSpace | function reportNoBeginningSpace(node: ASTNode, token: Token) {
const nextToken = sourceCode.getTokenAfter(token)!
context.report({
node,
loc: { start: token.loc.end, end: nextToken.loc.start },
messageId: 'unexpectedSpaceAfter',
data: {
tokenValue: token.value,
... | /**
* Reports that there shouldn't be a space after the first token
* @param node The node to report in the event of an error.
* @param token The token to use for the report.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/array-bracket-spacing/array-bracket-spacing._js_.ts#L79-L93 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | reportNoEndingSpace | function reportNoEndingSpace(node: ASTNode, token: Token) {
const previousToken = sourceCode.getTokenBefore(token)!
context.report({
node,
loc: { start: previousToken.loc.end, end: token.loc.start },
messageId: 'unexpectedSpaceBefore',
data: {
tokenValue: token.val... | /**
* Reports that there shouldn't be a space before the last token
* @param node The node to report in the event of an error.
* @param token The token to use for the report.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/array-bracket-spacing/array-bracket-spacing._js_.ts#L100-L114 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | reportRequiredBeginningSpace | function reportRequiredBeginningSpace(node: ASTNode, token: Token) {
context.report({
node,
loc: token.loc,
messageId: 'missingSpaceAfter',
data: {
tokenValue: token.value,
},
fix(fixer) {
return fixer.insertTextAfter(token, ' ')
},
... | /**
* Reports that there should be a space after the first token
* @param node The node to report in the event of an error.
* @param token The token to use for the report.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/array-bracket-spacing/array-bracket-spacing._js_.ts#L121-L133 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | reportRequiredEndingSpace | function reportRequiredEndingSpace(node: ASTNode, token: Token) {
context.report({
node,
loc: token.loc,
messageId: 'missingSpaceBefore',
data: {
tokenValue: token.value,
},
fix(fixer) {
return fixer.insertTextBefore(token, ' ')
},
... | /**
* Reports that there should be a space before the last token
* @param node The node to report in the event of an error.
* @param token The token to use for the report.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/array-bracket-spacing/array-bracket-spacing._js_.ts#L140-L152 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isObjectType | function isObjectType(node: ASTNode) {
return node && (node.type === 'ObjectExpression' || node.type === 'ObjectPattern')
} | /**
* Determines if a node is an object type
* @param node The node to check.
* @returns Whether or not the node is an object type.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/array-bracket-spacing/array-bracket-spacing._js_.ts#L159-L161 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isArrayType | function isArrayType(node: ASTNode) {
return node && (node.type === 'ArrayExpression' || node.type === 'ArrayPattern')
} | /**
* Determines if a node is an array type
* @param node The node to check.
* @returns Whether or not the node is an array type.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/array-bracket-spacing/array-bracket-spacing._js_.ts#L168-L170 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | validateArraySpacing | function validateArraySpacing(node: Tree.ArrayPattern | Tree.ArrayExpression) {
if (options.spaced && node.elements.length === 0)
return
const first = sourceCode.getFirstToken(node)!
const second = sourceCode.getFirstToken(node, 1)!
const last = node.type === 'ArrayPattern' && node.type... | /**
* Validates the spacing around array brackets
* @param node The node we're checking for spacing
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/array-bracket-spacing/array-bracket-spacing._js_.ts#L176-L216 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | normalizeOptionValue | function normalizeOptionValue(providedOption: BasicConfig) {
let consistent = false
let multiline = false
let minItems: number
const option = providedOption || 'always'
if (!option || option === 'always' || typeof option === 'object' && option.minItems === 0) {
minItems = 0
... | /**
* Normalizes a given option value.
* @param providedOption An option value to parse.
* @returns Normalized option object.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/array-element-newline/array-element-newline._js_.ts#L89-L113 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | normalizeOptions | function normalizeOptions(options: any) {
if (options && (options.ArrayExpression || options.ArrayPattern)) {
let expressionOptions, patternOptions
if (options.ArrayExpression)
expressionOptions = normalizeOptionValue(options.ArrayExpression)
if (options.ArrayPattern)
... | /**
* Normalizes a given option value.
* @param options An option value to parse.
* @returns Normalized option object.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/array-element-newline/array-element-newline._js_.ts#L120-L136 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | reportNoLineBreak | function reportNoLineBreak(token: Token): void {
const tokenBefore = sourceCode.getTokenBefore(token, { includeComments: true })
context.report({
loc: {
start: tokenBefore!.loc.end,
end: token.loc.start,
},
messageId: 'unexpectedLineBreak',
fix(fixer) {
... | /**
* Reports that there shouldn't be a line break after the first token
* @param token The token to use for the report.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/array-element-newline/array-element-newline._js_.ts#L142-L180 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | reportRequiredLineBreak | function reportRequiredLineBreak(token: Token): void {
const tokenBefore = sourceCode.getTokenBefore(token, { includeComments: true })
context.report({
loc: {
start: tokenBefore!.loc.end,
end: token.loc.start,
},
messageId: 'missingLineBreak',
fix(fixer) ... | /**
* Reports that there should be a line break after the first token
* @param token The token to use for the report.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/array-element-newline/array-element-newline._js_.ts#L186-L199 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | check | function check(node: Tree.ArrayPattern | Tree.ArrayExpression): void {
const elements = node.elements
const normalizedOptions = normalizeOptions(context.options[0])
const options = normalizedOptions[node.type]
if (!options)
return
let elementBreak = false
/**
* MULT... | /**
* Reports a given node if it violated this rule.
* @param node A node to check. This is an ObjectExpression node or an ObjectPattern node.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/array-element-newline/array-element-newline._js_.ts#L205-L282 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | hasBlockBody | function hasBlockBody(node: Tree.ArrowFunctionExpression) {
return node.body.type === 'BlockStatement'
} | /**
* Determines if the given arrow function has block body.
* @param node `ArrowFunctionExpression` node.
* @returns `true` if the function has block body.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/arrow-parens/arrow-parens._js_.ts#L16-L18 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | findOpeningParenOfParams | function findOpeningParenOfParams(node: Tree.ArrowFunctionExpression) {
const tokenBeforeParams = sourceCode.getTokenBefore(node.params[0])
if (
tokenBeforeParams
&& isOpeningParenToken(tokenBeforeParams)
&& node.range[0] <= tokenBeforeParams.range[0]
) {
return tokenB... | /**
* Finds opening paren of parameters for the given arrow function, if it exists.
* It is assumed that the given arrow function has exactly one parameter.
* @param node `ArrowFunctionExpression` node.
* @returns the opening paren, or `null` if the given arrow function doesn't have parens of parame... | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/arrow-parens/arrow-parens._js_.ts#L70-L82 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | getClosingParenOfParams | function getClosingParenOfParams(node: Tree.ArrowFunctionExpression) {
return sourceCode.getTokenAfter(node.params[0], isClosingParenToken)
} | /**
* Finds closing paren of parameters for the given arrow function.
* It is assumed that the given arrow function has parens of parameters and that it has exactly one parameter.
* @param node `ArrowFunctionExpression` node.
* @returns the closing paren of parameters.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/arrow-parens/arrow-parens._js_.ts#L90-L92 | 481d54b6521b8705570132424c78d320dec57610 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.