repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
SequenceSplitter.execute
public execute(log: LogFunction): boolean { const self = this; traverse(this.ast, { ConditionalExpression(path) { if (path.parentPath && path.parentPath.isExpressionStatement()) { const replacement = t.ifStatement( path.node.test, ...
/** * Executes the transformation. * @param log The log function. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/controlFlow/sequenceSplitter.ts#L14-L160
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
SequenceSplitter.isExcluded
private isExcluded(node: t.Node): boolean { return t.isIdentifier(node) && node.name == 'eval'; }
/** * Returns whether a node that is the last in a sequence expression * is excluded from being placed on its own. * @param node The AST node. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/controlFlow/sequenceSplitter.ts#L168-L170
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ExpressionSimplifier.execute
public execute(log: LogFunction): boolean { const self = this; traverse(this.ast, { ['UnaryExpression|BinaryExpression'](path) { const replacement = path.isUnaryExpression() ? self.simplifyUnaryExpression(path.node) : self.simplifyBina...
/** * Executes the transformation. * @param log The log function. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/expressions/expressionSimplifier.ts#L45-L61
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ExpressionSimplifier.simplifyExpression
private simplifyExpression(expression: t.Expression): t.Expression { if (t.isUnaryExpression(expression) || t.isBinaryExpression(expression)) { const replacement = t.isUnaryExpression(expression) ? this.simplifyUnaryExpression(expression) : this.simplifyBinaryExpressi...
/** * Attempts to simplify an expression. * @param expression The expression. * @returns The expression in the simplest form possible. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/expressions/expressionSimplifier.ts#L68-L77
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ExpressionSimplifier.simplifyUnaryExpression
private simplifyUnaryExpression(expression: t.UnaryExpression): t.Expression | undefined { if (!ExpressionSimplifier.RESOLVABLE_UNARY_OPERATORS.has(expression.operator)) { return undefined; } else if (isNegativeNumericLiteral(expression)) { return undefined; // avoid trying to si...
/** * Attempts to simplify a unary expression. * @param expression The unary expression. * @returns The simplified expression or undefined. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/expressions/expressionSimplifier.ts#L84-L103
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ExpressionSimplifier.simplifyBinaryExpression
private simplifyBinaryExpression(expression: t.BinaryExpression): t.Expression | undefined { if ( !t.isExpression(expression.left) || !ExpressionSimplifier.RESOLVABLE_BINARY_OPERATORS.has(expression.operator) ) { return undefined; } const left = this....
/** * Attempts to simplify a binary expression. * @param expression The binary expression. * @returns The simplified expression or undefined. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/expressions/expressionSimplifier.ts#L110-L138
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ExpressionSimplifier.applyUnaryOperation
private applyUnaryOperation(operator: ResolvableUnaryOperator, argument: any): any { switch (operator) { case '-': return -argument; case '+': return +argument; case '!': return !argument; case '~': r...
/** * Applies a unary operation. * @param operator The operator. * @param argument The argument value. * @returns The resultant value. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/expressions/expressionSimplifier.ts#L146-L161
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ExpressionSimplifier.applyBinaryOperation
private applyBinaryOperation(operator: ResolvableBinaryOperator, left: any, right: any): any { switch (operator) { case '==': return left == right; case '!=': return left != right; case '===': return left === right; ...
/** * Applies a binary operation. * @param operator The resolvable binary operator. * @param left The value of the left expression. * @param right The value of the right expression. * @returns The resultant value. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/expressions/expressionSimplifier.ts#L170-L213
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ExpressionSimplifier.getResolvableExpressionValue
private getResolvableExpressionValue(expression: ResolvableExpression): any { switch (expression.type) { case 'NumericLiteral': case 'StringLiteral': case 'BooleanLiteral': case 'DecimalLiteral': case 'BigIntLiteral': return expression....
/** * Gets the real value from a resolvable expression. * @param expression The resolvable expression. * @returns The value. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/expressions/expressionSimplifier.ts#L220-L241
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ExpressionSimplifier.convertValueToExpression
private convertValueToExpression(value: any): t.Expression | undefined { switch (typeof value) { case 'string': return t.stringLiteral(value); case 'number': return value >= 0 ? t.numericLiteral(value) : t.unaryExpre...
/** * Attempts to convert a value of unknown type to an expression node. * @param value The value. * @returns The expression or undefined. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/expressions/expressionSimplifier.ts#L248-L265
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ExpressionSimplifier.isResolvableExpression
private isResolvableExpression(node: t.Node): node is ResolvableExpression { return ( (t.isLiteral(node) && !t.isRegExpLiteral(node) && !t.isTemplateLiteral(node)) || (t.isUnaryExpression(node) && node.operator == '-' && t.isLiteral(node.argument)) || (t.isIdentifier(node) &&...
/** * Returns whether a node is a resolvable expression that can be * evaluated safely. * @param node The AST node. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/expressions/expressionSimplifier.ts#L273-L281
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ObjectPacker.execute
public execute(log: LogFunction): boolean { const self = this; traverse(this.ast, { enter(path) { const variable = findConstantVariable<EmptyObjectExpression>( path, isEmptyObjectExpression ); if (!varia...
/** * Executes the transformation. * @param log The log function. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/objects/objectPacker.ts#L15-L113
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ObjectPacker.hasSelfReference
private hasSelfReference( value: t.Node, statementPath: NodePath, arrayIndex: number, referencePathSet: Set<NodePath>, log: LogFunction ): boolean { try { const valuePath = statementPath.parentPath!.get( `${statementPath.parentKey}.${arrayI...
/** * Searches a value for a reference to the object itself. Inlining this value * as an object property would be unsafe: https://github.com/ben-sb/obfuscator-io-deobfuscator/issues/39 * @param value The value of the object property. * @param statementPath The path of the statement assigning the pro...
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/objects/objectPacker.ts#L124-L156
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ObjectPacker.isPropertyAssignment
private isPropertyAssignment( node: t.Node, objectName: string ): node is t.AssignmentExpression & { left: t.MemberExpression } { return ( t.isAssignmentExpression(node) && t.isMemberExpression(node.left) && t.isIdentifier(node.left.object) && ...
/** * Returns whether a node is setting a property on a given object. * @param node The AST node. * @param objectName The name of the object. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/objects/objectPacker.ts#L164-L174
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
isEmptyObjectExpression
const isEmptyObjectExpression = (node: t.Node): node is EmptyObjectExpression => { return t.isObjectExpression(node) && node.properties.length == 0; };
/** * Returns whether a node is an empty object expression. * @param node The node. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/objects/objectPacker.ts#L184-L186
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ObjectSimplifier.constructor
constructor(ast: t.File, config: ObjectSimplificationConfig) { super(ast, config); this.config = config; }
/** * Creates a new transformation. * @param ast The AST. * @param config The config. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/objects/objectSimplifier.ts#L24-L27
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ObjectSimplifier.execute
public execute(log: LogFunction): boolean { const self = this; const usages: [NodePath, ProxyObject][] = []; let depth = 0; traverse(this.ast, { enter(path) { setProperty(path, 'depth', depth++); const variable = findConstantVariable<ProxyObje...
/** * Executes the transformation. * @param log The log function. * @returns Whether any changes were made. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/objects/objectSimplifier.ts#L34-L80
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ProxyObject.constructor
constructor(variable: ConstantVariable<ProxyObjectExpression>) { this.variable = variable; }
/** * Creates a new proxy object. * @param variable The variable. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/objects/proxyObject.ts#L27-L29
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ProxyObject.process
public process(): void { for (const property of this.variable.expression.properties) { if (t.isObjectProperty(property) && this.isLiteralPropertyKey(property)) { const key = t.isIdentifier(property.key) ? property.key.name : property.key.value; if (t.isLiteral(propert...
/** * Finds all the object's entries which can be replaced. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/objects/proxyObject.ts#L34-L52
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ProxyObject.getUsages
public getUsages(): NodePath[] { return this.variable.binding.referencePaths; }
/** * Returns the usages of the object. * @returns The usages. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/objects/proxyObject.ts#L58-L60
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ProxyObject.replaceUsage
public replaceUsage(path: NodePath): boolean { const parentPath = path.parentPath; if ( parentPath && parentPath.isMemberExpression() && this.isLiteralMemberKey(parentPath.node) && (!parentPath.parentPath || !parentPath.parentPath.isAssignm...
/** * Attempts to replace a usage of the object. * @param path The path of the usage. * @returns Whether it was replaced. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/objects/proxyObject.ts#L67-L101
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ProxyObject.isLiteralPropertyKey
private isLiteralPropertyKey( property: t.ObjectProperty ): property is | (t.ObjectProperty & { key: t.StringLiteral | t.NumericLiteral }) | (t.ObjectProperty & { computed: false; key: t.Identifier }) { return ( t.isStringLiteral(property.key) || t.isNumericLi...
/** * Returns whether an object property has a literal key. * @param property The object property. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/objects/proxyObject.ts#L108-L118
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ProxyObject.isLiteralMethodKey
private isLiteralMethodKey( property: t.ObjectMethod ): property is | (t.ObjectMethod & { key: t.StringLiteral | t.NumericLiteral }) | (t.ObjectMethod & { computed: false; key: t.Identifier }) { return ( t.isStringLiteral(property.key) || t.isNumericLiteral(pr...
/** * Returns whether an object method has a literal key. * @param property The object method. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/objects/proxyObject.ts#L125-L135
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ProxyObject.isLiteralMemberKey
private isLiteralMemberKey( member: t.MemberExpression ): member is | (t.MemberExpression & { property: t.StringLiteral | t.NumericLiteral }) | (t.MemberExpression & { computed: false; property: t.Identifier }) { return ( t.isStringLiteral(member.property) || ...
/** * Returns whether a member expression has a literal key. * @param member The member expression. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/objects/proxyObject.ts#L142-L152
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
PropertySimplifier.execute
public execute(log: LogFunction): boolean { const self = this; traverse(this.ast, { MemberExpression(path) { if ( path.node.computed && t.isStringLiteral(path.node.property) && t.isValidIdentifier(path.node.property...
/** * Executes the transformation. * @param log The log function. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/properties/propertySimplifier.ts#L14-L50
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
isProxyValue
const isProxyValue = (node: t.Node): boolean => { if (t.isFunction(node) || t.isBlockStatement(node) || t.isSequenceExpression(node)) { return false; } let isValid = true; traverse(node, { ['SequenceExpression|BlockStatement|Function|AssignmentExpression'](path) { isValid = ...
/** * Returns whether a node is a valid proxy function return value. * @param node The node. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/proxyFunctions/proxyFunction.ts#L41-L56
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ProxyFunction.constructor
constructor(expression: ProxyFunctionExpression) { this.expression = expression; }
/** * Creates a new proxy function. * @param expression The proxy function expression. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/proxyFunctions/proxyFunction.ts#L67-L69
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ProxyFunction.getReplacement
public getReplacement(args: Argument[]): t.Expression { const expression = t.isExpression(this.expression.body) ? copyExpression(this.expression.body) : this.expression.body.body[0].argument ? copyExpression(this.expression.body.body[0].argument) : t.identifier('u...
/** * Returns the replacement for a call of the proxy function. * @param args The arguments of the call. * @returns The replacement expression. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/proxyFunctions/proxyFunction.ts#L76-L84
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ProxyFunction.replaceParameters
private replaceParameters(expression: t.Expression, args: Argument[]): void { const paramMap = new Map<string, t.Node>( this.expression.params.map((param: t.Identifier, index: number) => [ param.name, args[index] || t.identifier('undefined') ]) ); ...
/** * Replaces usages of the proxy function's parameters with the concrete arguments for a given call. * @param expression The expression. * @param args The arguments of the call. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/proxyFunctions/proxyFunction.ts#L91-L122
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ProxyFunctionVariable.constructor
constructor(variable: ConstantVariable<ProxyFunctionExpression>) { super(variable.expression); this.variable = variable; }
/** * Creates a new proxy function variable. * @param variable The variable. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/proxyFunctions/proxyFunction.ts#L132-L135
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ProxyFunctionVariable.getCalls
public getCalls(): NodePath[] { return this.variable.binding.referencePaths; }
/** * Returns the calls to the proxy function. * @returns The calls to the proxy function. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/proxyFunctions/proxyFunction.ts#L141-L143
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ProxyFunctionVariable.replaceCall
public replaceCall(path: NodePath): boolean { if (path.parentPath && path.parentPath.isCallExpression() && path.key == 'callee') { const expression = this.getReplacement(path.parentPath.node.arguments); path.parentPath.replaceWith(expression); return true; } else { ...
/** * Attempts to replace a call of the proxy function. * @param path The path of the call. * @returns Whether it was replaced. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/proxyFunctions/proxyFunction.ts#L150-L158
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ProxyFunctionInliner.execute
public execute(log: LogFunction): boolean { const usages: [NodePath, ProxyFunctionVariable][] = []; let depth = 0; traverse(this.ast, { enter(path) { setProperty(path, 'depth', depth++); const variable = findConstantVariable<ProxyFunctionExpression>(p...
/** * Executes the transformation. * @param log The log function. * @returns Whether any changes were made. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/proxyFunctions/proxyFunctionInliner.ts#L18-L46
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
StringRevealer.execute
public execute(log: LogFunction): boolean { const self = this; traverse(this.ast, { enter(path) { if ( self.isDirectStringArrayDeclarator(path.node) || self.isStringArrayFunction(path.node) ) { const...
/** * Executes the transformation. * @param log The log function. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/strings/stringRevealer.ts#L31-L306
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
StringRevealer.isDirectStringArrayDeclarator
private isDirectStringArrayDeclarator(node: t.Node): node is t.VariableDeclarator & { id: t.Identifier; init: t.ArrayExpression & { elements: t.StringLiteral[] }; } { return ( t.isVariableDeclarator(node) && t.isIdentifier(node.id) && node.init != undefine...
/** * Returns whether a node is directly declaring a string array. * @param node The AST node. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/strings/stringRevealer.ts#L313-L325
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
StringRevealer.isStringArrayFunction
private isStringArrayFunction( node: t.Node ): node is t.FunctionDeclaration & { id: t.Identifier } { return ( t.isFunctionDeclaration(node) && t.isBlockStatement(node.body) && node.body.body.length == 3 && isDeclarationOrAssignmentStatement( ...
/** * Returns whether a node is the function that splits and returns the * string array. * @param node The AST node. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/strings/stringRevealer.ts#L333-L368
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
StringRevealer.isBasicStringArrayWrapper
private isBasicStringArrayWrapper( node: t.Node, stringArrayName: string ): node is t.FunctionDeclaration { return ( t.isFunctionDeclaration(node) && t.isBlockStatement(node.body) && node.body.body.length == 3 && isDeclarationOrAssignmentStatem...
/** * Returns whether a node is a basic string array wrapper function. * @param node The AST node. * @param stringArrayName The name of the string array function. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/strings/stringRevealer.ts#L376-L427
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
StringRevealer.isComplexStringArrayWrapper
private isComplexStringArrayWrapper( node: t.Node, stringArrayName: string ): node is t.FunctionDeclaration { return ( t.isFunctionDeclaration(node) && t.isBlockStatement(node.body) && node.body.body.length == 3 && isDeclarationOrAssignmentStat...
/** * Returns whether a node is either a base 64 or RC4 string array wrapper function. * @param node The AST node. * @param stringArrayName The name of the string array function. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/strings/stringRevealer.ts#L435-L487
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
StringRevealer.isComplexDirectStringArrayWrapper
private isComplexDirectStringArrayWrapper( node: t.Node, stringArrayName: string ): node is t.FunctionDeclaration { let lastStatement: t.Statement; return ( t.isFunctionDeclaration(node) && t.isBlockStatement(node.body) && node.body.body.length >= ...
/** * Returns whether a node is either a base 64 or RC4 string array wrapper function, * around a direct string array. * @param node The AST node. * @param stringArrayName The name of the string array. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/strings/stringRevealer.ts#L496-L531
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
StringRevealer.isRotateStringArrayCall
private isRotateStringArrayCall( node: t.Node, stringArrayName: string ): node is t.CallExpression & { callee: t.FunctionExpression & { body: t.BlockStatement }; arguments: [t.Identifier, t.NumericLiteral]; } { return ( t.isCallExpression(node) && ...
/** * Returns whether a node is a call to rotate the string array. * @param node The AST node. * @param stringArrayName The name of the string array function. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/strings/stringRevealer.ts#L539-L588
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
StringRevealer.isStringArrayWrapperCall
private isStringArrayWrapperCall( node: t.Node, wrapperType: DecoderType ): node is t.CallExpression & { callee: t.Identifier; arguments: (t.NumericLiteral | t.StringLiteral)[]; } { return ( t.isCallExpression(node) && t.isIdentifier(node.callee) &...
/** * Returns whether a node is a call of the string array wrapper function. * @param node The AST node. * @param wrapperType The type of string wrapper. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/strings/stringRevealer.ts#L596-L614
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
StringRevealer.isEscapedStringLiteral
private isEscapedStringLiteral(node: t.Node): node is t.StringLiteral { return ( t.isStringLiteral(node) && node.extra != undefined && typeof node.extra.rawValue == 'string' && typeof node.extra.raw == 'string' && node.extra.raw.replace(/["']/g, '') !=...
/** * Returns whether a node is an escaped string literal. * @param node The AST node. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/strings/stringRevealer.ts#L621-L629
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ConstantPropgator.execute
public execute(log: LogFunction): boolean { const self = this; traverse(this.ast, { enter(path) { // note that in general this is unsafe, should perform data flow analysis to handle params that are constants regardless of their runtime value const variable = ...
/** * Executes the transformation. * @param log The log function. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/variables/constantPropagator.ts#L17-L51
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
isLiteral
const isLiteral = (node: t.Node): node is Literal => { return t.isLiteral(node) && !t.isRegExpLiteral(node); };
/** * Returns whether a node is a literal that can be safely propagated. * @param node The node. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/variables/constantPropagator.ts#L65-L67
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ReassignmentRemover.execute
public execute(log: LogFunction): boolean { const self = this; traverse(this.ast, { enter(path) { const variable = findConstantVariable<t.Identifier>(path, t.isIdentifier); if (!variable || variable.name == variable.expression.name) { retu...
/** * Executes the transformation. * @param log The log function. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/variables/reassignmentRemover.ts#L16-L76
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ReassignmentRemover.isExcludedConstantViolation
private isExcludedConstantViolation(assignedBinding: Binding) { if ( assignedBinding.constantViolations.length == 1 && assignedBinding.path.isFunctionDeclaration() ) { const functionParent = assignedBinding.constantViolations[0].getFunctionParent(); return...
/** * Checks whether a binding has a constant violation that reassigns a function from * within (i.e. string decoder function), and thus should be treated as constant. * @param assignedBinding The binding. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/variables/reassignmentRemover.ts#L84-L94
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
UnusedVariableRemover.execute
public execute(log: LogFunction): boolean { const self = this; traverse(this.ast, { Scope(path) { for (const binding of Object.values(path.scope.bindings)) { if ( !binding.referenced && binding.constantViola...
/** * Executes the transformation. * @param log The log function. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/variables/unusedVariableRemover.ts#L15-L86
686b3dce0aeadb100c262ba6cbe1e04812217736
easyblocks
github_2023
easyblockshq
typescript
configTraverse
function configTraverse( config: NoCodeComponentEntry, context: Pick<CompilationContextType, "definitions">, callback: ConfigTraverseCallback ): void { configTraverseInternal(config, context, callback, ""); }
/** * Traverses given `config` by invoking given `callback` for each schema prop defined within components from `context` */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/core/src/compiler/configTraverse.ts#L16-L22
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
normalize
const normalize = (x: any) => { if (!Array.isArray(x) || x.length === 0) { let componentDefinition: NoCodeComponentDefinition | undefined; for (const componentIdOrType of schemaProp.accepts) { componentDefinition = findComponentDefinitionById( componentIdOrType, ...
// Here:
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/core/src/compiler/definitions.ts#L364-L412
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
$findComponentDefinition
function $findComponentDefinition( config: NoCodeComponentEntry | undefined | null, context?: AnyContextWithDefinitions ): InternalComponentDefinition | undefined { if (!config) { return undefined; } return $findComponentDefinitionById(config._component, context); }
/** * Generic */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/core/src/compiler/findComponentDefinition.ts#L47-L56
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
getMostCommonValueFromRichTextParts
function getMostCommonValueFromRichTextParts< RichTextPartProperty extends Extract< keyof RichTextPartComponentConfig, "color" | "font" > >( richTextComponentConfig: RichTextComponentConfig, prop: RichTextPartProperty, compilationContext: CompilationContextType, cache: CompilationCache ) { const r...
/** * Returns the most common value for given `prop` parameter among all @easyblocks/rich-text-part components from `richTextComponentConfig`. */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/core/src/compiler/getMostCommonValueFromRichTextParts.ts#L18-L97
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
stripRichTextPartSelection
function stripRichTextPartSelection(value: string): string { return value.replace(/\.\{\d+,\d+\}$/g, ""); }
/** * When selecting text within $richText, we keep information about which text parts are selected * within focused fields. If the text part is partially selected, we add information about the selection. * This selection has format: ".{textPartCharacterSelectionStartIndex,textPartCharacterSelectionEndIndex}". * We...
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/core/src/compiler/parsePath.ts#L9-L11
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
scalar
function scalar<T>( value: ScalarOrCollection<T> ): Exclude<ScalarOrCollection<T>, Array<T>> { return value as Exclude<ScalarOrCollection<T>, Array<T>>; }
// This type only narrows result of `styles.styled` property
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/core/src/compiler/resop.test.ts#L122-L126
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
squashCSSResults
function squashCSSResults( scalarValues: { [key: string]: any }, devices: Devices, disableNesting?: boolean ): any { // Let's check whether scalarValues represent object (for nesting) or a scalar value. let objectsNum = 0; let noObjectsNum = 0; let arraysNum = 0; for (const breakpointName in scalarValu...
/** * Input like: { breakpoint1: sth, breakpoint2: sth, breakpoint3: sth, ... } */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/core/src/compiler/resop.ts#L24-L178
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
build
function build<T extends SchemaProp>( schemaProp: T, editorContext: EditorContextType, value?: any ) { return { def: getSchemaDefinition<T>(schemaProp, editorContext) as any, // temporarily as any field: getTinaField(schemaProp, editorContext, value), }; }
/** * IMPORTANT!!! * * There's a heavy coupling between getTinaFields and builds. * * That's why we introduce new compound type that combines those two functions and we test both at the same time! */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/core/src/compiler/schemaPropDefinitions.test.ts#L147-L156
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
defres
function defres(x: any) { return { $res: true, b4: x, }; }
// default responsive
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/core/src/compiler/schemaPropDefinitions.test.ts#L698-L703
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
expectToMatchObjectOrEqual
function expectToMatchObjectOrEqual( input: any, output: any, useMatchObject?: boolean ) { if (typeof input === "object" && useMatchObject) { expect(input).toMatchObject(output); } else { expect(input).toEqual(output); } }
/** * This matcher is here on purpose. If we have space, then we really want to test with toMatchObject, because of linearization. */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/core/src/compiler/schemaPropDefinitions.test.ts#L719-L729
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
simpleTest
function simpleTest( { field, def }: ReturnType<typeof build>, rawValue: any, outputValue: any, useMatchObject?: boolean ) { return superTest( { field, def }, rawValue, outputValue, outputValue, responsiveValueFill( outputValue, editorContext.devices, getDevicesWidths(edi...
// compiled, field and normalized are the same
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/core/src/compiler/schemaPropDefinitions.test.ts#L804-L822
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
testThemeValue
function testThemeValue( x: ReturnType<typeof build>, defaultValue: any, // Correct normalized default value globalDefaultValue: any, refVal1: any, // { value: "red", ref: "devRed"} refVal2: any, // { value: "blue", ref: "devBlue" } refVal3: any, // { value: "white", ref: "white" } refValResponsive: any, ...
/** * Color, Font, Space * * !!! important !!! * * For now we use "Select" widget which means that we only can show references. * * This means that the value like { value: "sth" } which is NOT a ref is always treated as INCORRECT VALUE. * * What if reference is missing? We set first available reference from th...
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/core/src/compiler/schemaPropDefinitions.test.ts#L1282-L1617
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
testIconWithDefaultIconAsResult
function testIconWithDefaultIconAsResult(x: ReturnType<typeof build>) { const DEFAULT_ICON = arrowLeftIcon.value; const DEFAULT_ICON_VALUE = { tokenId: "$sliderLeft", value: DEFAULT_ICON, }; expect(x.field.label).toBe("blabla"); expect(x.field.name).toBe("blabla"); expect(x.field.component).toBe("t...
/** * ICON */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/core/src/compiler/schemaPropDefinitions.test.ts#L2011-L2066
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
testExternalFieldAgainstDefault
function testExternalFieldAgainstDefault( x: any, defaultVal: UnresolvedResource ) { simpleTest(x, undefined, defaultVal); simpleTest(x, 100, defaultVal); simpleTest(x, {}, defaultVal); simpleTest(x, null, defaultVal); simpleTest(x, "someId", { id: null, widgetId: "product", }); simpleTest( ...
/** * PRODUCT */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/core/src/compiler/schemaPropDefinitions.test.ts#L2151-L2172
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
traverseComponents
function traverseComponents( config: NoCodeComponentEntry, context: CompilationContextType, callback: TraverseComponentsCallback ): void { traverseComponentsInternal(config, context, callback, ""); }
/** * Traverses given `config` by invoking given `callback` for each schema prop defined within components from `context` */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/core/src/compiler/traverseComponents.ts#L13-L19
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
filterNonComparableProperties
function filterNonComparableProperties(obj: Text): ComparableText { return keys(obj) .filter<keyof ComparableText>((key): key is keyof ComparableText => ["color", "font", "TextWrapper"].includes(key) ) .reduce((filteredObject, currentKey) => { filteredObject[currentKey] = obj[currentKey]; ...
// This function might be useful in the future, but right now it's not needed.
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/core/src/compiler/builtins/$richText/withEasyblocks.ts#L295-L304
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
createTemporaryEditor
function createTemporaryEditor( editor: Pick<Editor, "children" | "selection"> ): Editor { const temporaryEditor = withEasyblocks(withReact(createEditor())); temporaryEditor.children = [...editor.children]; temporaryEditor.selection = editor.selection ? { ...editor.selection } : null; return temporaryEditor; ...
// Slate's transforms methods mutates given editor instance.
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/core/src/compiler/builtins/$richText/utils/createTemporaryEditor.ts#L8-L15
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
stripRichTextPartSelection
function stripRichTextPartSelection(value: string): string { return value.replace(/\.\{\d+,\d+\}$/g, ""); }
/** * When selecting text within $richText, we keep information about which text parts are selected * within focused fields. If the text part is partially selected, we add information about the selection. * This selection has format: ".{textPartCharacterSelectionStartIndex,textPartCharacterSelectionEndIndex}". * We...
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/core/src/compiler/builtins/$richText/utils/stripRichTextTextPartSelection.ts#L8-L10
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
isString
const isString = (color: string) => color && typeof color === "string";
/** * This is a copy of validate-color function from validate-color npm package. This package has problem with bundling, so I copied it here. It was modified 100 years ago anyway and had 32 stars, so nothing fancy really. */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/core/src/compiler/validate-color/index.ts#L9-L9
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
responsiveValueAt
function responsiveValueAt<T>( responsiveValue: TrulyResponsiveValue<T>, breakpointIndex: string ): T | undefined { if (breakpointIndex === "$res") { throw new Error( "This situation isn't possible! Value of responsive value must be accessed by valid breakpoint name" ); } const breakpointValue ...
/** * Because of how `TrulyResponsiveValue` is typed, if we try to access value at the current breakpoint it would return `true | T | undefined`. * The literal type `true` in this type shouldn't be included, because it makes no sense. * This comes from definition of `$res` property which is a special property that m...
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/core/src/responsiveness/responsiveValueAt.ts#L8-L23
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
close
const close = (config: NoCodeComponentEntry) => { const _itemProps = { [parentData._component]: { [fieldName]: {}, }, }; const newComponent = fieldName.startsWith("$") ? config : duplicateConfig( normalize( { ...config, _item...
// const defaultPickerMode =
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/editor/src/ModalPicker.tsx#L81-L102
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
duplicateItems
function duplicateItems( form: Form, fieldNames: Array<string>, compilationContext: CompilationContextType ): Array<string> | undefined { const duplicatableFieldNames = fieldNames.filter((fieldName) => isFieldDuplicatable(fieldName, form, compilationContext) ); if (duplicatableFieldNames.length === 0) ...
/** * Duplicates fields given in `fieldNames` within given `form`. * `compilationContext` is used to properly duplicate elements associated with given names. * @returns Array of fields to focus */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/editor/src/editorActions.ts#L91-L140
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
moveItems
function moveItems( form: Form, fieldsToMove: Array<string>, direction: "top" | "right" | "bottom" | "left" ): Array<string> | undefined { const nextFocusedFields: Array<string> = []; const isMovingMultipleFields = fieldsToMove.length > 1; if (direction === "top" || direction === "left") { const fields...
/** * Moves fields given in `fieldNamesToRemove` within given `form` in given `direction`. * @returns Array of fields to focus. */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/editor/src/editorActions.ts#L155-L258
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
removeItems
function removeItems( form: Form, fieldNamesToRemove: Array<string>, compilationContext: CompilationContextType ): Array<string> | undefined { const removableFieldNames = fieldNamesToRemove.filter((fieldName) => isFieldRemovable(fieldName, form, compilationContext) ); if (removableFieldNames.length ===...
/** * Removes fields given in `fieldNamesToRemove` from given `form`. * @returns Array of fields to focus */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/editor/src/editorActions.ts#L281-L366
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
Form.values
get values(): S | undefined { if (this.loading) { return undefined; } return this.finalForm.getState().values || (this.initialValues as S); }
/** * Returns the current values of the form. * * if the form is still loading it returns `undefined`. */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/editor/src/form.ts#L106-L111
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
Form.initialValues
get initialValues() { return this.finalForm.getState().initialValues; }
/** * The values the form was initialized with. */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/editor/src/form.ts#L116-L118
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
Form.updateFields
updateFields(fields: F[]) { this.fields = fields; }
/** * @deprecated Unnecessary indirection */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/editor/src/form.ts#L123-L125
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
Form.subscribe
subscribe: FormApi<S>["subscribe"] = (cb, options) => { return this.finalForm.subscribe(cb, options); }
/** * Subscribes to changes to the form. The subscriber will only be called when * values specified in subscription change. A form can have many subscribers. */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/editor/src/form.ts
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
Form.change
change(name: string, value?: any) { if (process.env.NODE_ENV === "development") { console.groupCollapsed("Change to", name === "" ? '""' : `"${name}"`); console.log("Old config", this.values); console.log("Old value", dotNotationGet(this.values, name)); this.finalForm.change(name as keyof S,...
/** * Changes the value of the given field. * * @param name * @param value */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/editor/src/form.ts#L153-L166
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
Form.updateValues
updateValues(values: S) { this.finalForm.batch(() => { const activePath: any = this.finalForm.getState().active; if (!activePath) { updateEverything<S>(this.finalForm, values); } else { updateSelectively<S>(this.finalForm, values); } }); }
/** * Updates multiple fields in the form. * * The updates are batched so that it only triggers one `onChange` event. * * In order to prevent disruptions to the user's editing experience this * function will _not_ update the value of any field that is currently * being edited. * * @param valu...
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/editor/src/form.ts#L183-L193
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
Form.updateInitialValues
updateInitialValues(initialValues: S) { this.finalForm.batch(() => { const values = this.values || ({} as S); this.finalForm.initialize(initialValues); const activePath: any = this.finalForm.getState().active; if (!activePath) { updateEverything<S>(this.finalForm, values); } e...
/** * Replaces the initialValues of the form without deleting the current values. * * This function is helpful when the initialValues are loaded asynchronously. * * @param initialValues */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/editor/src/form.ts#L202-L214
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
isAnyFieldSelected
function isAnyFieldSelected(focusedFields: string[]) { return focusedFields.length > 0 && focusedFields[0] !== ""; }
// FIXME: This is my mistake, because I was lazy at the beginning and it was easier for me to introduce changes
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/editor/src/useEditorGlobalKeyboardShortcuts.ts#L154-L156
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
createThrottledHandler
function createThrottledHandler(callback: (event: Event) => void) { let isTicking = false; return (event: Event) => { if (isTicking) { return; } requestAnimationFrame(() => { callback(event); isTicking = false; }); isTicking = true; }; }
/** * https://developer.mozilla.org/en-US/docs/Web/API/Element/scroll_event#scroll_event_throttling */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/editor/src/EditableComponentBuilder/SelectionFrameController.tsx#L231-L246
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
isString
const isString = (color: string) => color && typeof color === "string";
/** * This is a copy of validate-color function from validate-color npm package. This package has problem with bundling, so I copied it here. It was modified 100 years ago anyway and had 32 stars, so nothing fancy really. */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/editor/src/sidebar/validate-color/index.ts#L9-L9
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
getUniqueValues
function getUniqueValues< Collection extends Array<any>, Item extends Collection[number] >( collection: Collection, mapper?: (item: Item, index: number) => string | undefined ): Array<Item> { if (mapper) { const uniqueValues = new Set<string | undefined>(); const uniqueItems: Array<Item> = []; co...
/** * * @param collection Array of values * @param mapper Optional callback function that will be invoked for each item of given array to map it into comparable string */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/editor/src/tinacms/fields/components/getUniqueValues.ts#L6-L30
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
richTextCacheInvalidator
const richTextCacheInvalidator: CacheInvalidator = ( cache, changedPath, context ) => { const cacheKeysToRemove: Array<string> = []; const { templateId, fieldName, parent } = parsePath( changedPath, context.form ); const isRichTextOrRichTextAncestorComponent = templateId.startsWith("@easybloc...
// $richText and @easyblocks/rich-text-part uses a lot of portals to display correct fields within sidebar
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/editor/src/tinacms/form-builder/utils/createFieldController.ts#L400-L438
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
useUpdateFormFields
function useUpdateFormFields(form: Form, fields?: InternalField[]) { React.useEffect(() => { if (typeof fields === "undefined") return; form.updateFields(fields); }, [form, fields]); }
/** * A React Hook that update's the `Form` if `fields` are changed. * * This hook is useful when dynamically creating fields, or updating * them via hot module replacement. */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/editor/src/tinacms/react-core/use-form.ts#L88-L93
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
useUpdateFormLabel
function useUpdateFormLabel(form: Form, label?: string) { React.useEffect(() => { if (typeof label === "undefined") return; form.label = label; }, [form, label]); }
/** * A React Hook that update's the `Form` if the `label` is changed. * * This hook is useful when dynamically creating creating the label, * or updating it via hot module replacement. */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/editor/src/tinacms/react-core/use-form.ts#L101-L106
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
useUpdateFormValues
function useUpdateFormValues(form: Form, values?: any) { React.useEffect(() => { if (typeof values === "undefined") return; form.updateValues(values); }, [form, values]); }
/** * Updates the Form with new values. * * Only updates fields that are: * * 1. registered with the form * 2. not currently [active](https://final-form.org/docs/final-form/types/FieldState#active) * * This hook is useful when the form must be kept in sync with the data source. */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/editor/src/tinacms/react-core/use-form.ts#L118-L123
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
getConfigSnapshot
function getConfigSnapshot(config: NoCodeComponentEntry): NoCodeComponentEntry { const strippedConfig = deepClone(config); return strippedConfig; }
/** * Outputs comparable config that is FULL COPY of config */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/editor/src/utils/config/getConfigSnapshot.ts#L7-L10
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
mockConsoleMethod
function mockConsoleMethod< ConsoleMethodName extends Exclude<keyof Console, "Console"> >( methodName: ConsoleMethodName, implementation: (...args: Array<any>) => void = () => {}, options: { debug: boolean } = { debug: false } ) { const originalConsoleMethod = console[methodName]; const mockedConsoleMethod ...
/** * Mocks given method of `console` object. If `implementation` is not given, it defaults to noop. */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/test-utils/src/index.ts#L4-L32
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
mock
function mock<Implementation extends (...args: any) => any>( implementation: Implementation ): MockedFn<Implementation> { return jest.fn<ReturnType<Implementation>, Parameters<Implementation>>( implementation ); }
/** * Wrapper for `jest.fn` function, but with types which automatically infer parameters type and return type. * This is more handy for cases where the mocked function has its dedicated type. */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/test-utils/src/index.ts#L43-L49
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
nonNullable
function nonNullable() { return function <T extends Array<any>>( value: T[number] ): value is NonNullable<T[number]> { return value != null; }; }
/** * Returns a new function that filters nullable elements to be used as callback of `.filter` method. * It's useful because it has already defined guard which otherwise would be repeated in many places * and also it automatically changes the return value of filter function by extracting `null` and `undefined` type...
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/utils/src/array/nonNullable.ts#L11-L17
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
toArray
function toArray<T extends {}>(scalarOrCollection: T | Array<T>): Array<T> { if (Array.isArray(scalarOrCollection)) { return scalarOrCollection; } return [scalarOrCollection]; }
// eslint-disable-next-line @typescript-eslint/ban-types
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/utils/src/array/toArray.ts#L2-L8
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
entries
function entries<T extends object>(o: T): Entries<T> { return Object.entries(o) as Entries<T>; }
/** * `Object.entries` is badly typed for its reasons and this function just fixes it. * https://stackoverflow.com/questions/55012174/why-doesnt-object-keys-return-a-keyof-type-in-typescript */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/utils/src/object/entries.ts#L9-L11
c97eaa1170131224644fd119bb61173b9c8d6e88
easyblocks
github_2023
easyblockshq
typescript
keys
function keys<T extends object>(o: T): Array<keyof T> { return Object.keys(o) as unknown as Array<keyof T>; }
/** * `Object.keys` is badly typed for its reasons and this function just fixes it. * https://stackoverflow.com/questions/55012174/why-doesnt-object-keys-return-a-keyof-type-in-typescript */
https://github.com/easyblockshq/easyblocks/blob/c97eaa1170131224644fd119bb61173b9c8d6e88/packages/utils/src/object/keys.ts#L5-L7
c97eaa1170131224644fd119bb61173b9c8d6e88
doculite
github_2023
stefanbielmeier
typescript
Database.getDb
private async getDb(): Promise<SQLDb | null> { if (!this.db) { const db = await this.connectToDatabase(); // set this.db = db; // listen // this.db.on("profile", (sql: string) => { // this.pubSub.publish("profile", sql); // }); this.db.on( "change", ...
// connect to DB
https://github.com/stefanbielmeier/doculite/blob/113fa110874e6ad72fc8f75c42261e3d8999ff65/src/database.ts#L44-L70
113fa110874e6ad72fc8f75c42261e3d8999ff65
doculite
github_2023
stefanbielmeier
typescript
Database.addDoc
public async addDoc( collection: Collection, doc: JsonStoreValue ): Promise<boolean> { const db = await this.getDb(); try { await this.createNewDoc(db, collection, doc); } catch (e) { console.log("error", e); return false; } return true; }
// set Doc to DB
https://github.com/stefanbielmeier/doculite/blob/113fa110874e6ad72fc8f75c42261e3d8999ff65/src/database.ts#L82-L96
113fa110874e6ad72fc8f75c42261e3d8999ff65
doculite
github_2023
stefanbielmeier
typescript
Database.getDoc
public async getDoc(collection: Collection, docId: string) { const db = await this.getDb(); const value = await this.getDocFromCollection(db, collection, docId); return value; }
// get doc from DB
https://github.com/stefanbielmeier/doculite/blob/113fa110874e6ad72fc8f75c42261e3d8999ff65/src/database.ts#L137-L143
113fa110874e6ad72fc8f75c42261e3d8999ff65
doculite
github_2023
stefanbielmeier
typescript
Database.createNewDoc
private async createNewDoc( db: SQLDb | null, collection: Collection, doc: JsonStoreValue ): Promise<void> { if (!db) return; await this.createCollection(db, collection); const partialQuery = `INSERT INTO ${collection} VALUES (json(?))`; const JSONdoc = JSON.stringify(doc); // convert t...
// function to insert something into the JSON database
https://github.com/stefanbielmeier/doculite/blob/113fa110874e6ad72fc8f75c42261e3d8999ff65/src/database.ts#L212-L225
113fa110874e6ad72fc8f75c42261e3d8999ff65
doculite
github_2023
stefanbielmeier
typescript
Database.getDocFromCollection
private async getDocFromCollection( db: SQLDb | null, collection: Collection, docId: string ): Promise<JsonStoreValue | null> { if (!db) return null; const partialQuery = `SELECT value FROM ${collection} WHERE id = ?`; const row = await db.get(partialQuery, [docId]); if (!row) { r...
// function to get the value of a key
https://github.com/stefanbielmeier/doculite/blob/113fa110874e6ad72fc8f75c42261e3d8999ff65/src/database.ts#L228-L245
113fa110874e6ad72fc8f75c42261e3d8999ff65
uniapp-vue3-template
github_2023
oyjt
typescript
parseRoutes
function parseRoutes(pagesJson = {} as any) { if (!pagesJson.pages) { pagesJson.pages = []; } if (!pagesJson.subPackages) { pagesJson.subPackages = []; } function parsePages(pages = [] as any, rootPath = '') { const routes = []; for (let i = 0; i < pages.length; i++) { routes.push({ ...
/** * 解析路由地址 * @param {object} pagesJson * @returns [{"path": "/pages/tab/home/index","needLogin": false},...] */
https://github.com/oyjt/uniapp-vue3-template/blob/455dee33b8dfd71f82f4fdd910eeceda492fb554/src/router/index.ts#L13-L44
455dee33b8dfd71f82f4fdd910eeceda492fb554
uniapp-vue3-template
github_2023
oyjt
typescript
setupStore
function setupStore(app: App) { const store = createPinia(); const piniaPersist = createPersistedState({ storage: { getItem: uni.getStorageSync, setItem: uni.setStorageSync, }, }); store.use(piniaPersist); app.use(store); }
// 安装pinia状态管理插件
https://github.com/oyjt/uniapp-vue3-template/blob/455dee33b8dfd71f82f4fdd910eeceda492fb554/src/store/index.ts#L11-L23
455dee33b8dfd71f82f4fdd910eeceda492fb554