Is there a way to encode and decode the closures?
Closures are not encodable or decodable as they are blocks code compiled into your program. Besides the fact that they might need to capture parts of the state of your program dynamically (which leads to a difficult technical challenge of making this work), consider the security implications of allowing you to arbitrarily encode and decode parts of the executable portions of your program: what happens when you attempt to reload the encoded class back into your app and run it? What if someone has maliciously edited an archive to insert code into your program? There is no reasonable way to tell whether the closure is valid/safe to run or not, past loading it back into your process.
This would be terribly insecure, and is generally not even allowed by the system. (Perhaps look into writable vs. executable memory — for this security reason, many operating systems designate blocks of memory as either being executable [e.g. the code in your program] or writable [e.g. data that you read into memory/manipulate], but not both.)
Google Closure Compiler inlines a repeatedly used private property - a flaw or am I missing something?
This is covered in the Closure Compiler FAQ:
https://github.com/google/closure-compiler/wiki/FAQ#closure-compiler-inlined-all-my-strings-which-made-my-code-size-bigger-why-did-it-do-that
There are cases where inlining a string will make code size larger post-gzip, but I don't expect that will be the case here as it is unlikely to "flood" the gzip compression window.
How can I encode and decode a objedct to Base64?
Use Buffer
.
const object = {
foo: 'bar',
};
// convert it to base64
const base64 = Buffer.from(JSON.stringify(object)).toString('base64');
console.table({ base64 });
// convert it back
const back = JSON.parse(Buffer.from(base64, 'base64').toString('utf-8'));
console.log(back);
How to encode a string for displaying in HTML in JavaScript?
You can decode HTML content by using decodeURIComponent. for more details (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent)
const uri = "<p>How are you?</p>";
const decodeUri = decodeURIComponent(uri);
console.log(decodeUri)
Related Topics
How to Handle Parameter Validation Swift
Swiftui - Make Toolbar's Navigationlink Use Detail View
Swift For-In Loop with Enumerate on Custom Array2D Class
How to Move Platform with Velocity
In Swift, Can One Use a String to Access a Struct Property
Why Strings Are Not Equal in My Case
Swift Lazy Stored Property Versus Regular Stored Property When Using Closure
How to Use Spritekit Archives with Skspritenode Subclasses
Swift: How to Fix Infinite Loop When Adding a Value to a Firebase Variable
Swift ? Must Be Followed by a Call, Member Lookup, or Subscript
Problem with Gesture in Xcode 12 and iOS 14
Dyld: Library Not Loaded, App Requires Afnetworking 2.0.0 But Provides Version 1.0.0
Get Nil When Looking for File in Subdirectory of Main Bundle
Swiftui on MACos - Handle Single-Click and Double-Click at the Same Time
How to Delete Object in Array of Dictionaries Using Key Value
Swift: Can Not Use Array Filter in If Let Statement Condition