get-script-tag

0.0.4 • Public • Published

Get Script Tag

Get script tags and attributes from String.

Latest Stable Version Total Downloads license PRs welcome Downloads Monthly

Installation

via npm

npm install get-script-tag

via yarn

yarn add get-script-tag

via pnpm

pnpm add get-script-tag

API

get-script-tag get all the a script tags and its attributes.

require('get-script-tag') returns a Object of the following interface: {getScriptTags: Function, getScriptTag: Function, getScriptAttributes: Function}

htmlString

Any HTML String that you have to fetch script tags from.

Example Usage

const GetStringTag = require('get-script-tag')
let htmlStr = `<p>You have the Script Tags <script type=\"text/javascript\" async=\"async\" src=\"//web.webformscr.com/apps/fc3/build/default-handler.js\" sp-form-id=\"YOUR_ID\"></script></p>`

// Array of All Script Tags
const scripts = GetStringTag.getScriptTags(htmlStr)
console.log(scripts)

// Individual Script Tag with Index
const script = GetStringTag.getScriptTag(htmlStr, 0)
console.log(script, 'Index Script')

// Fetching Script Tag Attributes from All Script Tags
for (var i = scripts.length - 1; i >= 0; i--) {  
  console.log(GetStringTag.getScriptAttributes(scripts[i]))
}

License

MIT

Package Sidebar

Install

npm i get-script-tag

Weekly Downloads

9

Version

0.0.4

License

MIT

Unpacked Size

4.42 kB

Total Files

4

Last publish

Collaborators

  • codeeshop