JavaScript gopher_parsedir
!No description available for gopher_parsedir. @php.js developers: Please update the function summary text file.
1 2 3 4 56 7 8 9 1011 12 13 14 1516 17 18 19 2021 22 23 24 2526 27 28 29 3031 32 33 34 3536 37 38 39 4041 42 43 44 4546 47 48 49 5051 52 53 54 5556 57 58 59 6061 62 63 64 6566 67 68 69 7071 72 73 74 | function gopher_parsedir (dirent) { // !No description available for gopher_parsedir. @php.js developers: Please update the function summary text file. // // version: 1109.2015 // discuss at: http://phpjs.org/functions/gopher_parsedir // + original by: Brett Zamir (http://brett-zamir.me) // * example 1: var entry = gopher_parsedir('0All about my gopher site.\t/allabout.txt\tgopher.example.com\t70\u000d\u000a'); // * example 1: entry.title; // * returns 1: 'All about my gopher site.' /* Types * 0 = plain text file * 1 = directory menu listing * 2 = CSO search query * 3 = error message * 4 = BinHex encoded text file * 5 = binary archive file * 6 = UUEncoded text file * 7 = search engine query * 8 = telnet session pointer * 9 = binary file * g = Graphics file format, primarily a GIF file * h = HTML file * i = informational message * s = Audio file format, primarily a WAV file */ var entryPattern = /^(.)(.*?)\t(.*?)\t(.*?)\t(.*?)\u000d\u000a$/; var entry = dirent.match(entryPattern); if (entry === null) { throw 'Could not parse the directory entry'; // return false; } var type = entry[1]; switch (type) { case 'i': type = 255; // GOPHER_INFO break; case '1': type = 1; // GOPHER_DIRECTORY break; case '0': type = 0; // GOPHER_DOCUMENT break; case '4': type = 4; // GOPHER_BINHEX break; case '5': type = 5; // GOPHER_DOSBINARY break; case '6': type = 6; // GOPHER_UUENCODED break; case '9': type = 9; // GOPHER_BINARY break; case 'h': type = 254; // GOPHER_HTTP break; default: return { type: -1, data: dirent }; // GOPHER_UNKNOWN } return { type: type, title: entry[2], path: entry[3], host: entry[4], port: entry[5] }; } |
Examples
Running
1 2 | var entry = gopher_parsedir('0All about my gopher site.\t/allabout.txt\tgopher.example.com\t70\u000d\u000a'); entry.title; |
Should return
1 | 'All about my gopher site.' |
Dependencies
No dependencies, you can use this function standalone.
Open syntax issues
php.js uses JsLint to help us keep our code consistent and prevent some common bugs.
Eventually we want all code to pass or at least take into consideration most fixes suggested by JsLint, following this JsLint configuration we’ve decided on.
Authors
Thanks to the following developers, you get to have gopher_parsedir goodness in JavaScript.
No comments yet. Be the first!
spread the word:
Use any PHP function in JavaScript
These kind folks have already donated: AYHAN BARI*, Nikita Ekshiyan, Nikita Ekshiyan, Petr Pavel, @HalfWinter, Paulo Freitas, Andros Peña Romo, @andorosu, Raimund Szabo, Nitin Gupta, @nikosdion, Anonymous, Anonymous and Shawn Houser.
<your name here>