<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>mim.Armand &#187; Javascript</title>
	<atom:link href="http://armand.eu/blog/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://armand.eu/blog</link>
	<description>Artist, inventor and developer!</description>
	<lastBuildDate>Wed, 24 Jun 2015 12:02:08 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.2.2</generator>
	<item>
		<title>Using Objects like Arrays in JavaScript.</title>
		<link>http://armand.eu/blog/how-to-use-objects-like-arrays-in-javascript/</link>
		<comments>http://armand.eu/blog/how-to-use-objects-like-arrays-in-javascript/#comments</comments>
		<pubDate>Thu, 17 Jul 2014 22:06:38 +0000</pubDate>
		<dc:creator><![CDATA[mim]]></dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[Functions]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Keys]]></category>
		<category><![CDATA[Length]]></category>
		<category><![CDATA[Object]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://armand.eu/blog/?p=79</guid>
		<description><![CDATA[In some situations, there can be a lot of advantages of using Objects instead of Arrays in JavaScript. But some of programmers just don&#8217;t like objects! Here I don&#8217;t want to enter this debate about why or what! I just want to show you how to use a JavaScript Object like an Array! So one &#8230; <a href="http://armand.eu/blog/how-to-use-objects-like-arrays-in-javascript/" class="more-link">Continue reading <span class="screen-reader-text">Using Objects like Arrays in JavaScript.</span> <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>In some situations, there can be a lot of advantages of using Objects instead of Arrays in JavaScript.<br />
But some of programmers just don&#8217;t like objects! Here I don&#8217;t want to enter this debate about why or what! I just want to show you how to use a JavaScript Object like an Array!</p>
<p>So one of the very useful methods of Arrays (in JavaScript! otherwise it&#8217;s just the opposite side let&#8217;s say in Java for example!) is that you can get and set the length of any array any-time you want! then you can iterate between items inside the array and do literally any thing you want (you can do this because you know the length!).</p>
<p>And you can do the exact (well in pragmatic point of view) same thing in new versions of JavaScript with Objects too! using the Keys function:</p>
<pre class="syntaxbox  language-html" data-prism-prevent-line-number="1"><code class=" language-javascript">Object.keys(obj);
</code></pre>
<p>But you should know that: first of all this wasn&#8217;t there in older versions of JavaScript (So your code wouldn&#8217;t function properly in old IE browsers for instance) and secondary, in proprietary / customized versions of JavaScript that aren&#8217;t that fast to get up to date with the advances of JavaScript, you won&#8217;t probably have it even in the future! (for example in Adobe products they are still using VERY old versions of JS in their VERY modern products), so what can you do about it?</p>
<p>Here is the solution!<br />
If your problem is old browsers / IE, you can use <a title="Add compatible Object.keys support in older environments that do not natively support it." href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys#Polyfill" target="_blank">sophisticated Amazon solution</a> which will make the functionality available in most of the older browsers /IE:<br />
<script src="https://gist.github.com/mim-Armand/fc8c929c0b12d34ed412.js"></script><br />
<small>Please note that you can use this function in other environments as well, but it would be a little bit over-kill since in embedded systems for example you may know most of the times the version of JavaScript and if it&#8217;s available or not so you don&#8217;t need to and probably shouldn&#8217;t check it!</small></p>
<p>And for the environments, where you know that uses an older version of JavaScript and/or this function doesn&#8217;t exist, you can write a very simple function yourself that will tell you the length of the object properties and the key values (since knowing only the length won&#8217;t help you, since you can&#8217;t access properties by index!) like so:</p>
<p><script src="https://gist.github.com/mim-Armand/f7f1015d040969b52b82.js"></script><br />
<small>Here by passing an object to this function you will get back an array of Object property keys and of-course you can get the length from it like a simple array as well!</small></p>
<p>As you see it is a super simple and very short function!</p>
<p>See you later, mim, <img src="http://s.w.org/images/core/emoji/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
]]></content:encoded>
			<wfw:commentRss>http://armand.eu/blog/how-to-use-objects-like-arrays-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>manage paths in Adobe Extend-Script</title>
		<link>http://armand.eu/blog/manage-paths-in-adobe-extend-script/</link>
		<comments>http://armand.eu/blog/manage-paths-in-adobe-extend-script/#comments</comments>
		<pubDate>Wed, 25 Jun 2014 18:45:45 +0000</pubDate>
		<dc:creator><![CDATA[mim]]></dc:creator>
				<category><![CDATA[Adobe ExtendScript]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[Absolute path]]></category>
		<category><![CDATA[Adobe CS]]></category>
		<category><![CDATA[Adobe extend-script]]></category>
		<category><![CDATA[AES]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[InDesign]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Paths]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[Relative path]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://armand.eu/blog/?p=62</guid>
		<description><![CDATA[Managing paths obtained from Adobe Extend-Script, Specially when you want to share these paths with an external 3th application (to do things which aren&#8217;t possible with just ExtendScript) is kind of difficult! For instance let&#8217;s say we want to get the Path of an In-Design file being opened (and in front) in in-Design, we may &#8230; <a href="http://armand.eu/blog/manage-paths-in-adobe-extend-script/" class="more-link">Continue reading <span class="screen-reader-text">manage paths in Adobe Extend-Script</span> <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<figure id="attachment_66" style="width: 674px;" class="wp-caption aligncenter"><a href="http://armand.eu/blog/wp-content/uploads/2014/06/Header_cs_sdk_brnd_ex.jpg"><img class="size-full wp-image-66" src="http://armand.eu/blog/wp-content/uploads/2014/06/Header_cs_sdk_brnd_ex.jpg" alt="Adobe Exten-Script (source: internet)" width="674" height="208" /></a><figcaption class="wp-caption-text">Adobe Exten-Script (source: internet)</figcaption></figure>
<p>Managing paths obtained from Adobe Extend-Script, Specially when you want to share these paths with an external 3th application (to do things which aren&#8217;t possible with just ExtendScript) is kind of difficult!<br />
For instance let&#8217;s say we want to get the Path of an In-Design file being opened (and in front) in in-Design, we may simply do:</p>
<p><script src="https://gist.github.com/mim-Armand/10bf1ff8483dc5d7ad5c.js"></script><br />
 And get:</p>
<figure id="attachment_63" style="width: 299px;" class="wp-caption aligncenter"><a href="http://armand.eu/blog/wp-content/uploads/2014/06/AES_path_01.jpg"><img class="size-full wp-image-63" src="http://armand.eu/blog/wp-content/uploads/2014/06/AES_path_01.jpg" alt="alert(app.activeDocument.filePath);" width="299" height="181" /></a><figcaption class="wp-caption-text">alert(app.activeDocument.filePath);</figcaption></figure>
<p>But there is obviously 3 (+1 not obvious here!) possible problems with this path (even if you can transfer that variable as easily as shout it out in an alert! <small>look at #3</small>):</p>
<ol>
<li>the Tilde (<a title="Tilde on Wikipedia!" href="http://en.wikipedia.org/wiki/Tilde" target="_blank"><code>~</code></a>) character at the beginning, an environment variable meaning &#8220;<a title="Home Directory Path" href="http://en.wikipedia.org/wiki/Home_directory" target="_blank">Home Directory</a>&#8220;, which is not a recognizable standard character in all the different programing environments (for instance it&#8217;d be <a title="Batch parameters" href="http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true" target="_blank"><code>%~dp0</code></a> in <a title="Windows Batch Scripting" href="http://en.wikibooks.org/wiki/Windows_Batch_Scripting" target="_blank">Batch scripting</a> and <code><a title="System Properties in Java" href="http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html" target="_blank">user.home</a></code>, (<a title="Bug # 4787391 (mostly Windows Fault than Java!)" href="http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4787931" target="_blank">more or less!</a>) in Java) although it is supposed to be the absolute path using above code!</li>
<li>existence of Slash characters (<a title="Slash character" href="http://en.wikipedia.org/wiki/Slash_%28punctuation%29" target="_blank"><code>/</code></a>) in the path instead of Backslash (<a title="Backslash character" href="http://en.wikipedia.org/wiki/Backslash" target="_blank"><code>\</code></a>), making it hard (not so much tho!) to send it through a <a title="JSON (JavaScript Object Notation)" href="http://json.org/" target="_blank">JSON</a> package for example (or save it in a <a title="Batch File" href="http://en.wikipedia.org/wiki/Batch_file" target="_blank">batch file</a> -again- for instance), be-cause in most environments it&#8217;d be considered as a <a title="Escape characters" href="http://en.wikipedia.org/wiki/Escape_character" target="_blank">escape character</a> and not a path level separator.</li>
<li>It is an object and not a string (apparently!) and you can send, save or sometimes even use the <a title="myPath var in the above Gist" href="https://gist.github.com/mim-Armand/10bf1ff8483dc5d7ad5c#file-aes_path_01-jsx" target="_blank"><code>myPath</code> </a>variable for instance directly! (it will give you an <code>[object]</code> instead of the path, <small>which I <b>guess</b> should be the parent <code>File object</code> itself</small>)</li>
<li>in addition if our file wasn&#8217;t in our Desktop folder and was in a disk drive instead, we would have this problem too:
<figure id="attachment_64" style="width: 164px;" class="wp-caption aligncenter"><a href="http://armand.eu/blog/wp-content/uploads/2014/06/AES_path_02.jpg"><img class="size-full wp-image-64" src="http://armand.eu/blog/wp-content/uploads/2014/06/AES_path_02.jpg" alt="alert(app.activeDocument.filePath);" width="164" height="181" /></a><figcaption class="wp-caption-text">alert(app.activeDocument.filePath);</figcaption></figure>
<p>as you can see, an additional Slash character (<a title="Slash character" href="http://en.wikipedia.org/wiki/Slash_%28punctuation%29" target="_blank"><code>/</code></a>) before the Drive letter (c)! which is incomprehensible to me why it is!! but it seems that Extend-Script itself doesn&#8217;t have any problem with it, but as I said when you want o communicate with 3th party apps it will become a problem immediately!
</li>
<p>    So as you may guess there is a lot of solutions for any and each of mentioned problems, but here I just wanted to suggest the most convenient one I figured out after trying a lot of different shenanigan techniques!<script src="https://gist.github.com/mim-Armand/1124e39b165172f1129e.js"></script><br />
Here we used <a title="Regulra expressions" href="https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions" target="_blank">Regular Expression</a> Patterns to <a title="str.replace(regexp|substr, newSubStr|function[,flags]);" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace" target="_blank"><code>Replace()</code></a> all (by using the <code>g</code> pseudo) the Slashes with Backslashes and by using <a title="Look at the references for fsName!" href="http://www.jongware.com/idjshelp.html" target="_blank"><code>fsName</code> </a>instead of <a title="look at the references for filePath!" href="http://www.jongware.com/idjshelp.html" target="_blank"><code>filePath</code> </a>eliminating other problems (like getting &#8220;relative paths&#8221; (or fake absolutes!) instead of absolutes and the beginning slash character)<br />
And the result:</p>
<figure id="attachment_65" style="width: 398px;" class="wp-caption aligncenter"><a href="http://armand.eu/blog/wp-content/uploads/2014/06/AES_path_03.jpg"><img class="size-full wp-image-65" src="http://armand.eu/blog/wp-content/uploads/2014/06/AES_path_03.jpg" alt="alert(app.activeDocument.fullName.parent.fsName).toString().replace(/\\/g, '/');" width="398" height="180" /></a><figcaption class="wp-caption-text">alert(app.activeDocument.fullName.parent.fsName).toString().replace(/\\/g, &#8216;/&#8217;);</figcaption></figure>
<p>Awesome! <img src="http://s.w.org/images/core/emoji/72x72/1f600.png" alt="😀" class="wp-smiley" style="height: 1em; max-height: 1em;" /><br />
<small>Please let me know if you have a better idea to this or if you see a problem or something, I appreciate it <img src="http://s.w.org/images/core/emoji/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></small><br />
mim,</p>
]]></content:encoded>
			<wfw:commentRss>http://armand.eu/blog/manage-paths-in-adobe-extend-script/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
