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

@boehs/gulp-js-text-inject

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@boehs/gulp-js-text-inject

Fixed version of text-inject

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

gulp-js-text-inject

This is a small Gulp plugin for injecting text files right directly into your .js code as strings.

What is it

The simplest example. JS code:

var template = '@@import template.txt';
var fragment = '@@import src/fragments/fragment.html';
var jsonConfig = '@@import config.json';

...and Gulp task:

var gulp = require('gulp');
var inject = require('gulp-js-text-inject');

gulp.task('js', function() {
    return gulp.src('path/to/your/js/*.js')
        .pipe(inject({
            basepath: 'path/to/your/templates/'
        }))
        .pipe(gulp.dest('path/for/output'));
});

If we use this plugin, the resulting JS will be:

var template = 'Hello World!\n\nHow are you!';
var fragment = '<div>\n   <p>Hello World!</p>\n   <p>How are you!</p>\n</div>';
var template = '{\n   "config": true,\n   "moreConfig": false\n}';

Changing the import pattern

var myLog = Loader.load('myLog.log');

Config to match Loader.load:

var gulp = require('gulp');
var inject = require('gulp-js-html-inject');

gulp.task('js', function() {
    return gulp.src('path/to/your/js/*.js')
        .pipe(inject({
            basepath: 'path/to/your/js/',
            pattern: /Loader.load\(['"]([a-zA-Z0-9\-_.\\/]+)['"]\)/g
        }))
        .pipe(gulp.dest('path/for/output'));
});

Options

OptionTypeDefaultDetails
basepathstring""Base path to look up referenced templates from
patternRegExp/'@@import ([a-zA-Z0-9\-_.\\/]+)'/gPattern to match template references. Should have one capture group that will match template path
relativebooleanfalseResolve templates relative to the file being processed
debugbooleanfalseDisplays some information while working - processed files, found references, injection result

Keywords

FAQs

Package last updated on 28 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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