script-tags
Advanced tools
Comparing version 0.0.3 to 0.1.0
22
index.js
@@ -8,27 +8,15 @@ /** | ||
var url = require('url'); | ||
var cheerio = require('cheerio'); | ||
var _ = require('lodash'); | ||
module.exports = function(str) { | ||
var attrs = []; | ||
// Use cheerio to extract valuse | ||
var obj = [], attrs = []; | ||
var $ = cheerio.load(str); | ||
// Build an object with useful info for each script tag | ||
$('script').each(function(i, elem) { | ||
attrs[i] = { | ||
id: $(this).attr('id') || '', | ||
async: $(this).attr('async') || '', | ||
language: $(this).attr('language') || '', | ||
defer: $(this).attr('defer') || '', | ||
type: $(this).attr('type') || '', | ||
src: $(this).attr('src') || '', | ||
content: $(this).html(), | ||
obj[i] = { | ||
attrs: elem.attribs, | ||
html: $(this).html() | ||
} | ||
}); | ||
return _.flatten(attrs); | ||
return obj; | ||
}; |
{ | ||
"name": "script-tags", | ||
"version": "0.0.3", | ||
"description": "Utils for HTML script tags. Extracts script tags from HTML and parse them into objects with useful information.", | ||
"version": "0.1.0", | ||
"description": "Parse HTML script tags into JSON.", | ||
"homepage": "https://github.com/jonschlinkert/script-tags", | ||
@@ -28,7 +28,8 @@ "author": { | ||
"devDependencies": { | ||
"fs-utils": "~0.3.6" | ||
"chai": "^1.9.1", | ||
"fs-utils": "^0.4.3", | ||
"verb": "^0.2.10" | ||
}, | ||
"dependencies": { | ||
"lodash": "~2.4.1", | ||
"cheerio": "~0.13.1" | ||
"cheerio": "^0.16.0" | ||
}, | ||
@@ -35,0 +36,0 @@ "keywords": [ |
# script-tags [![NPM version](https://badge.fury.io/js/script-tags.png)](http://badge.fury.io/js/script-tags) | ||
> Extract script tags from HTML and parse them into objects with useful information. | ||
> Parse HTML script tags into JSON. | ||
@@ -18,7 +18,6 @@ ## Install with [npm](npmjs.org): | ||
Returns an object with info for each script tag. See [an example](./test/example.json). | ||
Returns an object with info for each script tag. See [example](./test/example.json). | ||
## Author | ||
**Jon Schlinkert** | ||
@@ -30,3 +29,3 @@ | ||
## License | ||
Copyright (c) 2014 Jon Schlinkert, contributors. | ||
Copyright (c) 2014 Jon Schlinkert, contributors. | ||
Released under the MIT license | ||
@@ -36,2 +35,2 @@ | ||
_This file was generated by Phaser on March 14, 2014._ | ||
_This file was generated by Phaser on May 24, 2014._ |
[ | ||
{ | ||
"id": "", | ||
"async": "", | ||
"language": "", | ||
"defer": "", | ||
"type": "text/javascript", | ||
"src": "", | ||
"content": "\n WebFontConfig = {\n google:\n {\n families: ['Open+Sans+Condensed:300,700:latin', 'Open+Sans:400,300,600,700:latin']\n }\n };\n (function()\n {\n var wf = document.createElement('script');\n wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +\n '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';\n wf.type = 'text/javascript';\n wf.async = 'true';\n var s = document.getElementsByTagName('script')[0];\n s.parentNode.insertBefore(wf, s);\n })();\n " | ||
"attrs": { | ||
"type": "text/javascript", | ||
"data-foo": "test" | ||
}, | ||
"html": "\n WebFontConfig = {\n google:\n {\n families: ['Open+Sans+Condensed:300,700:latin', 'Open+Sans:400,300,600,700:latin']\n }\n };\n (function()\n {\n var wf = document.createElement('script');\n wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +\n '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';\n wf.type = 'text/javascript';\n wf.async = 'true';\n var s = document.getElementsByTagName('script')[0];\n s.parentNode.insertBefore(wf, s);\n })();\n " | ||
}, | ||
{ | ||
"id": "", | ||
"async": "", | ||
"language": "", | ||
"defer": "", | ||
"type": "application/ld+json", | ||
"src": "", | ||
"content": "\n [\n {\n \"@context\": \"http://schema.org\",\n \"@type\": \"Person\",\n \"name\": \"Jon Schlinkert\",\n \"description\": \"Co-creator of Assemble.\",\n \"url\": \"https://github.com/jonschlinkert\"\n },\n {\n \"@context\": \"http://schema.org\",\n \"@type\": \"Person\",\n \"name\": \"Brian Woodward\",\n \"description\": \"Co-creator of Assemble.\",\n \"url\": \"https://github.com/doowb\"\n }]\n " | ||
"attrs": { | ||
"type": "application/ld+json", | ||
"src": "foo/bar/baz.js" | ||
}, | ||
"html": "\n [\n {\n "@context": "http://schema.org",\n "@type": "Person",\n "name": "Jon Schlinkert",\n "description": "Co-creator of Assemble.",\n "url": "https://github.com/jonschlinkert"\n },\n {\n "@context": "http://schema.org",\n "@type": "Person",\n "name": "Brian Woodward",\n "description": "Co-creator of Assemble.",\n "url": "https://github.com/doowb"\n }]\n " | ||
}, | ||
{ | ||
"id": "", | ||
"async": "", | ||
"language": "", | ||
"defer": "", | ||
"type": "", | ||
"src": "https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js", | ||
"content": "" | ||
"attrs": { | ||
"src": "https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" | ||
}, | ||
"html": "" | ||
}, | ||
{ | ||
"id": "", | ||
"async": "", | ||
"language": "", | ||
"defer": "", | ||
"type": "", | ||
"src": "public/js/docs.min.js", | ||
"content": "" | ||
"attrs": { | ||
"src": "public/js/docs.min.js" | ||
}, | ||
"html": "" | ||
}, | ||
{ | ||
"id": "", | ||
"async": "", | ||
"language": "", | ||
"defer": "", | ||
"type": "", | ||
"src": "", | ||
"content": "\n $('.dismiss').click(function()\n {\n $('.navbar-wrap').addClass('fade');\n $('.anchor-target').addClass('anchor-target-small');\n $('.navbar-wrap').delay(1000).hide('fast');\n });\n " | ||
"attrs": {}, | ||
"html": "\n $('.dismiss').click(function()\n {\n $('.navbar-wrap').addClass('fade');\n $('.anchor-target').addClass('anchor-target-small');\n $('.navbar-wrap').delay(1000).hide('fast');\n });\n " | ||
}, | ||
{ | ||
"attrs": { | ||
"type": "text/javascript" | ||
}, | ||
"html": "\n WebFontConfig = {\n google:\n {\n families: ['Open+Sans+Condensed:300,700:latin', 'Open+Sans:400,300,600,700:latin']\n }\n };\n (function()\n {\n var wf = document.createElement('script');\n wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +\n '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';\n wf.type = 'text/javascript';\n wf.async = 'true';\n var s = document.getElementsByTagName('script')[0];\n s.parentNode.insertBefore(wf, s);\n })();\n " | ||
}, | ||
{ | ||
"attrs": { | ||
"type": "application/ld+json" | ||
}, | ||
"html": "\n [\n {\n "@context": "http://schema.org",\n "@type": "Person",\n "name": "Jon Schlinkert",\n "description": "Co-creator of Assemble.",\n "url": "https://github.com/jonschlinkert"\n },\n {\n "@context": "http://schema.org",\n "@type": "Person",\n "name": "Brian Woodward",\n "description": "Co-creator of Assemble.",\n "url": "https://github.com/doowb"\n }]\n " | ||
}, | ||
{ | ||
"attrs": { | ||
"src": "https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" | ||
}, | ||
"html": "" | ||
}, | ||
{ | ||
"attrs": { | ||
"src": "public/js/docs.min.js" | ||
}, | ||
"html": "" | ||
}, | ||
{ | ||
"attrs": {}, | ||
"html": "\n $('.dismiss').click(function()\n {\n $('.navbar-wrap').addClass('fade');\n $('.anchor-target').addClass('anchor-target-small');\n $('.navbar-wrap').delay(1000).hide('fast');\n });\n " | ||
}, | ||
{ | ||
"attrs": { | ||
"type": "text/javascript" | ||
}, | ||
"html": "\n WebFontConfig = {\n google:\n {\n families: ['Open+Sans+Condensed:300,700:latin', 'Open+Sans:400,300,600,700:latin']\n }\n };\n (function()\n {\n var wf = document.createElement('script');\n wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +\n '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';\n wf.type = 'text/javascript';\n wf.async = 'true';\n var s = document.getElementsByTagName('script')[0];\n s.parentNode.insertBefore(wf, s);\n })();\n " | ||
}, | ||
{ | ||
"attrs": { | ||
"type": "application/ld+json" | ||
}, | ||
"html": "\n [\n {\n "@context": "http://schema.org",\n "@type": "Person",\n "name": "Jon Schlinkert",\n "description": "Co-creator of Assemble.",\n "url": "https://github.com/jonschlinkert"\n },\n {\n "@context": "http://schema.org",\n "@type": "Person",\n "name": "Brian Woodward",\n "description": "Co-creator of Assemble.",\n "url": "https://github.com/doowb"\n }]\n " | ||
}, | ||
{ | ||
"attrs": { | ||
"src": "https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" | ||
}, | ||
"html": "" | ||
}, | ||
{ | ||
"attrs": { | ||
"src": "public/js/docs.min.js" | ||
}, | ||
"html": "" | ||
}, | ||
{ | ||
"attrs": {}, | ||
"html": "\n $('.dismiss').click(function()\n {\n $('.navbar-wrap').addClass('fade');\n $('.anchor-target').addClass('anchor-target-small');\n $('.navbar-wrap').delay(1000).hide('fast');\n });\n " | ||
}, | ||
{ | ||
"attrs": { | ||
"type": "text/javascript" | ||
}, | ||
"html": "\n WebFontConfig = {\n google: {\n families: ['Open+Sans+Condensed:300,700:latin', 'Open+Sans:400,300,600,700:latin']\n }\n };\n (function() {\n var wf = document.createElement('script');\n wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +\n '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';\n wf.type = 'text/javascript';\n wf.async = 'true';\n var s = document.getElementsByTagName('script')[0];\n s.parentNode.insertBefore(wf, s);\n })();\n" | ||
}, | ||
{ | ||
"attrs": { | ||
"type": "application/ld+json" | ||
}, | ||
"html": "\n[\n {\n "@context" : "http://schema.org",\n "@type" : "Person",\n "name" : "Jon Schlinkert",\n "description" : "Co-creator of Assemble.",\n "url" : "https://github.com/jonschlinkert"\n },\n {\n "@context" : "http://schema.org",\n "@type" : "Person",\n "name" : "Brian Woodward",\n "description" : "Co-creator of Assemble.",\n "url" : "https://github.com/doowb"\n }\n]\n" | ||
}, | ||
{ | ||
"attrs": { | ||
"src": "https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" | ||
}, | ||
"html": "" | ||
}, | ||
{ | ||
"attrs": { | ||
"src": "public/js/docs.min.js" | ||
}, | ||
"html": "" | ||
}, | ||
{ | ||
"attrs": {}, | ||
"html": "\n $( '.dismiss' ).click(function() {\n $( '.navbar-wrap' ).addClass( 'fade' );\n $( '.anchor-target' ).addClass( 'anchor-target-small' );\n $( '.navbar-wrap' ).delay(1000).hide( 'fast' );\n });\n" | ||
}, | ||
{ | ||
"attrs": { | ||
"type": "text/javascript" | ||
}, | ||
"html": "\n WebFontConfig = {\n google:\n {\n families: ['Open+Sans+Condensed:300,700:latin', 'Open+Sans:400,300,600,700:latin']\n }\n };\n (function()\n {\n var wf = document.createElement('script');\n wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +\n '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';\n wf.type = 'text/javascript';\n wf.async = 'true';\n var s = document.getElementsByTagName('script')[0];\n s.parentNode.insertBefore(wf, s);\n })();\n " | ||
}, | ||
{ | ||
"attrs": { | ||
"type": "application/ld+json" | ||
}, | ||
"html": "\n [\n {\n "@context": "http://schema.org",\n "@type": "Person",\n "name": "Jon Schlinkert",\n "description": "Co-creator of Assemble.",\n "url": "https://github.com/jonschlinkert"\n },\n {\n "@context": "http://schema.org",\n "@type": "Person",\n "name": "Brian Woodward",\n "description": "Co-creator of Assemble.",\n "url": "https://github.com/doowb"\n }]\n " | ||
}, | ||
{ | ||
"attrs": { | ||
"src": "https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" | ||
}, | ||
"html": "" | ||
}, | ||
{ | ||
"attrs": { | ||
"src": "public/js/docs.min.js" | ||
}, | ||
"html": "" | ||
}, | ||
{ | ||
"attrs": {}, | ||
"html": "\n $('.dismiss').click(function()\n {\n $('.navbar-wrap').addClass('fade');\n $('.anchor-target').addClass('anchor-target-small');\n $('.navbar-wrap').delay(1000).hide('fast');\n });\n " | ||
}, | ||
{ | ||
"attrs": { | ||
"type": "text/javascript" | ||
}, | ||
"html": "\n WebFontConfig = {\n google:\n {\n families: ['Open+Sans+Condensed:300,700:latin', 'Open+Sans:400,300,600,700:latin']\n }\n };\n (function()\n {\n var wf = document.createElement('script');\n wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +\n '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';\n wf.type = 'text/javascript';\n wf.async = 'true';\n var s = document.getElementsByTagName('script')[0];\n s.parentNode.insertBefore(wf, s);\n })();\n " | ||
}, | ||
{ | ||
"attrs": { | ||
"type": "application/ld+json" | ||
}, | ||
"html": "\n [\n {\n "@context": "http://schema.org",\n "@type": "Person",\n "name": "Jon Schlinkert",\n "description": "Co-creator of Assemble.",\n "url": "https://github.com/jonschlinkert"\n },\n {\n "@context": "http://schema.org",\n "@type": "Person",\n "name": "Brian Woodward",\n "description": "Co-creator of Assemble.",\n "url": "https://github.com/doowb"\n }]\n " | ||
}, | ||
{ | ||
"attrs": { | ||
"src": "https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" | ||
}, | ||
"html": "" | ||
}, | ||
{ | ||
"attrs": { | ||
"src": "public/js/docs.min.js" | ||
}, | ||
"html": "" | ||
}, | ||
{ | ||
"attrs": {}, | ||
"html": "\n $('.dismiss').click(function()\n {\n $('.navbar-wrap').addClass('fade');\n $('.anchor-target').addClass('anchor-target-small');\n $('.navbar-wrap').delay(1000).hide('fast');\n });\n " | ||
}, | ||
{ | ||
"attrs": { | ||
"data-foo": "bar" | ||
}, | ||
"html": "i" | ||
} | ||
] |
@@ -1,7 +0,3 @@ | ||
/** | ||
* No tests yet. just a placeholder. | ||
*/ | ||
var file = require('fs-utils'); | ||
var _ = require('lodash'); | ||
var fs = require('fs-utils'); | ||
var expect = require('chai').expect; | ||
var scriptTags = require('../'); | ||
@@ -11,13 +7,20 @@ | ||
// Test setup | ||
var fixtures = 'test/fixtures/html/about.html'; | ||
var files = file.expand(fixtures, {filter: 'isFile'}); | ||
var fixtures = 'test/fixtures/html/*.html'; | ||
var files = fs.expand(fixtures, {filter: 'isFile'}); | ||
var scripts = _.flatten(files.map(function(filepath) { | ||
var content = file.readFileSync(filepath); | ||
return scriptTags(content); | ||
})); | ||
var scripts = []; | ||
files.forEach(function(filepath) { | ||
var content = fs.readFileSync(filepath); | ||
scripts = scripts.concat(scriptTags(content)); | ||
}); | ||
console.log(JSON.stringify(scripts, null, 2)); | ||
file.writeFileSync('test/example.json', JSON.stringify(scripts, null, 2)); | ||
// Write example file | ||
fs.writeFileSync('test/example.json', JSON.stringify(scripts, null, 2)); | ||
describe('script-tags:', function () { | ||
it('should extract the attributes and inner html of each script tag.', function () { | ||
expect(scripts.length).to.be.above(1); | ||
expect(scripts[0]).to.have.property('attrs'); | ||
expect(scripts[0]).to.have.property('html'); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1
261469
3
18
249
33
1
+ Addedcheerio@0.16.0(transitive)
+ Addeddom-serializer@0.2.2(transitive)
+ Addeddomelementtype@2.3.0(transitive)
+ Addeddomutils@1.5.1(transitive)
+ Addedentities@1.0.01.1.22.2.0(transitive)
+ Addedhtmlparser2@3.7.3(transitive)
- Removedlodash@~2.4.1
- Removedcheerio@0.13.1(transitive)
- Removeddomutils@1.3.0(transitive)
- Removedentities@0.5.0(transitive)
- Removedhtmlparser2@3.4.0(transitive)
- Removedunderscore@1.5.2(transitive)
Updatedcheerio@^0.16.0