Last updated: November 27, 2023. You can use the JSZip library to extract file data from a zip file. First, you need to import JSZip into your project, for example by inserting the following CDN link from cdnjs into your project before usage: The data is output in blob format, which contains the raw file data. The data could also come from a HTTP request. In the below example, data is extracted from a zip file acquired from a fetch request: fetch(‘./my_zip_file.zip’) .then(res => res.blob()) .then(data => { extractFiles(data); }); function extractFiles(inputFiles) { JSZip.loadAsync(inputFiles) .then(res => { for (key of…
Author: drweb
Welcome to the racetrack of the web, where the race for speed is relentless, and the contenders are always gearing up for the next lap. In the world of web development, CSS (Cascading Style Sheets) has been a key player, defining the look and feel of websites since the dawn of digital aesthetics. But how has CSS evolved in terms of speed? Buckle up, as we dive into a journey through time, exploring the turbocharged evolution of CSS, without a single dance metaphor in sight. The Starting Line: The Early Days In the beginning, CSS was like a classic car:…
You know those One Time Password inputs? The UI is typically 4 or 6 numbers with individual inputs. Just from today… Here’s the UI the Safeway app uses in the Pharmacy section to log in. Here’s how Substack authenticates. Brad Frost was blogging about them recently. They certainly have some issue! Here’s one he spells out that I agree with wholeheartedly: I don’t like the pattern where each digit is its own text box. It’s an affordance that’s supposed to make things clearer, but it doesn’t (for me at least). Can I paste? Where do I paste? Is my paste going to…
Let’s dive into this magical world of CSS where we can create some truly eye-catching effects without needing to resort to any complex sorcery. Today, we’re exploring the holographic CSS effect. You know, that shiny, futuristic look that makes your website elements feel like they’re about to leap off the screen? Yep, that’s what we’re gonna demystify. The CSS Holographic Effect First off, the holographic effect in CSS is like the unicorn of web design. It’s not just about slapping on some glitter, it’s about creating depth, movement, and a touch of futurism, all while making sure it doesn’t look…
Over 250,000 websites are launched every day. With this, it’s essential to use CSS practices that elevate your page and frontload your services. With the right guidelines, you can translate your unique offering to digital consumers who are quick to dismiss subpar websites. If you look at Yahoo Finance’s ranking of the most visited websites in the world, the top 10 is littered with social media platforms. Beyond that, users visit websites built for search aggregation, personalized recommendations, shopping, and content generation. What all these have in common, in terms of the biggest CSS lessons to learn, is that there…
Last updated: December 12, 2023. Most often when defining a function, you are aware of how many arguments the function should accept: function add(x, y) { return x + y; }; add(1, 2); // Returns 3 The number of arguments accept can be extended manually: function add(x, y, z=0) { return x + y + z; }; add(1, 2); // Returns 3 add(1, 2, 3); // Returns 6 But this solution isn’t very scalable because you have to include a parameter in the function for each argument you may pass in when the function is called. A solution is to…
Last updated: December 12, 2023. To get the first date and day of the month, first create a new instance of the native Date object and set its date to the first day of the month: const date = new Date(); // Creates new date object, default is current date date.setDate(1); // Sets date to first day of month (count starts from 1) date.toLocaleDateString(‘en-us’); // returns date e.g. 12/1/2023 You can then extract the day (as a number or string) and the date (in this case always 1) as follows: date.getDay(); // returns 0-6, where 0 = Sunday and 6…
Last updated: December 13, 2023. An item in an array can be moved to its beginning by: Checking if item exists in the array (to prevent an unhandled error) Filtering the array of that value Inserting the item at the beginning of the array Here is an example in code: const array = [“Second”, “Third”, “First”]; // Check if a value exists… if (array.includes(“First”)) { //…filter this value from the array… const arrayFiltered = array.filter((val) => val !== “First”); //…and place it first in a new array, spreading the other values afterwards const res = [“First”, …arrayFiltered]; console.log(res); // […
Last updated: December 15, 2023. You can play an audio file in JavasScript by creating an Audio object, setting a URL and then calling the play() method on it: const audio = new Audio(); // Generates new Audio object, equivalent of HTML element but in JS audio.src = “https://openjavascript.info/2023/12/15/how-to-play-audio-in-javascript/./happy.mp3”; // Set URL to audio file to play audio.play(); // Play audio (usually generates error because user has not interacted with page) To prevent an error occurring when calling play() because the user has not interacted with the page, you can call it in response to a click event: Play The…
User input from HTML form fields is generally provided to JavaScript as a string. We’ve lived with that fact for decades but sometimes developers need to extract numbers from that string. There are multiple ways to get those numbers but let’s rely on regular expressions to extract those numbers! To employ a regular expression to get a number within a string, we can use \d+: const string = “x12345david”; const [match] = string.match(/(\d+)/); match; // 12345 Regular expressions are capable of really powerful operations within JavaScript; this practice is one of the easier operations. Converting the number using a Number()…