Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/codeeshop-oc/get-script-tag
Get script tags and attributes from String
https://github.com/codeeshop-oc/get-script-tag
javascript js mjs npm npm-package
Last synced: about 9 hours ago
JSON representation
Get script tags and attributes from String
- Host: GitHub
- URL: https://github.com/codeeshop-oc/get-script-tag
- Owner: codeeshop-oc
- License: mit
- Created: 2022-03-04T08:21:38.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-13T10:23:25.000Z (about 1 year ago)
- Last Synced: 2024-11-12T08:35:38.932Z (3 days ago)
- Topics: javascript, js, mjs, npm, npm-package
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/get-script-tag
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Get Script Tag
> Get script tags and attributes from String.
[![Latest Stable Version](https://img.shields.io/npm/v/get-script-tag.svg)](https://www.npmjs.com/package/get-script-tag) [![Total Downloads](https://img.shields.io/npm/dt/get-script-tag.svg)](https://npm-stat.com/charts.html?package=get-script-tag)
[![license](https://img.shields.io/badge/license-MIT-green)](https://github.com/codeeshop-oc/get-script-tag/blob/main/LICENSE)
[![PRs welcome](https://img.shields.io/badge/PRs-welcome-ff69b4.svg)](https://github.com/codeeshop-oc/get-script-tag/issues?&q=is%3Aissue+is%3Aopen)
![Downloads Monthly](https://img.shields.io/npm/dm/get-script-tag.svg)## Installation
via npm
```bash
npm install get-script-tag
```via yarn
```bash
yarn add get-script-tag
```via pnpm
```bash
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
```javascript
const GetStringTag = require('get-script-tag')
let htmlStr = `You have the Script Tags
`// 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