Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfmiller committed Apr 10, 2017
1 parent a527098 commit 3dfdec8
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 11 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,31 @@

# rmr-lib

A well-tested library of code for working with internet metadata:

const
RMR = require('rmr-lib'),
mime = RMR.mime.fromPath('script.js')), // 'text/javascript'
ext = RMR.mime.extensionFor('application/json'), // 'json'
isURL = RMR.url.isA('https://google.com'); // true
RMR.meta.retrieve('http://readmeansrun.com').then(function(data) {
/*{
"title": "READMEANSRUN",
"apple-touch-icon": {
"mime": "image/png",
"url": "https://readmeansrun.com/apple-touch-icon.png"
},
"og:title": "READMEANSRUN",
"og:description": "READMEANSRUN makes websites and takes pictures",
"og:image": {
"mime": "image/png",
"url": "https://readmeansrun.com/assets/img/og-image.png"
},
"favicon": {
"mime": "image/x-icon",
"url": "https://readmeansrun.com/favicon.ico"
}
}*/
}).catch(function(err)) {
console.log('🚫', err);
};
38 changes: 31 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const
/**
@param markup {String} - the contents of the HTML document that will be parsed
@param baseURL {String} - (optional) the base URL that should be applied to all relative paths within the document
@param options {Object} - `baseURL` (optional) the base URL that should be applied to all relative paths within the document
*/
const parseMetadata = function(markup, options) {

Expand Down Expand Up @@ -129,8 +129,6 @@ const parseMetadata = function(markup, options) {
// if both icons have been retrieved, resolve
if (Object.keys(addresses).length === 0) { resolve(OBJ); }



async.map(Object.keys(addresses), function(key, callback) {
request.head({
url : addresses[key],
Expand Down Expand Up @@ -159,11 +157,32 @@ const parseMetadata = function(markup, options) {

/**
@param url {String} -
@param options {Object} -
{
"title": "READMEANSRUN",
"apple-touch-icon": {
"mime": "image/png",
"url": "https://readmeansrun.com/apple-touch-icon.png"
},
"og:title": "READMEANSRUN",
"og:description": "READMEANSRUN makes websites and takes pictures",
"og:image": {
"mime": "image/png",
"url": "https://readmeansrun.com/assets/img/og-image.png"
},
"favicon": {
"mime": "image/x-icon",
"url": "https://readmeansrun.com/favicon.ico"
}
}
@param address {String} - the URL whose metadata should be retrieved
@param options {Object} - `baseURL`
*/
const retrieveMetadata = function(address, options) {

var ARGS = arguments;

return new Promise(function(resolve, reject) {

request.head({
Expand Down Expand Up @@ -192,6 +211,12 @@ const retrieveMetadata = function(address, options) {
return;
}

options = ARGS.length == 2 ? options : {
baseURL : response.request.uri.href,
icons : true
};


parseMetadata(body, options ? options : { baseURL : response.request.uri.href, icons : true }).then(function(obj) {
resolve(obj);
}).catch(function(err) {
Expand Down Expand Up @@ -310,7 +335,7 @@ module.exports = {
};


/*

if (require.main === module) {

if (process.argv.length == 3) {
Expand All @@ -323,4 +348,3 @@ if (require.main === module) {
console.log('🚫 No URL provided');
}
}
*/
8 changes: 4 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ describe('RMR.mime', function() {
expect(RMR.mime.extensionFor('application/pdf')).to.equal('pdf');
expect(RMR.mime.extensionFor('text/html')).to.equal('html');
expect(RMR.mime.extensionFor('text/css')).to.equal('css');
expect(RMR.mime.extensionFor('text/javascript')).to.equal('js');

expect(RMR.mime.extensionFor('text/javascript')).to.equal('js');

expect(RMR.mime.extensionFor('application/json')).to.equal('json');

expect(RMR.mime.extensionFor('asdfadsf')).to.equal(null);
});

Expand Down

0 comments on commit 3dfdec8

Please sign in to comment.