-
Pairify - how to match balanced string pairs
posted in JavaScript on 2020-03-11 pairify balanced matches javascript pairs decided type stack line starter token code const position function category https -
I'm now actively working on a VSCode extension. I started it as a theme but then decided to add some more features. Like for example a tin line on the left side of the editor marking the current function scope. In order to do that I had to analyze the current file's code and find the lines that are included in that scope. The obvious approach will be to translate the code to AST and then traverse the tree finding the information that I need. This however will require the usage of a language server which now I don't want to deal with. So I decided to explore a brute force approach. Looping over the string characters and finding balanced matches. I quickly wrapped it into a library. I called it Pairify. It consumes text and returns an array of pairs. This blog post will show you how it works.
read more
-
Using media queries in JavaScript (AbsurdJS edition)
posted in JavaScript on 2014-03-04 media css function var width window matchmedia dom html mq absurdjs -
If you believe in responsive design you probably use a lot of media queries. That's a CSS feature which gives us the power to add something like if statements. We are able to apply rules only if the current page meets certain conditions. In this article I'll show you how I use media queries in JavaScript.
read more
-
A modern JavaScript router in 100 lines
posted in JavaScript on 2014-02-21 router javascript navigo match history node -
(The router here is now placed in its own project - Navigo. There is also another article Deep dive into client-side routing which you may find interesting)
Nowadays the popular single page applications are everywhere. Having such application means that you need a solid routing mechanism. Frameworks like Emberjs are truly build on top of a Router class. I'm still not sure that this is a concept which I like, but I'm absolutely sure that AbsurdJS should have a build-in Router. And, as with everything in this little library, it should be small, simple class. Let's see how such a module may look like.
read more
-
iPhone and iPod detection under JavaScript
posted in JavaScript on 2013-03-29 iphone ipod navigator useragent match -
A little code snippet for detecting iPhone or iPod. You can easily edit it to match iPad.
read more