Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-embed-json

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-embed-json - npm Package Compare versions

Comparing version 1.0.0 to 1.2.0

6

CHANGELOG.md

@@ -0,2 +1,8 @@

# 1.2.0
* [#4: Add pre-commit hooks.](https://github.com/haensl/gulp-embed-json/issues/4)
# 1.1.0
* [#2: Add option to minify.](https://github.com/haensl/gulp-embed-json/issues/2)
# 1.0.0
* Initial project release.

15

index.js

@@ -13,2 +13,3 @@ const through = require('through2');

root: __dirname,
minify: true,
encoding: 'utf8'

@@ -44,2 +45,6 @@ };

if (typeof options.minify !== 'boolean') {
return callback(new gutil.PluginError(PLUGIN_NAME, 'Invalid option: minify must be a boolean.'));
}
if (typeof options.encoding !== 'string') {

@@ -64,6 +69,8 @@ return callback(new gutil.PluginError(PLUGIN_NAME, 'Invalid option: encoding must be a string.'));

const jsonData = fs.readFileSync(absSrc, options.encoding);
el.empty()
.text(jsonData)
.attr('src', null);
didEmbed = true;
if (jsonData.length) {
el.empty()
.text(options.minify ? JSON.stringify(JSON.parse(jsonData)) : jsonData)
.attr('src', null);
didEmbed = true;
}
} catch(err) {

@@ -70,0 +77,0 @@ error = new gutil.PluginError(PLUGIN_NAME, err);

{
"name": "gulp-embed-json",
"version": "1.0.0",
"version": "1.2.0",
"description": "Gulp plugin to inline/embed JSON data into HTML files.",

@@ -9,3 +9,4 @@ "main": "index.js",

"tdd": "mocha --watch",
"lint": "eslint ./**/*.js"
"lint": "eslint ./**/*.js",
"prepush": "npm-run-all lint test"
},

@@ -47,4 +48,6 @@ "engines": {

"gulp": "^3.9.1",
"mocha": "^4.0.1"
"husky": "^0.14.3",
"mocha": "^4.0.1",
"npm-run-all": "^4.1.2"
}
}

@@ -51,2 +51,11 @@ # gulp-embed-json

structured-data.json
```json
{
"@context": "http://schema.org",
"@type": "SoftwareApplication",
"name": "gulp-embed-json"
}
```
Gulp task

@@ -73,3 +82,3 @@ ```javascript

<script type="application/json" src="data.json"></script>
<script type="application/ld+json"><!-- contents of structured-data.json --></script>
<script type="application/ld+json">{"@context":"http://schema.org","@type":"SoftwareApplication","name":"gulp-embed-json"}</script>
<!-- ... -->

@@ -102,2 +111,3 @@ </body>

Folder structure

@@ -127,2 +137,104 @@ ```shell

### minify `boolean`
Indicate whether or not to minify JSON data.
#### default: `true`
#### Example: Minify
HTML layout
```html
<html>
<head><!-- ... --></head>
<body>
<!-- ... -->
<script type="application/json" src="data.json"></script>
<!-- ... -->
</body>
</html>
```
data.json
```json
{
"foo": "bar"
}
```
Gulp task
```javascript
const embedJSON = requrie('gulp-embed-json');
// ...
gulp.task('embedJSON', () =>
gulp.src('*.html')
.pipe(embedJSON({
minify: true // default
}))
.pipe(gulp.dest('dist/')));
```
Output
```html
<html>
<head><!-- ... --></head>
<body>
<!-- ... -->
<script type="application/json">{"foo":"bar"}</script>
<!-- ... -->
</body>
</html>
```
#### Example: Do not Minify
HTML layout
```html
<html>
<head><!-- ... --></head>
<body>
<!-- ... -->
<script type="application/json" src="data.json"></script>
<!-- ... -->
</body>
</html>
```
data.json
```json
{
"foo": "bar"
}
```
Gulp task
```javascript
const embedJSON = requrie('gulp-embed-json');
// ...
gulp.task('embedJSON', () =>
gulp.src('*.html')
.pipe(embedJSON({
minify: false
}))
.pipe(gulp.dest('dist/')));
```
Output
```html
<html>
<head><!-- ... --></head>
<body>
<!-- ... -->
<script type="application/json">{
"foo": "bar"
}</script>
<!-- ... -->
</body>
</html>
```
### encoding `string`

@@ -129,0 +241,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc