repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
llama-coder | github_2023 | ex3ndr | typescript | normalizeText | function normalizeText(src: string) {
src = src.split('\n').join(' ');
src = src.replace(/\s+/gm, ' ');
return src;
} | // Remove all newlines, double spaces, etc | https://github.com/ex3ndr/llama-coder/blob/d4b65d6737e2c5d4b5797fd77e18e740dd9355df/src/prompts/promptCache.ts#L3-L7 | d4b65d6737e2c5d4b5797fd77e18e740dd9355df |
chrome-power-app | github_2023 | zmzimpl | typescript | findAvailablePortAndStartServer | async function findAvailablePortAndStartServer() {
if (!isDev) {
PORT = await portscanner.findAPortNotInUse(5173, 8000);
server.use(express.static(resolve(__dirname, '../../renderer/dist')));
server.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
serverStarted = true;
});
}
} | // 仅在生产环境下启动Express服务器 | https://github.com/zmzimpl/chrome-power-app/blob/7c4f40f757838274a54caf1320e59fd04b04f4f3/packages/main/src/mainWindow.ts#L13-L22 | 7c4f40f757838274a54caf1320e59fd04b04f4f3 |
chrome-power-app | github_2023 | zmzimpl | typescript | initializeDatabase | const initializeDatabase = async () => {
const userDataPath = app.getPath('userData');
// 确保目录存在
if (!existsSync(userDataPath)) {
mkdirSync(userDataPath, { recursive: true });
}
try {
// 初始化数据库连接
await db.raw('SELECT 1');
// 运行迁移
await db.migrate.latest({
directory: app.isPackaged
? join(process.resourcesPath, 'app/migrations')
: './migrations',
});
// 初始化窗口状态
await initWindowStatus();
console.log('Database initialized successfully');
} catch (error) {
console.error('Database initialization failed:', error);
throw error;
}
}; | // const deleteAll = async () => { | https://github.com/zmzimpl/chrome-power-app/blob/7c4f40f757838274a54caf1320e59fd04b04f4f3/packages/main/src/db/index.ts#L32-L59 | 7c4f40f757838274a54caf1320e59fd04b04f4f3 |
chrome-power-app | github_2023 | zmzimpl | typescript | getDriverPath | const getDriverPath = () => {
const settings = getSettings();
if (settings.useLocalChrome) {
return settings.localChromePath;
} else {
return settings.chromiumBinPath;
}
}; | // async function connectBrowser( | https://github.com/zmzimpl/chrome-power-app/blob/7c4f40f757838274a54caf1320e59fd04b04f4f3/packages/main/src/fingerprint/index.ts#L89-L97 | 7c4f40f757838274a54caf1320e59fd04b04f4f3 |
chrome-power-app | github_2023 | zmzimpl | typescript | getCookie | const getCookie = (windowId: number, domain: CookieDomain) => {
const map = cookieMap.get(windowId);
if (map) {
return map.get(domain);
}
return null;
}; | // const cookieToMap = (windowId: number, cookies: ICookie[]) => { | https://github.com/zmzimpl/chrome-power-app/blob/7c4f40f757838274a54caf1320e59fd04b04f4f3/packages/main/src/puppeteer/helpers.ts#L30-L36 | 7c4f40f757838274a54caf1320e59fd04b04f4f3 |
react-native-live-markdown | github_2023 | Expensify | typescript | getTagPriority | function getTagPriority(tag: string) {
switch (tag) {
case 'blockquote':
return 2;
case 'h1':
return 1;
default:
return 0;
}
} | // getTagPriority returns a priority for a tag, higher priority means the tag should be processed first | https://github.com/Expensify/react-native-live-markdown/blob/958dbd95c635c78ce491105368b5ac45adba228e/src/rangeUtils.ts#L6-L15 | 958dbd95c635c78ce491105368b5ac45adba228e |
react-native-live-markdown | github_2023 | Expensify | typescript | updateImageTreeNode | function updateImageTreeNode(targetNode: TreeNode, newElement: HTMLMarkdownElement, imageMarginTop = 0) {
const paddingBottom = `${parseStringWithUnitToNumber(newElement.style.height) + imageMarginTop}px`;
targetNode.element.appendChild(newElement.cloneNode(true));
let currentParent = targetNode.element;
while (currentParent.parentElement && !['line', 'block'].includes(currentParent.getAttribute('data-type') || '')) {
currentParent = currentParent.parentElement as HTMLMarkdownElement;
}
Object.assign(currentParent.style, {
paddingBottom,
});
return targetNode;
} | /** Adds already loaded image element from current input content to the tree node */ | https://github.com/Expensify/react-native-live-markdown/blob/958dbd95c635c78ce491105368b5ac45adba228e/src/web/inputElements/inlineImage.ts#L134-L147 | 958dbd95c635c78ce491105368b5ac45adba228e |
react-native-live-markdown | github_2023 | Expensify | typescript | addInlineImagePreview | function addInlineImagePreview(
currentInput: MarkdownTextInputElement,
targetNode: TreeNode,
text: string,
ranges: MarkdownRange[],
markdownStyle: PartialMarkdownStyle,
inlineImagesProps: InlineImagesInputProps,
) {
const {addAuthTokenToImageURLCallback, imagePreviewAuthRequiredURLs} = inlineImagesProps;
const linkRange = ranges.find((r) => r.type === 'link');
let imageHref = '';
if (linkRange) {
imageHref = text.substring(linkRange.start, linkRange.start + linkRange.length);
if (addAuthTokenToImageURLCallback && imagePreviewAuthRequiredURLs && imagePreviewAuthRequiredURLs.find((url) => imageHref.startsWith(url))) {
imageHref = addAuthTokenToImageURLCallback(imageHref);
}
}
const imageMarginTop = parseStringWithUnitToNumber(`${markdownStyle.inlineImage?.marginTop}`);
const imageMarginBottom = parseStringWithUnitToNumber(`${markdownStyle.inlineImage?.marginBottom}`);
// If the inline image markdown with the same href exists in the current input, use it instead of creating new one.
// Prevents from image flickering and layout jumps
const alreadyLoadedPreview = currentInput.imageElements?.find((el) => el?.src === imageHref);
const loadedImageContainer = alreadyLoadedPreview?.parentElement;
if (loadedImageContainer && loadedImageContainer.getAttribute('data-type') === 'inline-container') {
return updateImageTreeNode(targetNode, loadedImageContainer as HTMLMarkdownElement, imageMarginTop);
}
// Add a loading spinner
const spinner = createLoadingIndicator(imageHref, markdownStyle);
if (spinner) {
targetNode.element.appendChild(spinner);
}
Object.assign(targetNode.element.style, {
display: 'block',
marginBottom: `${imageMarginBottom}px`,
paddingBottom: markdownStyle.loadingIndicatorContainer?.height || markdownStyle.loadingIndicator?.height || (!!markdownStyle.loadingIndicator && '30px') || undefined,
});
createImageElement(currentInput, targetNode, imageHref, markdownStyle);
return targetNode;
} | /** The main function that adds inline image preview to the node */ | https://github.com/Expensify/react-native-live-markdown/blob/958dbd95c635c78ce491105368b5ac45adba228e/src/web/inputElements/inlineImage.ts#L150-L195 | 958dbd95c635c78ce491105368b5ac45adba228e |
react-native-live-markdown | github_2023 | Expensify | typescript | createLoadingIndicator | function createLoadingIndicator(url: string, markdownStyle: PartialMarkdownStyle) {
const container = document.createElement('span');
container.contentEditable = 'false';
const spinner = document.createElement('span');
const spinnerStyles = markdownStyle.loadingIndicator;
if (spinnerStyles) {
const spinnerBorderWidth = spinnerStyles.borderWidth || 3;
Object.assign(spinner.style, {
...spinnerDefaultStyles,
border: `${spinnerBorderWidth}px solid ${String(spinnerStyles.secondaryColor)}`,
borderTop: `${spinnerBorderWidth}px solid ${String(spinnerStyles.primaryColor)}`,
width: spinnerStyles.width || '20px',
height: spinnerStyles.height || '20px',
});
}
const containerStyles = markdownStyle.loadingIndicatorContainer;
Object.assign(container.style, {
...markdownStyle.loadingIndicatorContainer,
...spinnerContainerDefaultStyles,
width: containerStyles?.width || 'auto',
height: containerStyles?.height || 'auto',
});
container.setAttribute('data-type', 'spinner');
container.setAttribute('data-url', url);
container.contentEditable = 'false';
container.appendChild(spinner);
return container;
} | /** Creates animated loading spinner */ | https://github.com/Expensify/react-native-live-markdown/blob/958dbd95c635c78ce491105368b5ac45adba228e/src/web/inputElements/loadingIndicator.ts#L18-L49 | 958dbd95c635c78ce491105368b5ac45adba228e |
react-native-live-markdown | github_2023 | Expensify | typescript | getAnimationCurrentTimes | function getAnimationCurrentTimes(currentInput: MarkdownTextInputElement): AnimationTimes {
const animationTimes: AnimationTimes = {};
ANIMATED_ELEMENT_TYPES.forEach((type) => {
const elements = currentInput.querySelectorAll(`[data-type="${type}"]`);
animationTimes[type] = Array.from(elements).map((element) => {
const animation = (element.firstChild as HTMLMarkdownElement).getAnimations()[0];
if (animation) {
return animation.currentTime || 0;
}
return 0;
});
});
return animationTimes;
} | /** Gets the current times of all animated elements inside the input */ | https://github.com/Expensify/react-native-live-markdown/blob/958dbd95c635c78ce491105368b5ac45adba228e/src/web/utils/animationUtils.ts#L25-L40 | 958dbd95c635c78ce491105368b5ac45adba228e |
react-native-live-markdown | github_2023 | Expensify | typescript | updateAnimationsTime | function updateAnimationsTime(currentInput: MarkdownTextInputElement, animationTimes: AnimationTimes) {
ANIMATED_ELEMENT_TYPES.forEach((type) => {
const elements = currentInput.querySelectorAll(`[data-type="${type}"]`);
if (!KEYFRAMES[type]) {
return;
}
elements.forEach((element, index) => {
const animation = (element.firstChild as HTMLMarkdownElement).animate(KEYFRAMES[type] as Keyframe[], OPTIONS[type]);
if (animationTimes?.[type] && animation) {
animation.currentTime = animationTimes[type]?.[index] || 0;
}
});
});
} | /** Updates the current times of all animated elements inside the input, to preserve their state between input rerenders */ | https://github.com/Expensify/react-native-live-markdown/blob/958dbd95c635c78ce491105368b5ac45adba228e/src/web/utils/animationUtils.ts#L43-L57 | 958dbd95c635c78ce491105368b5ac45adba228e |
react-native-live-markdown | github_2023 | Expensify | typescript | isEventComposing | function isEventComposing(nativeEvent: globalThis.KeyboardEvent | MarkdownNativeEvent) {
return nativeEvent.isComposing || nativeEvent.keyCode === 229;
} | // If an Input Method Editor is processing key input, the 'keyCode' is 229. | https://github.com/Expensify/react-native-live-markdown/blob/958dbd95c635c78ce491105368b5ac45adba228e/src/web/utils/inputUtils.ts#L8-L10 | 958dbd95c635c78ce491105368b5ac45adba228e |
react-native-live-markdown | github_2023 | Expensify | typescript | parseInnerHTMLToText | function parseInnerHTMLToText(target: MarkdownTextInputElement, cursorPosition: number, inputType?: string): string {
// Returns the parent of a given node that is higher in the hierarchy and is of a different type than 'text', 'br' or 'line'
function getTopParentNode(node: ChildNode) {
let currentParentNode = node.parentNode;
while (currentParentNode && ['text', 'br', 'line'].includes(currentParentNode.parentElement?.getAttribute('data-type') || '')) {
currentParentNode = currentParentNode?.parentNode || null;
}
return currentParentNode;
}
const stack: ChildNode[] = [target];
let text = '';
let shouldAddNewline = false;
const lastNode = target.childNodes[target.childNodes.length - 1];
// Remove the last <br> element if it's the last child of the target element. Fixes the issue with adding extra newline when pasting into the empty input.
if (lastNode?.nodeName === 'DIV' && (lastNode as HTMLElement)?.innerHTML === '<br>') {
target.removeChild(lastNode);
}
while (stack.length > 0) {
const node = stack.pop();
if (!node) {
break;
}
// If we are operating on the nodes that are children of the MarkdownTextInputElement, we need to add a newline after each
const isTopComponent = node.parentElement?.contentEditable === 'true';
if (isTopComponent) {
// Replaced text is beeing added as text node, so we need to not add the newline before and after it
if (node.nodeType === Node.TEXT_NODE) {
shouldAddNewline = false;
} else {
const firstChild = node.firstChild as HTMLElement;
const containsEmptyBlockElement = firstChild?.getAttribute?.('data-type') === 'block' && firstChild.textContent === '';
if (shouldAddNewline && !containsEmptyBlockElement) {
text += '\n';
shouldAddNewline = false;
}
shouldAddNewline = true;
}
}
if (node.nodeType === Node.TEXT_NODE) {
// Parse text nodes into text
text += node.textContent;
} else if (node.nodeName === 'BR') {
const parentNode = getTopParentNode(node);
if (parentNode && parentNode.parentElement?.contentEditable !== 'true' && !!(node as HTMLElement).getAttribute('data-id')) {
// Parse br elements into newlines only if their parent is not a child of the MarkdownTextInputElement (a paragraph when writing or a div when pasting).
// It prevents adding extra newlines when entering text
text += '\n';
}
} else {
let i = node.childNodes.length - 1;
while (i > -1) {
const child = node.childNodes[i];
if (!child) {
break;
}
stack.push(child);
i--;
}
}
}
text = text.replaceAll('\r\n', '\n');
// Force letter removal if the input value haven't changed but input type is 'delete'
if (text === target.value && inputType?.includes('delete')) {
text = text.slice(0, cursorPosition - 1) + text.slice(cursorPosition);
}
return text;
} | // Parses the HTML structure of a MarkdownTextInputElement to a plain text string. Used for getting the correct value of the input element. | https://github.com/Expensify/react-native-live-markdown/blob/958dbd95c635c78ce491105368b5ac45adba228e/src/web/utils/inputUtils.ts#L40-L111 | 958dbd95c635c78ce491105368b5ac45adba228e |
react-native-live-markdown | github_2023 | Expensify | typescript | getTopParentNode | function getTopParentNode(node: ChildNode) {
let currentParentNode = node.parentNode;
while (currentParentNode && ['text', 'br', 'line'].includes(currentParentNode.parentElement?.getAttribute('data-type') || '')) {
currentParentNode = currentParentNode?.parentNode || null;
}
return currentParentNode;
} | // Returns the parent of a given node that is higher in the hierarchy and is of a different type than 'text', 'br' or 'line' | https://github.com/Expensify/react-native-live-markdown/blob/958dbd95c635c78ce491105368b5ac45adba228e/src/web/utils/inputUtils.ts#L42-L48 | 958dbd95c635c78ce491105368b5ac45adba228e |
react-native-live-markdown | github_2023 | Expensify | typescript | mergeLinesWithMultilineTags | function mergeLinesWithMultilineTags(lines: Paragraph[], ranges: MarkdownRange[]) {
let mergedLines = [...lines];
const lineIndexes = mergedLines.map((_line, index) => index);
ranges.forEach((range) => {
const beginLineIndex = mergedLines.findLastIndex((line) => line.start <= range.start);
const endLineIndex = mergedLines.findIndex((line) => line.start + line.length >= range.start + range.length);
const correspondingLineIndexes = lineIndexes.slice(beginLineIndex, endLineIndex + 1);
if (correspondingLineIndexes.length > 0) {
const mainLineIndex = correspondingLineIndexes[0] as number;
const mainLine = mergedLines[mainLineIndex] as Paragraph;
mainLine.markdownRanges.push(range);
const otherLineIndexes = correspondingLineIndexes.slice(1);
otherLineIndexes.forEach((lineIndex) => {
const otherLine = mergedLines[lineIndex] as Paragraph;
mainLine.text += `\n${otherLine.text}`;
mainLine.length += otherLine.length + 1;
mainLine.markdownRanges.push(...otherLine.markdownRanges);
});
if (otherLineIndexes.length > 0) {
mergedLines = mergedLines.filter((_line, index) => !otherLineIndexes.includes(index));
}
}
});
return mergedLines;
} | /** Merges lines that contain multiline markdown tags into one line */ | https://github.com/Expensify/react-native-live-markdown/blob/958dbd95c635c78ce491105368b5ac45adba228e/src/web/utils/parserUtils.ts#L35-L65 | 958dbd95c635c78ce491105368b5ac45adba228e |
react-native-live-markdown | github_2023 | Expensify | typescript | appendValueToElement | function appendValueToElement(element: HTMLMarkdownElement, parentTreeNode: TreeNode, value: string) {
const targetElement = element;
const parentNode = parentTreeNode;
targetElement.value = value;
parentNode.element.value = (parentNode.element.value || '') + value;
} | /** Adds a value prop to the element and appends the value to the parent node element */ | https://github.com/Expensify/react-native-live-markdown/blob/958dbd95c635c78ce491105368b5ac45adba228e/src/web/utils/parserUtils.ts#L68-L73 | 958dbd95c635c78ce491105368b5ac45adba228e |
react-native-live-markdown | github_2023 | Expensify | typescript | parseRangesToHTMLNodes | function parseRangesToHTMLNodes(
text: string,
ranges: MarkdownRange[],
isMultiline = true,
markdownStyle: PartialMarkdownStyle = {},
disableInlineStyles = false,
currentInput: MarkdownTextInputElement | null = null,
inlineImagesProps: InlineImagesInputProps = {},
) {
const rootElement: HTMLMarkdownElement = document.createElement('span') as HTMLMarkdownElement;
const textLength = text.length;
const rootNode: TreeNode = createRootTreeNode(rootElement, textLength);
let currentParentNode: TreeNode = rootNode;
let lines = splitTextIntoLines(text);
if (ranges.length === 0) {
lines.forEach((line) => {
addParagraph(rootNode, line.text, line.length, disableInlineStyles);
});
return {dom: rootElement, tree: rootNode};
}
// Sort all ranges by start position, length, and by tag hierarchy so the styles and text are applied in correct order
const sortedRanges = sortRanges(ranges);
const markdownRanges = ungroupRanges(sortedRanges);
lines = mergeLinesWithMultilineTags(lines, markdownRanges);
let lastRangeEndIndex = 0;
while (lines.length > 0) {
const line = lines.shift();
if (!line) {
break;
}
// preparing line paragraph element for markdown text
currentParentNode = addParagraph(rootNode, null, line.length, disableInlineStyles);
rootElement.value = (rootElement.value || '') + line.text;
if (lines.length > 0) {
rootElement.value = `${rootElement.value || ''}\n`;
}
if (line.markdownRanges.length === 0) {
addTextToElement(currentParentNode, line.text);
}
let wasBlockGenerated = false;
lastRangeEndIndex = line.start;
const lineMarkdownRanges = line.markdownRanges;
// go through all markdown ranges in the line
while (lineMarkdownRanges.length > 0) {
const range = lineMarkdownRanges.shift();
if (!range) {
break;
}
const endOfCurrentRange = range.start + range.length;
const nextRangeStartIndex = lineMarkdownRanges.length > 0 && !!lineMarkdownRanges[0] ? lineMarkdownRanges[0].start || 0 : textLength;
// wrap all elements before the first block type markdown range with a span element
const blockRange = getFirstBlockMarkdownRange([range, ...lineMarkdownRanges]);
if (!wasBlockGenerated && blockRange) {
currentParentNode = addBlockWrapper(currentParentNode, line.text.substring(lastRangeEndIndex - line.start, blockRange.start + blockRange.length - line.start).length, markdownStyle);
wasBlockGenerated = true;
}
// add text before the markdown range
const textBeforeRange = line.text.substring(lastRangeEndIndex - line.start, range.start - line.start);
if (textBeforeRange) {
addTextToElement(currentParentNode, textBeforeRange);
}
// create markdown span element
const span = document.createElement('span') as HTMLMarkdownElement;
span.setAttribute('data-type', range.type);
if (!disableInlineStyles) {
addStyleToBlock(span, range.type, markdownStyle, isMultiline);
}
const spanNode = appendNode(span, currentParentNode, range.type, range.length);
if (isMultiline && !disableInlineStyles && currentInput) {
currentParentNode = extendBlockStructure(currentInput, currentParentNode, range, lineMarkdownRanges, text, markdownStyle, inlineImagesProps);
}
if (lineMarkdownRanges.length > 0 && nextRangeStartIndex < endOfCurrentRange && range.type !== 'syntax') {
// tag nesting
currentParentNode = spanNode;
lastRangeEndIndex = range.start;
} else {
// adding markdown tag
addTextToElement(spanNode, text.substring(range.start, endOfCurrentRange), isMultiline);
currentParentNode.element.value = (currentParentNode.element.value || '') + (spanNode.element.value || '');
lastRangeEndIndex = endOfCurrentRange;
// tag unnesting and adding text after the tag
while (currentParentNode.parentNode !== null && nextRangeStartIndex >= currentParentNode.start + currentParentNode.length) {
const textAfterRange = line.text.substring(lastRangeEndIndex - line.start, currentParentNode.start - line.start + currentParentNode.length);
if (textAfterRange) {
addTextToElement(currentParentNode, textAfterRange);
}
lastRangeEndIndex = currentParentNode.start + currentParentNode.length;
if (currentParentNode.parentNode.type !== 'root') {
currentParentNode.parentNode.element.value = currentParentNode.element.value || '';
}
if (isBlockMarkdownType(currentParentNode.type)) {
wasBlockGenerated = false;
}
currentParentNode = currentParentNode.parentNode || rootNode;
}
}
}
}
return {dom: rootElement, tree: rootNode};
} | /** Builds HTML DOM structure based on passed text and markdown ranges */ | https://github.com/Expensify/react-native-live-markdown/blob/958dbd95c635c78ce491105368b5ac45adba228e/src/web/utils/parserUtils.ts#L140-L255 | 958dbd95c635c78ce491105368b5ac45adba228e |
altcha | github_2023 | altcha-org | typescript | PluginAnalytics.constructor | constructor(context: PluginContext) {
super(context);
this.#elForm = this.context.el.closest('form');
if (this.#elForm) {
let beaconUrl = this.#elForm.getAttribute('data-beacon-url');
const action = this.#elForm.getAttribute('action');
if (!beaconUrl && action) {
beaconUrl = action + '/beacon';
}
this.#elForm.addEventListener('submit', this.#_onFormSubmit);
this.#session = new Session(this.#elForm, beaconUrl);
}
} | /**
* Creates an instance of PluginAnalytics.
*
* @param {PluginContext} context - The context object containing plugin configurations.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/analytics.ts#L26-L38 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | PluginAnalytics.destroy | destroy() {
this.#elForm?.removeEventListener('submit', this.#_onFormSubmit);
this.#session?.destroy();
} | /**
* Destroys the plugin instance, removing event listeners and cleaning up the session.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/analytics.ts#L43-L46 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | PluginAnalytics.onErrorChange | onErrorChange(err: string | null): void {
this.#session?.trackError(err);
} | /**
* Tracks errors by forwarding them to the session instance.
*
* @param {string | null} err - The error message, or `null` if no error exists.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/analytics.ts#L53-L55 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | Session.constructor | constructor(
readonly elForm: HTMLFormElement,
public beaconUrl: string | null = null
) {
window.addEventListener('unload', this.#onUnload);
this.elForm.addEventListener('change', this.#onFormChange);
this.elForm.addEventListener('focusin', this.#onFormFocus);
} | /**
* Creates a new Session instance.
*
* @param {HTMLFormElement} elForm - The form element being tracked.
* @param {string | null} [beaconUrl=null] - The URL to send analytics data to.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/analytics.ts#L115-L122 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | Session.data | data() {
const fields = Object.entries(this.#fieldChanges);
return {
correction: fields.length
? fields.filter(([_, changes]) => changes > 1).length / fields.length ||
0
: 0,
dropoff:
!this.submitTime && !this.error && this.#lastInputName
? this.#lastInputName
: null,
error: this.error,
mobile: this.isMobile(),
start: this.startTime,
submit: this.submitTime,
tz: getTimeZone(),
};
} | /**
* Collects and returns analytics data about the form interaction.
*
* @returns {Record<string, unknown>} - An object containing analytics data.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/analytics.ts#L129-L146 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | Session.dataAsBase64 | dataAsBase64() {
try {
return btoa(JSON.stringify(this.data()));
} catch (err) {
console.error('failed to encode ALTCHA session data to base64', err);
}
return '';
} | /**
* Encodes the session data as a base64 string.
*
* @returns {string} - The base64-encoded session data.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/analytics.ts#L153-L160 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | Session.destroy | destroy() {
window.removeEventListener('unload', this.#onUnload);
this.elForm.removeEventListener('change', this.#onFormChange);
this.elForm.removeEventListener('focusin', this.#onFormFocus);
} | /**
* Destroys the session, removing event listeners.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/analytics.ts#L165-L169 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | Session.end | end() {
if (!this.submitTime) {
this.submitTime = Date.now();
}
} | /**
* Marks the session as ended by recording the submission time.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/analytics.ts#L174-L178 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | Session.getFieldName | getFieldName(el: HTMLInputElement, maxLength: number = 40) {
const group = el.getAttribute('data-group-label');
const name = el.getAttribute('name') || el.getAttribute('aria-label');
return ((group ? group + ': ' : '') + name).slice(0, maxLength);
} | /**
* Retrieves the name of a form field, including a group label if available.
*
* @param {HTMLInputElement} el - The input element.
* @param {number} [maxLength=40] - The maximum length of the field name.
* @returns {string} - The field name, truncated to `maxLength` if necessary.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/analytics.ts#L187-L191 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | Session.isMobile | isMobile(): boolean {
const userAgentData =
'userAgentData' in navigator && navigator.userAgentData
? (navigator.userAgentData as Record<string, unknown>)
: {};
if ('mobile' in userAgentData) {
return userAgentData.mobile === true;
}
// Fallback to user agent string analysis for mobile detection
return /Mobi/i.test(window.navigator.userAgent);
} | /**
* Determines if the current device is a mobile device.
*
* @returns {boolean} - `true` if the device is mobile, otherwise `false`.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/analytics.ts#L198-L208 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | Session.isInput | isInput(el: HTMLElement) {
return ['INPUT', 'SELECT', 'TEXTAREA'].includes(el.tagName);
} | /**
* Checks if a given element is an input element (input, select, or textarea).
*
* @param {HTMLElement} el - The element to check.
* @returns {boolean} - `true` if the element is an input, otherwise `false`.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/analytics.ts#L216-L218 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | Session.onFormFieldChange | onFormFieldChange(el: HTMLInputElement) {
const name = this.getFieldName(el);
if (name) {
this.trackFieldChange(name);
}
} | /**
* Tracks changes to a specific form field.
*
* @param {HTMLInputElement} el - The input element that changed.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/analytics.ts#L225-L230 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | Session.onFormChange | onFormChange(ev: Event) {
const target = ev.target as HTMLInputElement | null;
if (target && this.isInput(target)) {
this.onFormFieldChange(target);
}
} | /**
* Handles form change events, tracking changes to input fields.
*
* @param {Event} ev - The change event.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/analytics.ts#L237-L242 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | Session.onFormFocus | onFormFocus(ev: FocusEvent) {
const target = ev.target as HTMLInputElement | null;
if (!this.startTime) {
this.start();
}
if (target && this.isInput(target)) {
const name = this.getFieldName(target);
if (name) {
this.#lastInputName = name;
}
}
} | /**
* Handles form focus events, marking the session start time and tracking the last focused field.
*
* @param {FocusEvent} ev - The focus event.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/analytics.ts#L249-L260 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | Session.onUnload | onUnload() {
if (
this.loadTime <= Date.now() - this.viewTimeThresholdMs &&
!this.submitTime
) {
this.sendBeacon();
}
} | /**
* Handles the window unload event, sending a beacon with session data if the form was viewed but not submitted.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/analytics.ts#L265-L272 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | Session.sendBeacon | async sendBeacon() {
if (this.beaconUrl && 'sendBeacon' in navigator) {
try {
navigator.sendBeacon(
new URL(this.beaconUrl, location.origin),
JSON.stringify(this.data())
);
} catch {
// noop
}
}
} | /**
* Sends a beacon with session data to the specified beacon URL.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/analytics.ts#L277-L288 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | Session.start | start() {
this.startTime = Date.now();
} | /**
* Marks the session as started by recording the start time.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/analytics.ts#L293-L295 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | Session.trackError | trackError(err: string | null) {
this.error = err === null ? null : String(err);
} | /**
* Tracks an error associated with the session.
*
* @param {string | null} err - The error message, or `null` if no error exists.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/analytics.ts#L302-L304 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | Session.trackFieldChange | trackFieldChange(name: string) {
this.#fieldChanges[name] = (this.#fieldChanges[name] || 0) + 1;
} | /**
* Tracks a change to a specific form field.
*
* @param {string} name - The name of the form field.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/analytics.ts#L311-L313 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | PluginObfuscation.constructor | constructor(context: PluginContext) {
super(context);
const el = context.el;
// Select the button that will trigger the obfuscation clarification
this.elButton =
el.parentElement?.querySelector('[data-clarify-button]') ||
(el.parentElement?.querySelector('button, a') as HTMLElement | null);
if (this.elButton) {
this.elButton.addEventListener('click', this.#_onButtonClick);
}
} | /**
* Creates an instance of PluginObfuscation.
*
* @param {PluginContext} context - The context object containing plugin configurations.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/obfuscation.ts#L22-L34 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | PluginObfuscation.destroy | destroy() {
if (this.elButton) {
this.elButton.removeEventListener('click', this.#_onButtonClick);
}
} | /**
* Destroys the plugin instance, removing event listeners.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/obfuscation.ts#L39-L43 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | PluginObfuscation.clarify | async clarify() {
const {
el,
getConfiguration,
getFloatingAnchor,
setFloatingAnchor,
reset,
solve,
setState,
} = this.context;
const { delay, floating, maxnumber, obfuscated } = getConfiguration();
// Set the floating anchor to the button if not already set
if (this.elButton && !getFloatingAnchor()) {
setFloatingAnchor(this.elButton);
}
// Handle the case where there is no obfuscated data
if (!obfuscated) {
setState(State.ERROR);
return;
}
// Reset state to VERIFYING and wait for the specified delay
reset(State.VERIFYING);
await new Promise((resolve) => setTimeout(resolve, delay || 0));
// Parse the obfuscated data and key from the configuration
const [data, params] = obfuscated.split('?');
const parsedParams = new URLSearchParams(params || '');
let key = parsedParams.get('key') || undefined;
// Prompt the user for a key if needed
if (key) {
const match = key.match(/^\(prompt:?(.*)\)$/);
if (match) {
key = prompt(match[1] || 'Enter Key:') || undefined;
}
}
// Run the decryption process and handle the result
const { solution } = await solve({
obfuscated: data,
key,
maxnumber,
});
if (solution && 'clearText' in solution) {
this.#renderClearText(solution.clearText);
setState(State.VERIFIED);
this.context.dispatch('cleartext', solution.clearText);
// Hide the original obfuscated element if floating is enabled
if (floating && el) {
el.style.display = 'none';
}
} else {
setState(State.ERROR, 'Unable to decrypt data.');
}
} | /**
* Handles the clarification process by decrypting the obfuscated data and rendering the clear text.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/obfuscation.ts#L48-L107 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | PluginUpload.constructor | constructor(context: PluginContext) {
super(context);
this.elForm = this.context.el.closest('form');
if (this.elForm) {
this.elForm.addEventListener('change', this.#_onFormChange);
this.elForm.addEventListener('submit', this.#_onFormSubmit, {
capture: true,
});
}
} | /**
* Constructor initializes the plugin, setting up event listeners on the form.
*
* @param {PluginContext} context - Plugin context providing access to the element, configuration, and utility methods.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/upload.ts#L37-L46 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | PluginUpload.addFile | addFile(fieldName: string, file: File) {
if (
!this.pendingFiles.find(([name, f]) => name === fieldName && f === file)
) {
this.pendingFiles.push([fieldName, file]);
}
} | /**
* Adds a file to the pending files list for upload.
*
* @param {string} fieldName - The field name associated with the file input.
* @param {File} file - The file to be uploaded.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/upload.ts#L54-L60 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | PluginUpload.destroy | destroy() {
if (this.elForm) {
this.elForm.removeEventListener('change', this.#_onFormChange);
this.elForm.removeEventListener('submit', this.#_onFormSubmit);
}
} | /**
* Cleans up event listeners and other resources when the plugin is destroyed.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/upload.ts#L65-L70 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | PluginUpload.uploadPendingFiles | async uploadPendingFiles() {
const next = async () => {
const entry = this.pendingFiles[0];
if (entry) {
await this.#uploadFile(this.#createUploadHandle(entry));
}
if (this.pendingFiles.length) {
return next();
}
};
await next();
if (this.pendingFiles.length === 0) {
this.#addFormFields();
this.elForm?.requestSubmit();
}
} | /**
* Uploads all pending files in the list.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/upload.ts#L75-L90 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | UploadHandle.constructor | constructor(
readonly fieldName: string,
readonly file: File
) {
this.uploadSize = this.file.size;
this.promise = new Promise((resolve, reject) => {
this.resolve = resolve;
this.reject = reject;
});
} | /**
* Creates an instance of UploadHandle.
*
* @param {string} fieldName - The name of the field associated with the file upload.
* @param {File} file - The file to be uploaded.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/upload.ts#L425-L434 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | UploadHandle.abort | abort() {
this.controller.abort();
} | /**
* Aborts the file upload by invoking the AbortController's abort method.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/upload.ts#L439-L441 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
altcha | github_2023 | altcha-org | typescript | UploadHandle.setProgress | setProgress(loaded: number) {
this.loaded = loaded;
this.progress =
this.file.size && loaded ? Math.min(1, loaded / this.file.size) : 0;
} | /**
* Updates the progress of the file upload.
*
* @param {number} loaded - The number of bytes that have been uploaded.
*/ | https://github.com/altcha-org/altcha/blob/2daa1e327576075f7eb43d648b61df97669dc4e8/src/plugins/upload.ts#L448-L452 | 2daa1e327576075f7eb43d648b61df97669dc4e8 |
Gomoon | github_2023 | wizardAEI | typescript | removeChineseSpaces | function removeChineseSpaces(str) {
return str
.replace(/([\u4e00-\u9fa5])\s+/g, '$1')
.replace(/\s+([\u4e00-\u9fa5])/g, '$1')
} | // 去掉中文的空格 | https://github.com/wizardAEI/Gomoon/blob/5c8904e9f072d27f906819dbe2d11770a0564014/src/renderer/src/components/MainInput/Tools.tsx#L265-L269 | 5c8904e9f072d27f906819dbe2d11770a0564014 |
Gomoon | github_2023 | wizardAEI | typescript | watchSelection | const watchSelection = (e: MouseEvent) => {
if (e.target === textAreaDiv) {
setHaveSelected(window.getSelection()?.toString() !== '')
}
} | // 监测是否划选 | https://github.com/wizardAEI/Gomoon/blob/5c8904e9f072d27f906819dbe2d11770a0564014/src/renderer/src/components/MainInput/index.tsx#L303-L307 | 5c8904e9f072d27f906819dbe2d11770a0564014 |
Gomoon | github_2023 | wizardAEI | typescript | showContextContainer | const showContextContainer = (e) => {
setShowContext(true)
// 将contextContainer定位到鼠标位置, 如果超出屏幕,则调整到合适位置
contextContainer!.style.left =
e.clientX + contextContainer!.offsetWidth > window.innerWidth
? `${e.clientX - contextContainer!.offsetWidth}px`
: `${e.clientX}px`
contextContainer!.style.top =
e.clientY + contextContainer!.offsetHeight > window.innerHeight
? `${e.clientY - contextContainer!.offsetHeight}px`
: `${e.clientY}px`
window.addEventListener('click', contextListener)
} | // 显示和隐藏右键菜单 | https://github.com/wizardAEI/Gomoon/blob/5c8904e9f072d27f906819dbe2d11770a0564014/src/renderer/src/components/MainInput/index.tsx#L310-L322 | 5c8904e9f072d27f906819dbe2d11770a0564014 |
Gomoon | github_2023 | wizardAEI | typescript | addActive | const addActive = () => {
textAreaContainerDiv!.attributes.setNamedItem(document.createAttribute('data-active'))
} | // 让input聚焦,box边框变为激活色 | https://github.com/wizardAEI/Gomoon/blob/5c8904e9f072d27f906819dbe2d11770a0564014/src/renderer/src/components/MainInput/index.tsx#L325-L327 | 5c8904e9f072d27f906819dbe2d11770a0564014 |
Gomoon | github_2023 | wizardAEI | typescript | showButton | const showButton = (e: MouseEvent) => {
const selection = window.getSelection()
!showSearch() && setFindContent('')
if (selection) {
if (selection.toString().length > 0) {
setShowSelectBtn(true)
btn!.style.top = `${e.clientY - 20}px`
btn!.style.left = `${e.clientX + 10}px`
if (btn!.offsetLeft + btn!.clientWidth > window.innerWidth) {
btn!.style.left = `${e.clientX - btn!.clientWidth - 10}px`
btn!.style.top = `${e.clientY - 20}px`
}
selectContent = selection.toString()
} else {
setShowSelectBtn(false)
}
}
} | // FEAT: 用户滑动选择文本 | https://github.com/wizardAEI/Gomoon/blob/5c8904e9f072d27f906819dbe2d11770a0564014/src/renderer/src/components/Message/Md.tsx#L122-L139 | 5c8904e9f072d27f906819dbe2d11770a0564014 |
Gomoon | github_2023 | wizardAEI | typescript | highlightText | function highlightText(node: any) {
if (!findContent()) return
$(node)
.contents()
.each(function (_, elem) {
if (elem.type === 'text') {
// 如果是文本节点,则替换文本
const text = $(elem).text()
// 检查是否有匹配
const regExp = new RegExp(escapeRegExp(findContent()), 'gi')
if (!regExp.test(text)) return
const newText = text.replace(
regExp,
(match) => `<span class="bg-active rounded-sm">${escape(match)}</span>`
)
$(elem).replaceWith(newText)
} else if (
elem.type === 'tag' &&
!['script', 'style', 'svg'].includes(elem.tagName.toLowerCase())
) {
highlightText(elem)
}
})
} | // FEAT: 对findContent高亮 | https://github.com/wizardAEI/Gomoon/blob/5c8904e9f072d27f906819dbe2d11770a0564014/src/renderer/src/components/Message/Md.tsx#L215-L238 | 5c8904e9f072d27f906819dbe2d11770a0564014 |
Gomoon | github_2023 | wizardAEI | typescript | callLLMFromNode | const callLLMFromNode = (
msgs: {
role: Roles
content: MessageContent
}[],
option: {
newTokenCallback: (content: string) => void
endCallback?: (result: LLMResult) => void
errorCallback?: (err: unknown) => void
pauseSignal: AbortSignal
}
) =>
new Promise((resolve, reject) => {
const remove = window.api.receiveMsg(async (_, msg: string) => {
if (msg.startsWith('new content: ')) {
const newContent = msg.replace(/^new content: /, '')
option.newTokenCallback(newContent)
}
})
window.api
.callLLM({
type: 'chat',
llm: 'Llama',
msgs: msgs.map((msg) => ({
role: msg.role,
content: msg.content as string
}))
})
.then((res) => {
option.endCallback?.({
generations: []
})
resolve(res)
})
.catch(reject)
.finally(remove)
}) | // TODO: 读取 assistant 信息来生成,可以从本地读取,也可以从远程读取 | https://github.com/wizardAEI/Gomoon/blob/5c8904e9f072d27f906819dbe2d11770a0564014/src/renderer/src/lib/ai/langchain/index.ts#L97-L133 | 5c8904e9f072d27f906819dbe2d11770a0564014 |
LafTools | github_2023 | work7z | typescript | shuffleArrayMutate | function shuffleArrayMutate<T>(array: T[]): T[] {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
} | // Durstenfeld shuffle | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/addons/it-tools/src/utils/random.ts#L8-L15 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | sleep | let sleep = (ms: number) =>
new Promise((resolve) => setTimeout(resolve, ms)); | // randomly sleep in 1 seconds | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/legacy/node/src/ext/job.ts#L46-L47 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | getLocale | function getLocale(request: NextRequest) {
let acceptLanguage = _.toLower(request.headers.get("accept-language") + "");
let val = defaultLocale.langInHttp;
let ack = false;
rever_locales_http.every((locale) => {
_.every(locale, (x) => {
if (acceptLanguage?.includes(x)) {
val = _.first(locale) || defaultLocale.langInHttp;
ack = true;
}
return !ack;
});
return !ack;
});
return val;
} | // Get the preferred locale, similar to the above or using a library | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/middleware.ts#L69-L84 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | fn | let fn = (obj: Partial<Metadata>) => {
return _.merge({
icons: [
'/icon.png'
],
title: Dot("title-laftools", "LafTools - The Leading All-In-One ToolBox for Programmers"),
description: Dot("iZXig7E2JF", "LafTools offers a comprehensive suite of development utilities including codecs, formatters, image processing tools, and computer resource management solutions. Designed to streamline and enhance your development workflow, LafTools is your go-to resource for efficient, high-quality software development."),
keywords: getAppKeywords(),
} satisfies Metadata, obj)
}; | // fn | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/page.tsx#L91-L100 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | EntryWrapper | const EntryWrapper = () => <div>deprecated</div>
let cachedLangMap: { [key: string]: string } = {} | // const EntryWrapper = dynamic(() => import('./client'), { ssr: false, loading: () => <PageLoadingEffect /> }) | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/page.tsx#L25-L27 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | formatEachNodeItem | let formatEachNodeItem = (nodeList: TreeNodeInfo[]): TreeNodeInfo[] => {
return _.map(nodeList, (x) => {
let rootLevel = (x.id + "").indexOf(TREE_ROOT_ID_PREFIX) == 0;
let hasCaret = !_.isNil(x.hasCaret)
? x.hasCaret
: !_.isEmpty(x.childNodes);
let isExpanded = hasSearchText
? true
: _.includes(props.expanded, x.id.toString());
let i = {
icon: "application",
...x,
label:
props.needShowCountChildren && hasCaret && !rootLevel
? x.label + `(${_.size(x.childNodes)})`
: x.label,
isExpanded: isExpanded,
isSelected: _.includes(props.selected, x.id.toString()),
childNodes: !isExpanded
? []
: rootLevel
? x.childNodes
: formatEachNodeItem(x.childNodes || []),
// secondaryLabel: <Button minimal={true} icon="star-empty" />,
hasCaret,
} as TreeNodeInfo;
if (props.formatEachNode) {
i = props.formatEachNode(i);
}
return i;
});
}; | // recursively format tmp_nodes to nodes, so that we can use it in Tree, note that isExpanded is true when it's in props.expanded and isSeleced is true when it's in props.selected | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/components/SystemNavTree/index.tsx#L113-L144 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | AND.constructor | constructor() {
super();
this.name = Dot("and.name", "AND");
this.module = "Default";
this.description = Dot("and.desc", "AND the input with the given key. e.g. fe023da5");
this.infoURL = "https://wikipedia.org/wiki/Bitwise_operation#AND";
this.inputType = "byteArray";
this.outputType = "byteArray";
this.args = [
{
name: Dot("and.arg.key", "Key"),
type: "toggleString",
value: "",
toggleValues: BITWISE_OP_DELIMS,
},
];
} | /**
* AND constructor
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/AND.tsx#L19-L36 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | AND.getOptDetail | public getOptDetail(): OptDetail {
return {
relatedID: 'nothing',
config: {
"module": "Default",
"description": this.description,
"infoURL": this.infoURL,
"inputType": this.inputType,
"outputType": this.outputType,
"flowControl": false,
"manualBake": false,
"args": this.args,
},
infoURL: this.infoURL,
nousenouseID: 'and',
optName: Dot("and.textiDjMIo", "Generate {0} Hash", "AND"),
optDescription: Dot(
"and.desc.rxsHq",
"This operation performs a bitwise {0} on data.",
"AND"
),
// exampleInput and exampleOutput are placeholders, actual values should be provided
exampleInput: "",
exampleOutput: ""
};
} | /**
* Get operation details
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/AND.tsx#L41-L66 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | AND.run | run(input: Uint8Array, args: any[]): Uint8Array {
const key = Utils.convertToByteArray(args[0].string || "", args[0].option);
return bitOp(input, key, and);
} | /**
* @param {Uint8Array} input
* @param {Object[]} args
* @returns {Uint8Array}
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/AND.tsx#L73-L77 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | AND.highlight | highlight(pos: { start: number; end: number }[], args: any[]): { start: number; end: number }[] {
return pos;
} | /**
* Highlight AND
*
* @param {Object[]} pos
* @param {number} pos[].start
* @param {number} pos[].end
* @param {Object[]} args
* @returns {Object[]} pos
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/AND.tsx#L88-L90 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | AND.highlightReverse | highlightReverse(pos: { start: number; end: number }[], args: any[]): { start: number; end: number }[] {
return pos;
} | /**
* Highlight AND in reverse
*
* @param {Object[]} pos
* @param {number} pos[].start
* @param {number} pos[].end
* @param {Object[]} args
* @returns {Object[]} pos
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/AND.tsx#L101-L103 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | CSSBeautify.constructor | constructor() {
super();
this.module = "Code";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
"name": Dot("isti", "Indent string"),
"type": "binaryShortString",
"value": "\\t"
}
];
} | /**
* CSSBeautify constructor
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/CSSBeautify.tsx#L61-L75 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | CSSBeautify.run | run(input, args) {
let indentStr = gutils.convertASCIICodeInStr(args[0]);
return vkbeautify.css(input, indentStr);
} | /**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/CSSBeautify.tsx#L82-L85 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | CSSMinify.constructor | constructor() {
super();
this.module = "Code";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
name: "Preserve comments",
type: "boolean",
value: false,
},
];
} | /**
* CSSMinify constructor
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/CSSMinify.tsx#L59-L74 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | CSSMinify.run | run(input, args) {
const preserveComments = args[0];
return vkbeautify.cssmin(input, preserveComments);
} | /**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/CSSMinify.tsx#L81-L84 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | CSVToJSON.constructor | constructor() {
super();
this.outputType = "JSON";
this.inputType = "string";
this.args = [
{
name: "Cell delimiters",
type: "binaryShortString",
value: ",",
},
{
name: "Row delimiters",
type: "binaryShortString",
value: "\\r\\n",
},
{
name: "Format",
type: "option",
value: ["Array of dictionaries", "Array of arrays"],
},
];
} | /**
* CSVToJSON constructor
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/CSVToJSON.tsx#L74-L96 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | CSVToJSON.run | run(input, args) {
const [cellDelims, rowDelims, format] = args;
let json, header;
try {
json = Utils.parseCSV(input, cellDelims.split(""), rowDelims.split(""));
} catch (err) {
throw new OperationError("Unable to parse CSV: " + err);
}
switch (format) {
case "Array of dictionaries":
header = json[0];
return json.slice(1).map((row) => {
const obj = {};
header.forEach((h, i) => {
obj[h] = row[i];
});
return obj;
});
case "Array of arrays":
default:
return json;
}
} | /**
* @param {string} input
* @param {Object[]} args
* @returns {JSON}
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/CSVToJSON.tsx#L103-L127 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromBCD.constructor | constructor() {
super();
this.module = "Default"
this.inputType = "string";
this.outputType = "BigNumber";
this.args = [
{
name: "Scheme",
type: "option",
value: ENCODING_SCHEME,
},
{
name: "Packed",
type: "boolean",
value: true,
},
{
name: "Signed",
type: "boolean",
value: false,
},
{
name: "Input format",
type: "option",
value: FORMAT,
},
];
this.checks = [
{
pattern: "^(?:\\d{4} ){3,}\\d{4}$",
flags: "",
args: ["8 4 2 1", true, false, "Nibbles"],
},
];
} | /**
* FromBCD constructor
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromBCD.tsx#L98-L132 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromBCD.run | run(input, args) {
const encoding = ENCODING_LOOKUP[args[0]],
packed = args[1],
signed = args[2],
inputFormat = args[3],
nibbles: any = [];
let output = "",
byteArray;
// Normalise the input
switch (inputFormat) {
case "Nibbles":
case "Bytes":
input = input.replace(/\s/g, "");
for (let i = 0; i < input.length; i += 4) {
nibbles.push(parseInt(input.substr(i, 4), 2));
}
break;
case "Raw":
default:
byteArray = new Uint8Array(Utils.strToArrayBuffer(input));
byteArray.forEach((b) => {
nibbles.push(b >>> 4);
nibbles.push(b & 15);
});
break;
}
if (!packed) {
// Discard each high nibble
for (let i = 0; i < nibbles.length; i++) {
nibbles.splice(i, 1); // lgtm [js/loop-iteration-skipped-due-to-shifting]
}
}
if (signed) {
const sign = nibbles.pop();
if (sign === 13 || sign === 11) {
// Negative
output += "-";
}
}
nibbles.forEach((n) => {
if (isNaN(n)) throw new OperationError("Invalid input");
const val = encoding.indexOf(n);
if (val < 0)
throw new OperationError(
`Value ${Utils.bin(n, 4)} is not in the encoding scheme`,
);
output += val.toString();
});
return new BigNumber(output);
} | /**
* @param {string} input
* @param {Object[]} args
* @returns {BigNumber}
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromBCD.tsx#L139-L194 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromBase32.constructor | constructor() {
super();
this.name = "From Base32";
this.module = "Default";
this.inputType = "string";
this.outputType = "byteArray";
this.args = [
{
name: Dot("skq3i12", "Alphabet"),
type: "binaryString",
value: "A-Z2-7="
},
{
name: Dot("nskqw", "Remove non-alphabet chars"),
type: "boolean",
value: true
}
];
this.checks = [
{
pattern: "^(?:[A-Z2-7]{8})+(?:[A-Z2-7]{2}={6}|[A-Z2-7]{4}={4}|[A-Z2-7]{5}={3}|[A-Z2-7]{7}={1})?$",
flags: "",
args: ["A-Z2-7=", false]
}
];
} | /**
* FromBase32 constructor
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromBase32.tsx#L78-L106 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromBase32.run | run(input, args) {
if (!input) return [];
const alphabet = args[0] ?
Utils.expandAlphRange(args[0]).join("") : "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
removeNonAlphChars = args[1],
output: any[] = [];
let chr1, chr2, chr3, chr4, chr5,
enc1, enc2, enc3, enc4, enc5, enc6, enc7, enc8,
i = 0;
if (removeNonAlphChars) {
const re = new RegExp("[^" + alphabet.replace(/[\]\\\-^]/g, "\\$&") + "]", "g");
input = input.replace(re, "");
}
while (i < input.length) {
enc1 = alphabet.indexOf(input.charAt(i++));
enc2 = alphabet.indexOf(input.charAt(i++) || "=");
enc3 = alphabet.indexOf(input.charAt(i++) || "=");
enc4 = alphabet.indexOf(input.charAt(i++) || "=");
enc5 = alphabet.indexOf(input.charAt(i++) || "=");
enc6 = alphabet.indexOf(input.charAt(i++) || "=");
enc7 = alphabet.indexOf(input.charAt(i++) || "=");
enc8 = alphabet.indexOf(input.charAt(i++) || "=");
chr1 = (enc1 << 3) | (enc2 >> 2);
chr2 = ((enc2 & 3) << 6) | (enc3 << 1) | (enc4 >> 4);
chr3 = ((enc4 & 15) << 4) | (enc5 >> 1);
chr4 = ((enc5 & 1) << 7) | (enc6 << 2) | (enc7 >> 3);
chr5 = ((enc7 & 7) << 5) | enc8;
output.push(chr1);
if ((enc2 & 3) !== 0 || enc3 !== 32) output.push(chr2);
if ((enc4 & 15) !== 0 || enc5 !== 32) output.push(chr3);
if ((enc5 & 1) !== 0 || enc6 !== 32) output.push(chr4);
if ((enc7 & 7) !== 0 || enc8 !== 32) output.push(chr5);
}
return output;
} | /**
* @param {string} input
* @param {Object[]} args
* @returns {byteArray}
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromBase32.tsx#L113-L154 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromBase45.constructor | constructor() {
super();
this.name = "From Base45";
this.module = "Default";
this.inputType = "string";
this.outputType = "byteArray";
this.args = [
{
name: Dot("skq3i12", "Alphabet"),
type: "string",
value: ALPHABET
},
{
name: Dot("nskqw", "Remove non-alphabet chars"),
type: "boolean",
value: true
},
];
this.highlight = highlightFromBase45;
this.highlightReverse = highlightToBase45;
} | /**
* FromBase45 constructor
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromBase45.tsx#L71-L97 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromBase45.run | run(input, args) {
if (!input) return [];
const alphabet = Utils.expandAlphRange(args[0]).join("");
const removeNonAlphChars = args[1];
const res: any = [];
// Remove non-alphabet characters
if (removeNonAlphChars) {
const re = new RegExp("[^" + alphabet.replace(/[[\]\\\-^$]/g, "\\$&") + "]", "g");
input = input.replace(re, "");
}
for (const triple of Utils.chunked(input, 3)) {
triple.reverse();
let b = 0;
for (const c of triple) {
const idx = alphabet.indexOf(c);
if (idx === -1) {
throw new OperationError(`Character not in alphabet: '${c}'`);
}
b *= 45;
b += idx;
}
if (b > 65535) {
throw new OperationError(`Triplet too large: '${triple.join("")}'`);
}
if (triple.length > 2) {
/**
* The last triple may only have 2 bytes so we push the MSB when we got 3 bytes
* Pushing MSB
*/
res.push(b >> 8);
}
/**
* Pushing LSB
*/
res.push(b & 0xff);
}
return res;
} | /**
* @param {string} input
* @param {Object[]} args
* @returns {byteArray}
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromBase45.tsx#L104-L149 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromBase58.constructor | constructor() {
super();
this.module = "Default";
// this.description = ;
// this.infoURL = "";
this.inputType = "string";
this.outputType = "byteArray";
this.args = [
{
"name": Dot("anosdk", "Alphabet"),
"type": "editableOption",
"value": ALPHABET_OPTIONS
},
{
"name": Dot("nskqw", "Remove non-alphabet chars"),
"type": "boolean",
"value": true
}
];
this.checks = [
{
pattern: "^[1-9A-HJ-NP-Za-km-z]{20,}$",
flags: "",
args: ["123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz", false]
},
{
pattern: "^[1-9A-HJ-NP-Za-km-z]{20,}$",
flags: "",
args: ["rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz", false]
},
];
} | /**
* FromBase58 constructor
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromBase58.tsx#L96-L133 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromBase58.run | run(input, args) {
let alphabet = args[0] || ALPHABET_OPTIONS[0].value;
const removeNonAlphaChars = args[1] === undefined ? true : args[1],
result = [0];
alphabet = Utils.expandAlphRange(alphabet).join("");
if (alphabet.length !== 58 ||
([] as any).unique.call(alphabet).length !== 58) {
throw new OperationError("Alphabet must be of length 58");
}
if (input.length === 0) return [];
let zeroPrefix = 0;
for (let i = 0; i < input.length && input[i] === alphabet[0]; i++) {
zeroPrefix++;
}
[].forEach.call(input, function (c, charIndex) {
const index = alphabet.indexOf(c);
if (index === -1) {
if (removeNonAlphaChars) {
return;
} else {
throw new OperationError(`Char '${c}' at position ${charIndex} not in alphabet`);
}
}
let carry = result[0] * 58 + index;
result[0] = carry & 0xFF;
carry = carry >> 8;
for (let i = 1; i < result.length; i++) {
carry += result[i] * 58;
result[i] = carry & 0xFF;
carry = carry >> 8;
}
while (carry > 0) {
result.push(carry & 0xFF);
carry = carry >> 8;
}
});
while (zeroPrefix--) {
result.push(0);
}
return result.reverse();
} | /**
* @param {string} input
* @param {Object[]} args
* @returns {byteArray}
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromBase58.tsx#L140-L191 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromBase62.constructor | constructor() {
super();
this.name = "From Base62";
this.module = "Default";
// this.description = "";
// this.infoURL = "https://wikipedia.org/wiki/List_of_numeral_systems";
this.inputType = "string";
this.outputType = "byteArray";
this.args = [
{
name: Dot("skq3i12", "Alphabet"),
type: "string",
value: "0-9A-Za-z"
}
];
} | /**
* FromBase62 constructor
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromBase62.tsx#L68-L88 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromBase62.run | run(input, args) {
if (input.length < 1) return [];
const alphabet = Utils.expandAlphRange(args[0]).join("");
const BN62 = BigNumber.clone({ ALPHABET: alphabet });
const re = new RegExp("[^" + alphabet.replace(/[[\]\\\-^$]/g, "\\$&") + "]", "g");
input = input.replace(re, "");
// Read number in using Base62 alphabet
const number = new BN62(input, 62);
// Copy to new BigNumber object that uses the default alphabet
const normalized = new BigNumber(number);
// Convert to hex and add leading 0 if required
let hex = normalized.toString(16);
if (hex.length % 2 !== 0) hex = "0" + hex;
return Utils.convertToByteArray(hex, "Hex");
} | /**
* @param {string} input
* @param {Object[]} args
* @returns {byteArray}
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromBase62.tsx#L95-L113 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromBase64.constructor | constructor() {
super();
this.module = "Default";
this.inputType = "string";
this.outputType = "byteArray";
this.args = [
{
name: Dot("skq3i12", "Alphabet"),
type: "editableOption",
value: ALPHABET_OPTIONS,
},
{
name: Dot("nskqw", "Remove non-alphabet chars"),
type: "boolean",
value: true,
},
{
name: "Strict mode",
type: "boolean",
value: false,
},
];
this.checks = [
{
pattern:
"^\\s*(?:[A-Z\\d+/]{4})+(?:[A-Z\\d+/]{2}==|[A-Z\\d+/]{3}=)?\\s*$",
flags: "i",
args: ["A-Za-z0-9+/=", true, false],
},
{
pattern: "^\\s*[A-Z\\d\\-_]{20,}\\s*$",
flags: "i",
args: ["A-Za-z0-9-_", true, false],
},
{
pattern:
"^\\s*(?:[A-Z\\d+\\-]{4}){5,}(?:[A-Z\\d+\\-]{2}==|[A-Z\\d+\\-]{3}=)?\\s*$",
flags: "i",
args: ["A-Za-z0-9+\\-=", true, false],
},
{
pattern:
"^\\s*(?:[A-Z\\d./]{4}){5,}(?:[A-Z\\d./]{2}==|[A-Z\\d./]{3}=)?\\s*$",
flags: "i",
args: ["./0-9A-Za-z=", true, false],
},
{
pattern: "^\\s*[A-Z\\d_.]{20,}\\s*$",
flags: "i",
args: ["A-Za-z0-9_.", true, false],
},
{
pattern:
"^\\s*(?:[A-Z\\d._]{4}){5,}(?:[A-Z\\d._]{2}--|[A-Z\\d._]{3}-)?\\s*$",
flags: "i",
args: ["A-Za-z0-9._-", true, false],
},
{
pattern:
"^\\s*(?:[A-Z\\d+/]{4}){5,}(?:[A-Z\\d+/]{2}==|[A-Z\\d+/]{3}=)?\\s*$",
flags: "i",
args: ["0-9a-zA-Z+/=", true, false],
},
{
pattern:
"^\\s*(?:[A-Z\\d+/]{4}){5,}(?:[A-Z\\d+/]{2}==|[A-Z\\d+/]{3}=)?\\s*$",
flags: "i",
args: ["0-9A-Za-z+/=", true, false],
},
{
pattern: "^[ !\"#$%&'()*+,\\-./\\d:;<=>?@A-Z[\\\\\\]^_]{20,}$",
flags: "",
args: [" -_", false, false],
},
{
pattern: "^\\s*[A-Z\\d+\\-]{20,}\\s*$",
flags: "i",
args: ["+\\-0-9A-Za-z", true, false],
},
{
pattern: "^\\s*[!\"#$%&'()*+,\\-0-689@A-NP-VX-Z[`a-fh-mp-r]{20,}\\s*$",
flags: "",
args: ["!-,-0-689@A-NP-VX-Z[`a-fh-mp-r", true, false],
},
{
pattern:
"^\\s*(?:[N-ZA-M\\d+/]{4}){5,}(?:[N-ZA-M\\d+/]{2}==|[N-ZA-M\\d+/]{3}=)?\\s*$",
flags: "i",
args: ["N-ZA-Mn-za-m0-9+/=", true, false],
},
{
pattern: "^\\s*[A-Z\\d./]{20,}\\s*$",
flags: "i",
args: ["./0-9A-Za-z", true, false],
},
{
pattern:
"^\\s*(?:[A-Z=\\d\\+/]{4}){5,}(?:[A-Z=\\d\\+/]{2}CC|[A-Z=\\d\\+/]{3}C)?\\s*$",
flags: "i",
args: [
"/128GhIoPQROSTeUbADfgHijKLM+n0pFWXY456xyzB7=39VaqrstJklmNuZvwcdEC",
true,
false,
],
},
{
pattern:
"^\\s*(?:[A-Z=\\d\\+/]{4}){5,}(?:[A-Z=\\d\\+/]{2}55|[A-Z=\\d\\+/]{3}5)?\\s*$",
flags: "i",
args: [
"3GHIJKLMNOPQRSTUb=cdefghijklmnopWXYZ/12+406789VaqrstuvwxyzABCDEF5",
true,
false,
],
},
{
pattern:
"^\\s*(?:[A-Z=\\d\\+/]{4}){5,}(?:[A-Z=\\d\\+/]{2}22|[A-Z=\\d\\+/]{3}2)?\\s*$",
flags: "i",
args: [
"ZKj9n+yf0wDVX1s/5YbdxSo=ILaUpPBCHg8uvNO4klm6iJGhQ7eFrWczAMEq3RTt2",
true,
false,
],
},
{
pattern:
"^\\s*(?:[A-Z=\\d\\+/]{4}){5,}(?:[A-Z=\\d\\+/]{2}55|[A-Z=\\d\\+/]{3}5)?\\s*$",
flags: "i",
args: [
"HNO4klm6ij9n+J2hyf0gzA8uvwDEq3X1Q7ZKeFrWcVTts/MRGYbdxSo=ILaUpPBC5",
true,
false,
],
},
];
} | /**
* FromBase64 constructor
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromBase64.tsx#L291-L431 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromBase64.run | run(input, args) {
const [alphabet, removeNonAlphChars, strictMode] = args;
return fromBase64(
input,
alphabet,
"byteArray",
removeNonAlphChars,
strictMode,
);
} | /**
* @param {string} input
* @param {Object[]} args
* @returns {byteArray}
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromBase64.tsx#L438-L448 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromBase64.highlight | highlight(pos, args) {
pos[0].start = Math.ceil((pos[0].start / 4) * 3);
pos[0].end = Math.floor((pos[0].end / 4) * 3);
return pos;
} | /**
* Highlight to Base64
*
* @param {Object[]} pos
* @param {number} pos[].start
* @param {number} pos[].end
* @param {Object[]} args
* @returns {Object[]} pos
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromBase64.tsx#L459-L463 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromBase64.highlightReverse | highlightReverse(pos, args) {
pos[0].start = Math.floor((pos[0].start / 3) * 4);
pos[0].end = Math.ceil((pos[0].end / 3) * 4);
return pos;
} | /**
* Highlight from Base64
*
* @param {Object[]} pos
* @param {number} pos[].start
* @param {number} pos[].end
* @param {Object[]} args
* @returns {Object[]} pos
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromBase64.tsx#L474-L478 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromBase85.constructor | constructor() {
super();
this.name = "From Base85";
this.module = "Default";
// this.description = ;
// this.infoURL = "";
this.inputType = "string";
this.outputType = "byteArray";
this.args = [
{
name: Dot("skq3i12", "Alphabet"),
type: "editableOption",
value: ALPHABET_OPTIONS
},
{
name: Dot("nskqw", "Remove non-alphabet chars"),
type: "boolean",
value: true
},
{
name: "All-zero group char",
type: "binaryShortString",
value: "z",
maxLength: 1
}
];
this.checks = [
{
pattern:
"^\\s*(?:<~)?" + // Optional whitespace and starting marker
"[\\s!-uz]*" + // Any amount of base85 characters and whitespace
"[!-uz]{15}" + // At least 15 continoues base85 characters without whitespace
"[\\s!-uz]*" + // Any amount of base85 characters and whitespace
"(?:~>)?\\s*$", // Optional ending marker and whitespace
args: ["!-u"],
},
{
pattern:
"^" +
"[\\s0-9a-zA-Z.\\-:+=^!/*?&<>()[\\]{}@%$#]*" +
"[0-9a-zA-Z.\\-:+=^!/*?&<>()[\\]{}@%$#]{15}" + // At least 15 continoues base85 characters without whitespace
"[\\s0-9a-zA-Z.\\-:+=^!/*?&<>()[\\]{}@%$#]*" +
"$",
args: ["0-9a-zA-Z.\\-:+=^!/*?&<>()[]{}@%$#"],
},
{
pattern:
"^" +
"[\\s0-9A-Za-z!#$%&()*+\\-;<=>?@^_`{|}~]*" +
"[0-9A-Za-z!#$%&()*+\\-;<=>?@^_`{|}~]{15}" + // At least 15 continoues base85 characters without whitespace
"[\\s0-9A-Za-z!#$%&()*+\\-;<=>?@^_`{|}~]*" +
"$",
args: ["0-9A-Za-z!#$%&()*+\\-;<=>?@^_`{|}~"],
},
];
} | /**
* From Base85 constructor
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromBase85.tsx#L112-L173 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromBase85.run | run(input, args) {
const alphabet = Utils.expandAlphRange(args[0]).join(""),
removeNonAlphChars = args[1],
allZeroGroupChar = typeof args[2] === "string" ? args[2].slice(0, 1) : "",
result: any = [];
if (alphabet.length !== 85 ||
([] as any).unique.call(alphabet).length !== 85) {
throw new OperationError("Alphabet must be of length 85");
}
if (allZeroGroupChar && alphabet.includes(allZeroGroupChar)) {
throw new OperationError("The all-zero group char cannot appear in the alphabet");
}
// Remove delimiters if present
const matches = input.match(/^<~(.+?)~>$/);
if (matches !== null) input = matches[1];
// Remove non-alphabet characters
if (removeNonAlphChars) {
const re = new RegExp("[^~" + allZeroGroupChar + alphabet.replace(/[[\]\\\-^$]/g, "\\$&") + "]", "g");
input = input.replace(re, "");
// Remove delimiters again if present (incase of non-alphabet characters in front/behind delimiters)
const matches = input.match(/^<~(.+?)~>$/);
if (matches !== null) input = matches[1];
}
if (input.length === 0) return [];
let i = 0;
let block, blockBytes;
while (i < input.length) {
if (input[i] === allZeroGroupChar) {
result.push(0, 0, 0, 0);
i++;
} else {
let digits = [];
digits = input
.substr(i, 5)
.split("")
.map((chr, idx) => {
const digit = alphabet.indexOf(chr);
if ((digit < 0 || digit > 84) && chr !== allZeroGroupChar) {
throw `Invalid character '${chr}' at index ${i + idx}`;
}
return digit;
});
block =
digits[0] * 52200625 +
digits[1] * 614125 +
(i + 2 < input.length ? digits[2] : 84) * 7225 +
(i + 3 < input.length ? digits[3] : 84) * 85 +
(i + 4 < input.length ? digits[4] : 84);
blockBytes = [
(block >> 24) & 0xff,
(block >> 16) & 0xff,
(block >> 8) & 0xff,
block & 0xff
];
if (input.length < i + 5) {
blockBytes.splice(input.length - (i + 5), 5);
}
result.push.apply(result, blockBytes);
i += 5;
}
}
return result;
} | /**
* @param {string} input
* @param {Object[]} args
* @returns {byteArray}
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromBase85.tsx#L180-L253 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromBinary.constructor | constructor() {
super();
this.name = "From Binary";
this.module = "Default";
this.inputType = "string";
this.outputType = "byteArray";
this.args = [
{
name: "Delimiter",
type: "option",
value: BIN_DELIM_OPTIONS,
},
{
name: "Byte Length",
type: "number",
value: 8,
min: 1,
},
];
this.checks = [
{
pattern: "^(?:[01]{8})+$",
flags: "",
args: ["None"],
},
{
pattern: "^(?:[01]{8})(?: [01]{8})*$",
flags: "",
args: ["Space"],
},
{
pattern: "^(?:[01]{8})(?:,[01]{8})*$",
flags: "",
args: ["Comma"],
},
{
pattern: "^(?:[01]{8})(?:;[01]{8})*$",
flags: "",
args: ["Semi-colon"],
},
{
pattern: "^(?:[01]{8})(?::[01]{8})*$",
flags: "",
args: ["Colon"],
},
{
pattern: "^(?:[01]{8})(?:\\n[01]{8})*$",
flags: "",
args: ["Line feed"],
},
{
pattern: "^(?:[01]{8})(?:\\r\\n[01]{8})*$",
flags: "",
args: ["CRLF"],
},
];
} | /**
* FromBinary constructor
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromBinary.tsx#L76-L133 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromBinary.run | run(input, args) {
const byteLen = args[1] ? args[1] : 8;
return fromBinary(input, args[0], byteLen);
} | /**
* @param {string} input
* @param {Object[]} args
* @returns {byteArray}
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromBinary.tsx#L140-L143 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromBinary.highlight | highlight(pos, args) {
const delim = Utils.charRep(args[0] || "Space");
pos[0].start =
pos[0].start === 0 ? 0 : Math.floor(pos[0].start / (8 + delim.length));
pos[0].end =
pos[0].end === 0 ? 0 : Math.ceil(pos[0].end / (8 + delim.length));
return pos;
} | /**
* Highlight From Binary
*
* @param {Object[]} pos
* @param {number} pos[].start
* @param {number} pos[].end
* @param {Object[]} args
* @returns {Object[]} pos
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromBinary.tsx#L154-L161 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromBinary.highlightReverse | highlightReverse(pos, args) {
const delim = Utils.charRep(args[0] || "Space");
pos[0].start = pos[0].start * (8 + delim.length);
pos[0].end = pos[0].end * (8 + delim.length) - delim.length;
return pos;
} | /**
* Highlight From Binary in reverse
*
* @param {Object[]} pos
* @param {number} pos[].start
* @param {number} pos[].end
* @param {Object[]} args
* @returns {Object[]} pos
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromBinary.tsx#L172-L177 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromCharcode.constructor | constructor() {
super();
this.name = "From Charcode";
this.module = "Default";
this.inputType = "string";
this.outputType = "ArrayBuffer";
this.args = [
{
name: "Delimiter",
type: "option",
value: DELIM_OPTIONS,
},
{
name: "Base",
type: "number",
value: 16,
},
];
} | /**
* FromCharcode constructor
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromCharcode.tsx#L64-L83 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromCharcode.run | run(input, args) {
const delim = Utils.charRep(args[0] || "Space"),
base = args[1];
let bites = input.split(delim),
i = 0;
if (base < 2 || base > 36) {
throw new OperationError("Error: Base argument must be between 2 and 36");
}
if (input.length === 0) {
return new ArrayBuffer(0);
}
// if (base !== 16 && isWorkerEnvironment())
// self.setOption("attemptHighlight", false);
// Split into groups of 2 if the whole string is concatenated and
// too long to be a single character
if (bites.length === 1 && input.length > 17) {
bites = [];
for (i = 0; i < input.length; i += 2) {
bites.push(input.slice(i, i + 2));
}
}
let latin1 = "";
for (i = 0; i < bites.length; i++) {
latin1 += Utils.chr(parseInt(bites[i], base));
}
return Utils.strToArrayBuffer(latin1);
} | /**
* @param {string} input
* @param {Object[]} args
* @returns {ArrayBuffer}
*
* @throws {OperationError} if base out of range
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromCharcode.tsx#L92-L123 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromDecimal.constructor | constructor() {
super();
this.name = "From Decimal";
this.module = "Default";
// this.description =
// "Converts the data from an ordinal integer array back into its raw form.<br><br>e.g. <code>72 101 108 108 111</code> becomes <code>Hello</code>";
this.inputType = "string";
this.outputType = "byteArray";
this.args = [
{
name: "Delimiter",
type: "option",
value: DELIM_OPTIONS,
},
{
name: "Support signed values",
type: "boolean",
value: false,
},
];
this.checks = [
{
pattern:
"^(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5])(?: (?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5]))*$",
flags: "",
args: ["Space", false],
},
{
pattern:
"^(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5])(?:,(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5]))*$",
flags: "",
args: ["Comma", false],
},
{
pattern:
"^(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5])(?:;(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5]))*$",
flags: "",
args: ["Semi-colon", false],
},
{
pattern:
"^(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5])(?::(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5]))*$",
flags: "",
args: ["Colon", false],
},
{
pattern:
"^(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5])(?:\\n(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5]))*$",
flags: "",
args: ["Line feed", false],
},
{
pattern:
"^(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5])(?:\\r\\n(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5]))*$",
flags: "",
args: ["CRLF", false],
},
];
} | /**
* FromDecimal constructor
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromDecimal.tsx#L95-L154 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromDecimal.run | run(input, args) {
let data = fromDecimal(input, args[0]);
if (args[1]) {
// Convert negatives
data = data.map((v) => (v < 0 ? 0xff + v + 1 : v));
}
return data;
} | /**
* @param {string} input
* @param {Object[]} args
* @returns {byteArray}
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromDecimal.tsx#L161-L168 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromHTMLEntity.constructor | constructor() {
super();
this.name = "From HTML Entity";
this.module = "Encodings";
this.inputType = "string";
this.outputType = "string";
this.args = [];
this.checks = [
{
pattern: "&(?:#\\d{2,3}|#x[\\da-f]{2}|[a-z]{2,6});",
flags: "i",
args: [],
},
];
} | /**
* FromHTMLEntity constructor
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromHTMLEntity.tsx#L46-L61 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromHTMLEntity.run | run(input, args) {
const regex = /&(#?x?[a-zA-Z0-9]{1,20});/g;
let output = "",
m,
i = 0;
while ((m = regex.exec(input))) {
// Add up to match
for (; i < m.index;) output += input[i++];
// Add match
const bite = entityToByte[m[1]];
if (bite) {
output += Utils.chr(bite);
} else if (
!bite &&
m[1][0] === "#" &&
m[1].length > 1 &&
/^#\d{1,6}$/.test(m[1])
) {
// Numeric entity (e.g. )
const num = m[1].slice(1, m[1].length);
output += Utils.chr(parseInt(num, 10));
} else if (
!bite &&
m[1][0] === "#" &&
m[1].length > 3 &&
/^#x[\dA-F]{2,8}$/i.test(m[1])
) {
// Hex entity (e.g. :)
const hex = m[1].slice(2, m[1].length);
output += Utils.chr(parseInt(hex, 16));
} else {
// Not a valid entity, print as normal
for (; i < regex.lastIndex;) output += input[i++];
}
i = regex.lastIndex;
}
// Add all after final match
for (; i < input.length;) output += input[i++];
return output;
} | /**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromHTMLEntity.tsx#L68-L111 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromHex.constructor | constructor() {
super();
this.module = "Default";
this.inputType = "string"
this.outputType = "byteArray"
this.args = [
{
name: "Delimiter",
type: "option",
value: FROM_HEX_DELIM_OPTIONS,
},
];
this.checks = [
{
pattern: "^(?:[\\dA-F]{2})+$",
flags: "i",
args: ["None"],
},
{
pattern: "^[\\dA-F]{2}(?: [\\dA-F]{2})*$",
flags: "i",
args: ["Space"],
},
{
pattern: "^[\\dA-F]{2}(?:,[\\dA-F]{2})*$",
flags: "i",
args: ["Comma"],
},
{
pattern: "^[\\dA-F]{2}(?:;[\\dA-F]{2})*$",
flags: "i",
args: ["Semi-colon"],
},
{
pattern: "^[\\dA-F]{2}(?::[\\dA-F]{2})*$",
flags: "i",
args: ["Colon"],
},
{
pattern: "^[\\dA-F]{2}(?:\\n[\\dA-F]{2})*$",
flags: "i",
args: ["Line feed"],
},
{
pattern: "^[\\dA-F]{2}(?:\\r\\n[\\dA-F]{2})*$",
flags: "i",
args: ["CRLF"],
},
{
pattern: "^(?:0x[\\dA-F]{2})+$",
flags: "i",
args: ["0x"],
},
{
pattern: "^0x[\\dA-F]{2}(?:,0x[\\dA-F]{2})*$",
flags: "i",
args: ["0x with comma"],
},
{
pattern: "^(?:\\\\x[\\dA-F]{2})+$",
flags: "i",
args: ["\\x"],
},
];
} | /**
* FromHex constructor
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromHex.tsx#L142-L209 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromHex.run | run(input, args) {
const delim = args[0] || "Auto";
return fromHex(input, delim, 2);
} | /**
* @param {string} input
* @param {Object[]} args
* @returns {byteArray}
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromHex.tsx#L216-L219 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromHex.highlight | highlight(pos, args) {
if (args[0] === "Auto") return false;
const delim = Utils.charRep(args[0] || "Space"),
len = delim === "\r\n" ? 1 : delim.length,
width = len + 2;
// 0x and \x are added to the beginning if they are selected, so increment the positions accordingly
if (delim === "0x" || delim === "\\x") {
if (pos[0].start > 1) pos[0].start -= 2;
else pos[0].start = 0;
if (pos[0].end > 1) pos[0].end -= 2;
else pos[0].end = 0;
}
pos[0].start = pos[0].start === 0 ? 0 : Math.round(pos[0].start / width);
pos[0].end = pos[0].end === 0 ? 0 : Math.ceil(pos[0].end / width);
return pos;
} | /**
* Highlight to Hex
*
* @param {Object[]} pos
* @param {number} pos[].start
* @param {number} pos[].end
* @param {Object[]} args
* @returns {Object[]} pos
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromHex.tsx#L230-L247 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
LafTools | github_2023 | work7z | typescript | FromHex.highlightReverse | highlightReverse(pos, args) {
const delim = Utils.charRep(args[0] || "Space"),
len = delim === "\r\n" ? 1 : delim.length;
pos[0].start = pos[0].start * (2 + len);
pos[0].end = pos[0].end * (2 + len) - len;
// 0x and \x are added to the beginning if they are selected, so increment the positions accordingly
if (delim === "0x" || delim === "\\x") {
pos[0].start += 2;
pos[0].end += 2;
}
return pos;
} | /**
* Highlight from Hex
*
* @param {Object[]} pos
* @param {number} pos[].start
* @param {number} pos[].end
* @param {Object[]} args
* @returns {Object[]} pos
*/ | https://github.com/work7z/LafTools/blob/ec1910c3ddf2827b529e4e1f0bed06d762f33b4a/modules/web2-spa/src/[lang]/client/src/impl/tools/impl/conversion/FromHex.tsx#L258-L271 | ec1910c3ddf2827b529e4e1f0bed06d762f33b4a |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.