Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[cleanup] mmhmmm

  • Loading branch information...
commit 20b5b11a34a6cb56695b1adca2eee59937d24d81 1 parent eb5d3ee
Edward Hotchkiss authored
1  .gitignore
View
@@ -1 +0,0 @@
-node_modules/
11 .npmignore
View
@@ -1,11 +0,0 @@
-.git*
-test/
-examples/
-test/
-*.md
-.travis.yml
-LICENSE
-.gitignore
-paige.config
-docs/
-benchmarks/
79 docs/ShortURL.html
View
@@ -1,79 +0,0 @@
-<!DOCTYPE html> <html> <head> <title>ShortURL.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="rocco.css" /> </head> <body> <div id="navbar"> <h3>Short - Node.JS URL Shortener backed by Mongoose.JS w/ Examples<em></em></h3> </div> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="index.html">Index</a> <a class="source" href="ShortURL.html"> ShortURL.js </a> <a class="source" href="short.html"> short.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> ShortURL.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/**</span>
-<span class="cm"> *</span>
-<span class="cm"> * Mongoose Model:</span>
-<span class="cm"> * - ShortURL</span>
-<span class="cm"> *</span>
-<span class="cm"> */</span>
-
-<span class="kd">var</span> <span class="nx">mongoose</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;mongoose&#39;</span><span class="p">)</span>
- <span class="p">,</span> <span class="nx">Schema</span> <span class="o">=</span> <span class="nx">mongoose</span><span class="p">.</span><span class="nx">Schema</span>
- <span class="p">,</span> <span class="nx">ObjectId</span> <span class="o">=</span> <span class="nx">Schema</span><span class="p">.</span><span class="nx">ObjectId</span><span class="p">;</span>
-
-<span class="kd">var</span> <span class="nx">ShortURLSchema</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Schema</span><span class="p">({</span>
- <span class="nx">id</span> <span class="o">:</span> <span class="p">{</span> <span class="nx">type</span> <span class="o">:</span> <span class="nx">ObjectId</span> <span class="p">},</span>
- <span class="nx">URL</span> <span class="o">:</span> <span class="p">{</span> <span class="nx">type</span> <span class="o">:</span> <span class="nb">String</span> <span class="p">},</span>
- <span class="nx">qr</span> <span class="o">:</span> <span class="p">{</span> <span class="nx">type</span> <span class="o">:</span> <span class="nb">String</span> <span class="p">},</span>
- <span class="nx">hash</span> <span class="o">:</span> <span class="p">{</span> <span class="nx">type</span> <span class="o">:</span> <span class="nb">String</span><span class="p">,</span> <span class="nx">unique</span><span class="o">:</span> <span class="kc">true</span> <span class="p">},</span>
- <span class="nx">hits</span> <span class="o">:</span> <span class="p">{</span> <span class="nx">type</span> <span class="o">:</span> <span class="nb">Number</span><span class="p">,</span> <span class="k">default</span><span class="o">:</span> <span class="mi">0</span> <span class="p">},</span>
- <span class="nx">created_at</span> <span class="o">:</span> <span class="p">{</span> <span class="nx">type</span> <span class="o">:</span> <span class="nb">Date</span><span class="p">,</span> <span class="k">default</span><span class="o">:</span> <span class="nb">Date</span><span class="p">.</span><span class="nx">now</span> <span class="p">},</span>
- <span class="nx">uniques</span> <span class="o">:</span> <span class="p">{</span> <span class="nx">type</span> <span class="o">:</span> <span class="nb">Number</span><span class="p">,</span> <span class="k">default</span><span class="o">:</span> <span class="mi">0</span><span class="p">},</span>
- <span class="nx">visitors</span> <span class="o">:</span> <span class="p">{</span> <span class="nx">type</span> <span class="o">:</span> <span class="p">[</span><span class="nb">String</span><span class="p">]}</span>
-<span class="p">});</span>
-
-<span class="kd">var</span> <span class="nx">ShortURL</span> <span class="o">=</span> <span class="nx">mongoose</span><span class="p">.</span><span class="nx">model</span><span class="p">(</span><span class="s1">&#39;ShortURL&#39;</span><span class="p">,</span> <span class="nx">ShortURLSchema</span><span class="p">);</span>
-
-<span class="cm">/**</span>
-<span class="cm"> * @model ShortURL</span>
-<span class="cm"> * @method findByHash</span>
-<span class="cm"> * @param {String} hash</span>
-<span class="cm"> * @param {Function} callback</span>
-<span class="cm"> */</span>
-
-<span class="nx">ShortURL</span><span class="p">.</span><span class="nx">findByHash</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">hash</span><span class="p">,</span> <span class="nx">options</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">options</span><span class="p">.</span><span class="nx">hash</span> <span class="o">=</span> <span class="nx">hash</span><span class="p">;</span>
- <span class="nx">ShortURL</span><span class="p">.</span><span class="nx">findOne</span><span class="p">({</span> <span class="nx">hash</span><span class="o">:</span> <span class="nx">hash</span> <span class="p">},</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">error</span><span class="p">,</span> <span class="nx">URL</span><span class="p">)</span> <span class="p">{</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">callback</span><span class="p">(</span><span class="nx">error</span><span class="p">,</span> <span class="kc">null</span><span class="p">);</span>
- <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">URL</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">ShortURL</span><span class="p">.</span><span class="nx">updateHitsById</span><span class="p">(</span><span class="nx">URL</span><span class="p">,</span> <span class="nx">options</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
- <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
- <span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="kc">null</span><span class="p">);</span>
- <span class="p">}</span>
- <span class="p">}</span>
- <span class="p">});</span>
-<span class="p">};</span>
-
-<span class="cm">/**</span>
-<span class="cm"> * @model ShortURL</span>
-<span class="cm"> * @method updatehitsById</span>
-<span class="cm"> * @param {ObjectId} id</span>
-<span class="cm"> * @param {Function} callback</span>
-<span class="cm">*/</span>
-
-<span class="nx">ShortURL</span><span class="p">.</span><span class="nx">updateHitsById</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">URL</span><span class="p">,</span> <span class="nx">options</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">options</span> <span class="o">&amp;&amp;</span> <span class="nx">options</span><span class="p">.</span><span class="nx">visitor</span> <span class="o">&amp;&amp;</span> <span class="nx">URL</span><span class="p">.</span><span class="nx">visitors</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">visitor</span><span class="p">)</span> <span class="o">===</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">ShortURL</span><span class="p">.</span><span class="nx">update</span><span class="p">({</span><span class="s1">&#39;hash&#39;</span><span class="o">:</span> <span class="nx">options</span><span class="p">.</span><span class="nx">hash</span><span class="p">},</span> <span class="p">{</span>
- <span class="nx">$inc</span><span class="o">:</span> <span class="p">{</span><span class="nx">hits</span><span class="o">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nx">uniques</span><span class="o">:</span> <span class="mi">1</span><span class="p">},</span> <span class="nx">$push</span><span class="o">:</span> <span class="p">{</span><span class="nx">visitors</span><span class="o">:</span> <span class="nx">options</span><span class="p">.</span><span class="nx">visitor</span><span class="p">}},</span> <span class="p">{</span> <span class="nx">multi</span><span class="o">:</span> <span class="kc">true</span><span class="p">},</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">callback</span><span class="p">(</span><span class="nx">error</span><span class="p">,</span> <span class="kc">null</span><span class="p">);</span>
- <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
- <span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">URL</span><span class="p">);</span>
- <span class="p">}</span>
- <span class="p">});</span>
- <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
- <span class="nx">ShortURL</span><span class="p">.</span><span class="nx">update</span><span class="p">({</span><span class="s1">&#39;hash&#39;</span><span class="o">:</span> <span class="nx">options</span><span class="p">.</span><span class="nx">hash</span><span class="p">},</span> <span class="p">{</span> <span class="nx">$inc</span><span class="o">:</span> <span class="p">{</span><span class="nx">hits</span><span class="o">:</span> <span class="mi">1</span><span class="p">}},</span> <span class="p">{</span> <span class="nx">multi</span><span class="o">:</span> <span class="kc">true</span><span class="p">},</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">callback</span><span class="p">(</span><span class="nx">error</span><span class="p">,</span> <span class="kc">null</span><span class="p">);</span>
- <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
- <span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">URL</span><span class="p">);</span>
- <span class="p">}</span>
- <span class="p">});</span>
- <span class="p">}</span>
-<span class="p">};</span>
-
-<span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="nx">ShortURL</span><span class="p">;</span>
-
-<span class="cm">/* EOF */</span>
-
-</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
BIN  docs/bg.png
View
Deleted file not rendered
97 docs/index.html
View
@@ -1,97 +0,0 @@
-<!DOCTYPE html> <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Short</title> <style> body { font-size: 16px; line-height: 24px; background: #fff url("bg.png"); color: #252519; font-family: "Palatino Linotype", "Book Antiqua", Palatino, FreeSerif, serif; padding: 0 0 50px 50px; } div.container { width: 720px; margin: 50px 0 50px 50px; } p { width: 550px; } #documentation p { margin-bottom: 4px; } a, a:visited { padding: 0 2px; text-decoration: none; background: #dbe6f3; color: #3f6fa5; } a:active, a:hover { color: #dbe6f3; background: #3f6fa5; } h1, h2, h3, h4, h5, h6 { margin-top: 40px; width: 550px; line-height: 1.25em; } b.header { font-size: 18px; } span.alias { font-size: 14px; font-style: italic; margin-left: 20px; } table, tr, td { margin: 0; padding: 0; } td { padding: 2px 12px 2px 0; } ul { list-style-type: circle; padding: 0 0 0 20px; } li { width: 500px; margin-bottom: 10px; } code, pre, tt { font-family: Monaco, Consolas, "Lucida Console", monospace; font-size: 12px; line-height: 18px; color: #555529; } pre { font-size: 12px; padding: 2px 0 2px 12px; border-left: 6px solid #aaaa99; margin: 0px 0 30px; } #ribbon { line-height: 0; } #ribbon:hover { background: none; } #ribbon img { position: fixed; top: 0; right: 0; border: 0; z-index: 2; } </style> </head> <body> <a id="ribbon" href="https://github.com/edwardhotchkiss/short"> <img src="https://a248.e.akamai.net/assets.github.com/img/71eeaab9d563c2b3c590319b398dd35683265e85/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677261795f3664366436642e706e67" alt="Fork me on GitHub"></a> <h1>Short</h1> <em>Node.JS URL Shortener backed by Mongoose.JS w/ Examples</em> <h3>Source files:</h3> <ol> <li><a href="ShortURL.html">ShortURL.js</a></li> <li><a href="short.html">short.js</a></li> </ol> <h1>Short <a href="http://travis-ci.org/edwardhotchkiss/short"><img src="https://secure.travis-ci.org/edwardhotchkiss/short.png" alt="Build Status" title="" /></a></h1>
-
-<blockquote>
- <p>NodeJS URL Shortener backed by MongooseJS w/ Examples</p>
-</blockquote>
-
-<h1>Notes migrating to 1.0.0+</h1>
-
-<p>NOTE: If you've used any version of Short before 1.0.0, please note the new API. This is a finalized API &amp; with the previous API structure being incompatible with Short 1.0.0+</p>
-
-<h1>Running Examples</h1>
-
-<pre>
-$ git clone git@github.com:edwardhotchkiss/short.git
-$ cd short/examples/basic
-$ node api.js
-</pre>
-
-<h1>Installation</h1>
-
-<pre>
-$ npm install short
-</pre>
-
-<hr />
-
-<h1>Basic API Usage</h1>
-
-<p>Using short within your own project as an API interface</p>
-
-<pre>
-
-/*!
- Core Modules
- */
-
-var short = require('short')
- , URL = 'http://nodejs.org/';
-
-short.connect('mongodb://localhost/short');
-
-short.connection.on('error', function(error){
- throw new Error(error);
-});
-
-/*!
- Generate a Shortened URL
- Retrieve URL based on Generated Hash
- */
-
-short.generate(URL, function(error, shortURL) {
- if (error) {
- throw new Error(error);
- } else {
- short.retrieve(shortURL.hash, function(error, shortenedURLObject) {
- if (error) {
- throw new Error(error);
- } else {
- console.log('URL:', shortenedURLObject.URL);
- console.log('hash:', shortenedURLObject.hash);
- process.exit(0);
- }
- });
- }
-});
-
-</pre>
-
-<h1>Complete Example with Express</h1>
-
-<p><strong>Please see</strong> https://github.com/thinkroth/shortUrl</p>
-
-<h1>Pull Requests</h1>
-
-<ul>
-<li>fork</li>
-<li>clone</li>
-<li>improve</li>
-<li>pull request</li>
-<li><strong>instant karma!</strong></li>
-</ul>
-
-<h1>Run Tests (git clone)</h1>
-
-<pre>
- bash
-$ git clone git@github.com:edwardhotchkiss/short.git
-$ cd short && npm test
-</pre>
-
-<h1>License (MIT)</h1>
-
-<p>Copyright (c) 2011, Edward Hotchkiss.</p>
-
-<h3>Author: <a href="http://ingklabs.com/">Edward Hotchkiss</a></h3>
-
-<h3>Contributors: <a href="http://github.com/thinkroth/">Kevin Roth</a></h3> </body> </html>
224 docs/rocco.css
View
@@ -1,224 +0,0 @@
-#navbar {
- position: fixed;
- width: 960px;
- height: 34px;
- background: #fff;
- border-bottom: 1px solid #cdcdcd;
- border-right: 1px solid #cdcdcd;
- border-bottom-right-radius: 5px;
- -webkit-border-bottom-right-radius: 5px;
- -moz-border-bottom-right-radius: 5px;
- z-index: 9;
-}
-#navbar a, #navbar a:visited {
- font-weight: normal;
- padding: 0 2px;
- text-decoration: none;
- color: #3f6fa5;
-}
-#navbar a:active, #navbar a:hover {
- text-decoration: underline;
-}
-#navbar h3 {
- top: 0;
- margin: 0;
- padding: 4px 20px;
-}
-#navbar h3 a {
- float: left;
- display: block;
- padding-right: 20px;
-}
-#container {
- padding-top: 20px;
-}
-body {
- background: #fff url("bg.png");
-}
-/*--------------------- Layout and Typography ----------------------------*/
-body {
- font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
- font-size: 15px;
- line-height: 22px;
- color: #252519;
- margin: 0; padding: 0;
-}
-a {
- color: #261a3b;
-}
- a:visited {
- color: #261a3b;
- }
-p {
- margin: 0 0 15px 0;
-}
-h1, h2, h3, h4, h5, h6 {
- margin: 0px 0 15px 0;
-}
- h1 {
- margin-top: 40px;
- }
-#container {
- position: relative;
-}
-#background {
- position: fixed;
- top: 0; left: 525px; right: 0; bottom: 0;
- background: #f5f5ff;
- border-left: 1px solid #e5e5ee;
- z-index: -1;
-}
-#jump_to, #jump_page {
- background: white;
- border-bottom: 1px solid #cdcdcd;
- border-left: 1px solid #cdcdcd;
- border-bottom-left-radius: 5px;
- -webkit-border-bottom-left-radius: 5px;
- -moz-border-radius-bottomleft: 5px;
- cursor: pointer;
- text-align: right;
-}
-#jump_to, #jump_wrapper {
- position: fixed;
- right: 0; top: 0;
- padding: 5px 30px;
-}
- #jump_wrapper {
- padding: 0;
- display: none;
- }
- #jump_to:hover #jump_wrapper {
- display: block;
- }
- #jump_page {
- padding: 5px 0 3px;
- margin: 0 0 25px 25px;
- }
- #jump_page .source {
- display: block;
- padding: 5px 30px;
- text-decoration: none;
- border-top: 1px solid #eee;
- }
- #jump_page .source:hover {
- background: #f5f5ff;
- }
- #jump_page .source:first-child {
- }
-table td {
- border: 0;
- outline: 0;
-}
- td.docs, th.docs {
- max-width: 450px;
- min-width: 450px;
- min-height: 5px;
- padding: 10px 25px 1px 50px;
- overflow-x: hidden;
- vertical-align: top;
- text-align: left;
- }
- .docs pre {
- margin: 15px 0 15px;
- padding-left: 15px;
- }
- .docs p tt, .docs p code {
- background: #f8f8ff;
- border: 1px solid #dedede;
- font-size: 12px;
- padding: 0 0.2em;
- }
- .pilwrap {
- position: relative;
- }
- .pilcrow {
- font: 12px Arial;
- text-decoration: none;
- color: #454545;
- position: absolute;
- top: 3px; left: -20px;
- padding: 1px 2px;
- opacity: 0;
- -webkit-transition: opacity 0.2s linear;
- }
- td.docs:hover .pilcrow {
- opacity: 1;
- }
- td.code, th.code {
- padding: 14px 15px 16px 25px;
- width: 100%;
- vertical-align: top;
- background: #f5f5ff;
- border-left: 1px solid #e5e5ee;
- }
- pre, tt, code {
- font-size: 12px; line-height: 18px;
- font-family: Menlo, Monaco, Consolas, "Lucida Console", monospace;
- margin: 0; padding: 0;
- }
-
-
-/*---------------------- Syntax Highlighting -----------------------------*/
-td.linenos { background-color: #f0f0f0; padding-right: 10px; }
-span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
-body .hll { background-color: #ffffcc }
-body .c { color: #408080; font-style: italic } /* Comment */
-body .err { border: 1px solid #FF0000 } /* Error */
-body .k { color: #954121 } /* Keyword */
-body .o { color: #666666 } /* Operator */
-body .cm { color: #408080; font-style: italic } /* Comment.Multiline */
-body .cp { color: #BC7A00 } /* Comment.Preproc */
-body .c1 { color: #408080; font-style: italic } /* Comment.Single */
-body .cs { color: #408080; font-style: italic } /* Comment.Special */
-body .gd { color: #A00000 } /* Generic.Deleted */
-body .ge { font-style: italic } /* Generic.Emph */
-body .gr { color: #FF0000 } /* Generic.Error */
-body .gh { color: #000080; font-weight: bold } /* Generic.Heading */
-body .gi { color: #00A000 } /* Generic.Inserted */
-body .go { color: #808080 } /* Generic.Output */
-body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
-body .gs { font-weight: bold } /* Generic.Strong */
-body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
-body .gt { color: #0040D0 } /* Generic.Traceback */
-body .kc { color: #954121 } /* Keyword.Constant */
-body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */
-body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */
-body .kp { color: #954121 } /* Keyword.Pseudo */
-body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */
-body .kt { color: #B00040 } /* Keyword.Type */
-body .m { color: #666666 } /* Literal.Number */
-body .s { color: #219161 } /* Literal.String */
-body .na { color: #7D9029 } /* Name.Attribute */
-body .nb { color: #954121 } /* Name.Builtin */
-body .nc { color: #0000FF; font-weight: bold } /* Name.Class */
-body .no { color: #880000 } /* Name.Constant */
-body .nd { color: #AA22FF } /* Name.Decorator */
-body .ni { color: #999999; font-weight: bold } /* Name.Entity */
-body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
-body .nf { color: #0000FF } /* Name.Function */
-body .nl { color: #A0A000 } /* Name.Label */
-body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
-body .nt { color: #954121; font-weight: bold } /* Name.Tag */
-body .nv { color: #19469D } /* Name.Variable */
-body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
-body .w { color: #bbbbbb } /* Text.Whitespace */
-body .mf { color: #666666 } /* Literal.Number.Float */
-body .mh { color: #666666 } /* Literal.Number.Hex */
-body .mi { color: #666666 } /* Literal.Number.Integer */
-body .mo { color: #666666 } /* Literal.Number.Oct */
-body .sb { color: #219161 } /* Literal.String.Backtick */
-body .sc { color: #219161 } /* Literal.String.Char */
-body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */
-body .s2 { color: #219161 } /* Literal.String.Double */
-body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
-body .sh { color: #219161 } /* Literal.String.Heredoc */
-body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
-body .sx { color: #954121 } /* Literal.String.Other */
-body .sr { color: #BB6688 } /* Literal.String.Regex */
-body .s1 { color: #219161 } /* Literal.String.Single */
-body .ss { color: #19469D } /* Literal.String.Symbol */
-body .bp { color: #954121 } /* Name.Builtin.Pseudo */
-body .vc { color: #19469D } /* Name.Variable.Class */
-body .vg { color: #19469D } /* Name.Variable.Global */
-body .vi { color: #19469D } /* Name.Variable.Instance */
-body .il { color: #666666 } /* Literal.Number.Integer.Long */
138 docs/short.html
View
@@ -1,138 +0,0 @@
-<!DOCTYPE html> <html> <head> <title>short.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="rocco.css" /> </head> <body> <div id="navbar"> <h3>Short - Node.JS URL Shortener backed by Mongoose.JS w/ Examples<em></em></h3> </div> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="index.html">Index</a> <a class="source" href="ShortURL.html"> ShortURL.js </a> <a class="source" href="short.html"> short.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> short.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/**</span>
-<span class="cm"> * Core Modules</span>
-<span class="cm"> */</span>
-
-<span class="kd">var</span> <span class="nx">mongoose</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;mongoose&#39;</span><span class="p">)</span>
- <span class="p">,</span> <span class="nx">ShortURL</span><span class="p">;</span>
-
-<span class="cm">/**</span>
-<span class="cm"> * @method hasher</span>
-<span class="cm"> * @param {String} URL URL to be hashed</span>
-<span class="cm"> * @returns {String} hash Base 62 hash representation of the URL</span>
-<span class="cm"> */</span>
-
-<span class="kd">var</span> <span class="nx">hasher</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">hasher</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">URL</span><span class="p">,</span> <span class="nx">length</span><span class="p">)</span> <span class="p">{</span>
- <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">length</span><span class="p">)</span> <span class="nx">length</span> <span class="o">=</span> <span class="mi">6</span><span class="p">;</span>
- <span class="kd">var</span> <span class="nx">AUID</span> <span class="o">=</span> <span class="p">[],</span>
- <span class="nx">CHARS</span> <span class="o">=</span> <span class="s1">&#39;0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&#39;</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">);</span>
- <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">AUID</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">CHARS</span><span class="p">[</span><span class="nb">Math</span><span class="p">.</span><span class="nx">floor</span><span class="p">(</span><span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">()</span><span class="o">*</span><span class="mi">62</span><span class="p">)]);</span>
- <span class="p">}</span>
- <span class="k">return</span> <span class="nx">AUID</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">);</span>
-<span class="p">};</span>
-
-<span class="cm">/**</span>
-<span class="cm"> * @method connect</span>
-<span class="cm"> * @param {String} mongdb Mongo DB String to connect to</span>
-<span class="cm"> */</span>
-
-<span class="kd">var</span> <span class="nx">connect</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">connect</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">mongodb</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">mongoose</span><span class="p">.</span><span class="nx">connect</span><span class="p">(</span><span class="nx">mongodb</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>expose connection object</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">exports</span><span class="p">.</span><span class="nx">connection</span> <span class="o">=</span> <span class="nx">mongoose</span><span class="p">.</span><span class="nx">connection</span><span class="p">;</span>
- <span class="nx">createModel</span><span class="p">();</span>
-<span class="p">};</span>
-
-<span class="cm">/**</span>
-<span class="cm"> * @expose createConnection</span>
-<span class="cm"> * This will create a connection, instead of using the global mongo connection.</span>
-<span class="cm"> */</span>
-
-<span class="nx">exports</span><span class="p">.</span><span class="nx">createConnection</span> <span class="o">=</span> <span class="kd">function</span> <span class="nx">createConnection</span><span class="p">(</span><span class="nx">MongoURI</span><span class="p">)</span> <span class="p">{</span>
- <span class="kd">var</span> <span class="nx">connection</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">connection</span> <span class="o">=</span> <span class="nx">mongoose</span><span class="p">.</span><span class="nx">createConnection</span><span class="p">(</span><span class="nx">MongoURI</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;connection error: &#39;</span> <span class="o">+</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;util&#39;</span><span class="p">).</span><span class="nx">inspect</span><span class="p">(</span><span class="nx">error</span><span class="p">));</span>
- <span class="p">}</span>
- <span class="p">});</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Event when the db is connected</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">connection</span><span class="p">.</span><span class="nx">once</span><span class="p">(</span><span class="s1">&#39;open&#39;</span><span class="p">,</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
- <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;short package opened connection to mongo db: &#39;</span> <span class="o">+</span> <span class="nx">MongoURI</span><span class="p">);</span>
- <span class="p">});</span>
- <span class="nx">createModel</span><span class="p">();</span>
-<span class="p">}</span>
-
-<span class="cm">/**</span>
-<span class="cm"> * @method createModel</span>
-<span class="cm"> * Connect after a connection has been declared</span>
-<span class="cm"> * it is OK if not connected yet, mongoose buffers request</span>
-<span class="cm"> */</span>
-
-<span class="kd">function</span> <span class="nx">createModel</span><span class="p">()</span> <span class="p">{</span>
- <span class="nx">ShortURL</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">ShortURL</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;../models/ShortURL&#39;</span><span class="p">);</span>
-<span class="p">}</span>
-
-<span class="cm">/**</span>
-<span class="cm"> * @method generate</span>
-<span class="cm"> * @param {String} URL URL to create a Short URL of</span>
-<span class="cm"> * @param {Functon} callback Callback to execute on completion</span>
-<span class="cm"> */</span>
-
-<span class="kd">var</span> <span class="nx">generate</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">generate</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">URL</span><span class="p">,</span> <span class="nx">options</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
- <span class="kd">var</span> <span class="nx">hashedURL</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>options takes an optional object literal
-right now it only supports an options.length argument</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">arguments</span><span class="p">.</span><span class="nx">length</span> <span class="o">===</span> <span class="mi">2</span> <span class="o">&amp;&amp;</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">instanceof</span> <span class="nb">Function</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">callback</span> <span class="o">=</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span>
- <span class="nx">hashedURL</span> <span class="o">=</span> <span class="nx">hasher</span><span class="p">(</span><span class="nx">URL</span><span class="p">);</span>
- <span class="p">}</span>
- <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">arguments</span><span class="p">.</span><span class="nx">length</span> <span class="o">===</span> <span class="mi">3</span> <span class="o">&amp;&amp;</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">instanceof</span> <span class="nb">Object</span> <span class="o">&amp;&amp;</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="k">instanceof</span> <span class="nb">Function</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">hashedURL</span> <span class="o">=</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span> <span class="o">?</span> <span class="nx">hasher</span><span class="p">(</span><span class="nx">URL</span><span class="p">,</span> <span class="nx">options</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span> <span class="o">:</span> <span class="nx">hasher</span><span class="p">(</span><span class="nx">URL</span><span class="p">);</span>
- <span class="p">}</span>
- <span class="k">else</span> <span class="p">{</span>
- <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s2">&quot;generate requires a URL and callback function!&quot;</span><span class="p">);</span>
- <span class="p">}</span>
- <span class="kd">var</span> <span class="nx">item</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ShortURL</span><span class="p">({</span>
- <span class="nx">URL</span> <span class="o">:</span> <span class="nx">URL</span><span class="p">,</span>
- <span class="nx">hash</span> <span class="o">:</span> <span class="nx">hashedURL</span>
- <span class="p">});</span>
- <span class="nx">item</span><span class="p">.</span><span class="nx">save</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">error</span><span class="p">,</span> <span class="nx">item</span><span class="p">){</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>tries to save to mongodb, if it exists it retries</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">error</span> <span class="o">&amp;&amp;</span> <span class="nx">error</span><span class="p">.</span><span class="nx">code</span> <span class="o">===</span> <span class="mi">11000</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">hashedURL</span> <span class="o">+</span> <span class="s1">&#39; already exists! retrying!&#39;</span><span class="p">);</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">generate</span><span class="p">(</span><span class="nx">URL</span><span class="p">,</span> <span class="nx">options</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
- <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
- <span class="nx">generate</span><span class="p">(</span><span class="nx">URL</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
- <span class="p">}</span>
- <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
- <span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">item</span><span class="p">);</span>
- <span class="p">}</span>
- <span class="p">});</span>
-<span class="p">}</span>
-
-<span class="cm">/**</span>
-<span class="cm"> * @method retrieve</span>
-<span class="cm"> * @param {String} hash Hashed Base 62 URL to retrieve</span>
-<span class="cm"> * @param {Functon} callback Callback to execute on completion</span>
-<span class="cm"> */</span>
-
-<span class="kd">var</span> <span class="nx">retrieve</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">retrieve</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">hash</span><span class="p">,</span> <span class="nx">options</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">arguments</span><span class="p">.</span><span class="nx">length</span> <span class="o">===</span> <span class="mi">2</span> <span class="o">&amp;&amp;</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">instanceof</span> <span class="nb">Function</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">callback</span> <span class="o">=</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span>
- <span class="nx">options</span> <span class="o">=</span> <span class="p">{};</span>
- <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">arguments</span><span class="p">.</span><span class="nx">length</span> <span class="o">===</span> <span class="mi">3</span> <span class="o">&amp;&amp;</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">instanceof</span> <span class="nb">Object</span> <span class="o">&amp;&amp;</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="k">instanceof</span> <span class="nb">Function</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>options takes an optional object literal
-right now it only supports an options.visitor argument</p> </td> <td class="code"> <div class="highlight"><pre> <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
- <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s2">&quot;retrieve requires a hash and callback function!&quot;</span><span class="p">);</span>
- <span class="p">}</span>
- <span class="nx">ShortURL</span><span class="p">.</span><span class="nx">findByHash</span><span class="p">(</span><span class="nx">hash</span><span class="p">,</span> <span class="nx">options</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">error</span><span class="p">,</span> <span class="nx">shortenedURLObject</span><span class="p">)</span> <span class="p">{</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">callback</span><span class="p">(</span><span class="nx">error</span><span class="p">,</span> <span class="kc">null</span><span class="p">);</span>
- <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">shortenedURLObject</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">shortenedURLObject</span><span class="p">);</span>
- <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
- <span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="kc">null</span><span class="p">);</span>
- <span class="p">}</span>
- <span class="p">});</span>
-<span class="p">};</span>
-
-<span class="cm">/**</span>
-<span class="cm"> * @method list</span>
-<span class="cm"> * @param {Function} callback</span>
-<span class="cm"> * List all Shortened URLs</span>
-<span class="cm"> */</span>
-
-<span class="kd">var</span> <span class="nx">list</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">list</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">ShortURL</span><span class="p">.</span><span class="nx">find</span><span class="p">({},</span> <span class="kd">function</span><span class="p">(</span><span class="nx">error</span><span class="p">,</span> <span class="nx">urls</span><span class="p">)</span> <span class="p">{</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">callback</span><span class="p">(</span><span class="nx">error</span><span class="p">,</span> <span class="kc">null</span><span class="p">);</span>
- <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
- <span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">urls</span><span class="p">);</span>
- <span class="p">}</span>
- <span class="p">});</span>
-<span class="p">};</span>
-
-<span class="cm">/* EOF */</span>
-
-</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
Please sign in to comment.
Something went wrong with that request. Please try again.