Tuesday 8 October 2013

How to use sugar.js file in Appcelerator ?

// Sugar.js file is very useful in our developing process .

// Today I create one sample  code which contain sugar.js file and it help me a lot.

// Sugar is a Javascript library that extends native objects with helpful methods. It is designed to be intuitive, unobtrusive, and let you do more with less code.

// Sugar provides methods on strings like from, to, first, last, add, and remove to make modifying strings intuitive and readable, as well as others like each, chars, words, lines, paragraphs which allow iterating over chunks of text. Common escaping methods like escapeURL, escapeHTML, and escapeRegExp provide quick shortcuts for string escaping. Multilingual support is also enhanced with shortcut methods to Unicode script blocks, such as Kanji (Chinese and Japanese), Hiragana (Japanese), Hangul (Korean), Greek, Hebrew, and more. 

// sugar gives the Date class much love starting with the Date.create method which can understand dates in just about any format in 15 major languages, including relative formats like "1 hour ago".

// I create one sample project in appcelerator and i really happy to use this file .

And that project is available on Git. :)

https://github.com/dharmik/use-of-sugar.js-file

Helpful Link : )

sugarjs.com

 I hope this code helps you and solve your some problems. :)


Tuesday 1 October 2013

How to check the valid Youtube URL ?

// Here, The simple way to valid YouTube url in Appcelerator.

// Typically, the thing that most people want is the youtube video ID valid or not. 

// Some one also check that front part youtube.com/ that one very easy in appcelerator.

Here , some code

 var _videoUrl = "youtube.com/watch?v=FhnMNwiGg5M";
 var _videoUrlNotValid = "go.com/watch?v=FhnMNwiGg5M";

var matches = _videoUrl.match(/((http|https):\/\/)?(www\.)?(youtube\.com)(\/)?([a-zA-Z0-9\-\.]+\/?/);

var matches = _videoUrlNotValid.match(/((http|https):\/\/)?(www\.)?(youtube\.com)(\/)?([a-zA-Z0-9\-\.]+)\/?/);

  if (matches) {
        alert('valid youtube URL');
    }else{
        alert('Not valid');
    }

Output :)

1) _videoUrl is valid
2) _videoUrlNotValid not valid

Hope it helps you , i use this in Appcelerator and it works for me.