View Source IgniterJs.Parsers.Javascript.Parser (igniter_js v0.4.3)
Codemods for JavaScript files.
Summary
Functions
Check if a LiveSocket var exists in the given file or content and returns tuple.
Check if a LiveSocket var exists in the given file or content and returns boolean.
Check if an specific var exists in the given file or content and returns tuple.
Extend the hook object in the given file or content. It accepts a single object or a list of objects. It returns a tuple.
Extend a variable of object type in the given file or content by adding additional objects to it, based on their names.
Insert imports to the given file or content and returns tuple.
Check if a module is imported in the given file or content or contents and return tuple.
Check if a module is imported in the given file or content or content and returns boolean.
Remove imports from the given file or content. it accepts a single module or a list of modules. It returns a tuple.
Remove objects from the hooks in the given file or content. It accepts a single o bject or a list of objects. It returns a tuple.
Retrieve statistical information about the JavaScript source code, such as the number of functions, classes, debugger statements, imports, try-catch blocks, and throw statements.
Check if a specific var exists in the given file or content and returns boolean.
Functions
Check if a LiveSocket var exists in the given file or content and returns tuple.
alias IgniterJs.Parsers.Javascript.Parser
Parser.exist_live_socket(js_content)
Parser.exist_live_socket(js_content, :content)
Parser.exist_live_socket("/path/to/file.js", :path)
Check if a LiveSocket var exists in the given file or content and returns boolean.
alias IgniterJs.Parsers.Javascript.Parser
Parser.exist_live_socket?(js_content)
Parser.exist_live_socket?(js_content, :content)
Parser.exist_live_socket?("/path/to/file.js", :path)
Check if an specific var exists in the given file or content and returns tuple.
alias IgniterJs.Parsers.Javascript.Parser
Parser.exist_live_socket(js_content, var_name)
Parser.exist_live_socket(js_content, var_name, :content)
Parser.exist_live_socket("/path/to/file.js", var_name, :path)
Extend the hook object in the given file or content. It accepts a single object or a list of objects. It returns a tuple.
alias IgniterJs.Parsers.Javascript.Parser
Parser.extend_hook_object(js_content, "SomeObject")
Parser.extend_hook_object(js_content, ["SomeObject", "AnotherObject"], :content)
Parser.extend_hook_object("/path/to/file.js", "SomeObject", :path)
Extend a variable of object type in the given file or content by adding additional objects to it, based on their names.
This function ensures that duplicate entries are not added during the process.
This function accepts:
- The content or path of the JavaScript file.
- The name of the variable to be extended.
- A single object name or a list of object names to be added.
- The type indicating whether it's content (
:content
) or a path (:path
).
It returns a tuple with the status, function atom, and the updated content or an error message if the variable could not be found or modified.
## Examples
alias IgniterJs.Parsers.Javascript.Parser
objects_names = ["OXCTestHook", "MishkaHooks", "MishkaHooks", "OXCTestHook"]
Parser.extend_var_object_by_object_names(js_content, "Components", "TestHook")
Parser.extend_var_object_by_object_names("/path/to/file.js", "Components", objects_names, :path)
{:error, :extend_var_object_by_object_names, _output} =
Parser.extend_var_object_by_object_names("None", "Components", objects_names)
Insert imports to the given file or content and returns tuple.
alias IgniterJs.Parsers.Javascript.Parser
Parser.insert_imports(js_content, imports_lines)
Parser.insert_imports(js_content, imports_lines, :content)
Parser.insert_imports("/path/to/file.js", imports_lines, :path)
Check if a module is imported in the given file or content or contents and return tuple.
alias IgniterJs.Parsers.Javascript.Parser
Parser.module_imported(js_content, "module")
Parser.module_imported(js_content, "module", :content)
Parser.module_imported("/path/to/file.js", "module", :path)
Check if a module is imported in the given file or content or content and returns boolean.
alias IgniterJs.Parsers.Javascript.Parser
Parser.module_imported?(js_content, "module")
Parser.module_imported?(js_content, "module", :content)
Parser.module_imported?("/path/to/file.js", "module", :path)
Remove imports from the given file or content. it accepts a single module or a list of modules. It returns a tuple.
alias IgniterJs.Parsers.Javascript.Parser
Parser.remove_imports(js_content, "SomeModule")
Parser.remove_imports("/path/to/file.js", "SomeModule", :path)
Remove objects from the hooks in the given file or content. It accepts a single o bject or a list of objects. It returns a tuple.
alias IgniterJs.Parsers.Javascript.Parser
Parser.remove_objects_from_hooks(js_content, "SomeObject")
Parser.remove_objects_from_hooks(js_content, ["SomeObject", "AnotherObject"], :content)
Parser.remove_objects_from_hooks("/path/to/file.js", "SomeObject", :path)
Retrieve statistical information about the JavaScript source code, such as the number of functions, classes, debugger statements, imports, try-catch blocks, and throw statements.
This function accepts either the content of the JavaScript file or the path to the file, and returns a tuple with the status, function atom, and the extracted data as a map.
Examples
alias IgniterJs.Parsers.Javascript.Parser
# Analyze a JavaScript source file by providing its content
Parser.statistics(js_content)
# Analyze a JavaScript source file by providing its file path
Parser.statistics("/path/to/file.js", :path)
Check if a specific var exists in the given file or content and returns boolean.
alias IgniterJs.Parsers.Javascript.Parser
Parser.exist_live_socket?(js_content)
Parser.exist_live_socket?(js_content, :content)
Parser.exist_live_socket?("/path/to/file.js", :path)