Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Sunday, September 4, 2016

Javascript Text Replacing Tool

JS Replace is a simple tool for programmers to copy&paste multiple text lines and make automatically changes on all of them by editing the Javascript code box. Tired of building throw-away scripts or complex SQL queries or repetitive Spreadsheet formulas to make simple changes on many rows of data, I developed a simple but powerful javascript tool to assist in such tasks. Use it!

 


Sunday, July 24, 2016

Simple ToDo-List Javascript application for the smartphone

I wrote a simple ToDo-List application in Javascript to use it in the smartphone. To try it, you need to download the todo-list.html file and then open it with your web browser (Note: not every smartphone lets you open correctly the downloaded HTML files):


It is just a HTML document that "saves" the items as parameters in the web browser address. This approach gives me persistence, Undo and Redo operations for free, just having it opened in a tab of the web browser (Note: it will work only if your web browser is configured to remember your opened tabs). Enjoy it!

Sunday, December 28, 2014

Simple JavaScript function to compare and sort localized strings

A recurring problem in JavaScript is sorting localized strings, that is, strings having characters from outside of the ASCII [A-Za-z] range, like for example the Spanish characters áéíóúüñ (and their uppercase equivalents).

For this problem I wrote the JavaScript function getLocaleStrCmpFn, which returns a function to compare and sort strings depending on the order given as parameter, for example, to sort an array of strings having Spanish characters you can do:

var ordES = ['AaÁá','Bb','Cc','Dd','EeÉé','Ff','Gg','Hh',
'IiÍí','Jj','Kk','Ll','Mm','Nn','Ññ','OoÓó','Pp','Qq',
'Rr','Ss','Tt','UuÚúÜü','Vv','Ww','Xx','Yy','Zz'];
var fnES = getLocaleStrCmpFn(ordES);

var arr = ['Álamo','abedul','Arce','abeto','Castaño','acacia'];
arr.sort(fnES);

Other ways to do it are the localeCompare function with additional non-standard arguments or the future JavaScript Internationalization API, but both are not supported in many versions of major browsers, so the locale-str-cmp.js solution is an easy way to sort strings for a specific locale or to create custom comparison functions. What do you think?