Socket
Socket
Sign inDemoInstall

pug-uses-variables

Package Overview
Dependencies
52
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pug-uses-variables

Extract variables from pug template


Version published
Maintainers
1
Install size
4.70 MB
Created

Readme

Source

pug-uses-variables circleci

Find all JavaScript variables used in pug template.

Usage

$ npm install --save pug-uses-variables
const { findVariablesInTemplate } = require('pug-uses-variables')

const pugTemplate = `

  ReactComponent(property=object[item])
    = content

    if condition === matcher
      p Truthy

`.trimRight()

const variables = findVariablesInTemplate(pugTemplate)
// `variables` is equal:
[{
  value: 'ReactComponent',
  loc: {
    start: { line: 3,  column: 2 },
    end:   { line: 3,  column: 14 }
  }
}, {
  value: 'object',
  loc: {
    start: { line: 3,  column: 24 },
    end:   { line: 3,  column: 30 }
  }
}, {
  value: 'item',
  loc: {
    start: { line: 3,  column: 31 },
    end:   { line: 3,  column: 35 }
  }
}, {
  value: 'content',
  loc: {
    start: { line: 4,  column: 4 },
    end:   { line: 4,  column: 11 }
  }
}, {
  value: 'condition',
  loc: {
    start: { line: 6,  column: 5 },
    end:   { line: 6,  column: 14 }
  }
}, {
  value: 'condition',
  loc: {
    start: { line: 6,  column: 19 },
    end:   { line: 6,  column: 26 }
  }
}]

Important: templates should be right-trimmed. Usually it means that you have to execute .trimRight on your template-string as in the example above.

Get variable names only

const variableNames = variables.map(variable => variable.value)
// > ['ReactComponent', 'object', 'item', 'content', 'condition', 'matcher']

Value

This plugin helps us to integrate babel-plugin-transform-react-pug and eslint.

Development

  • yarn test
  • yarn lint

License

MIT

Keywords

FAQs

Last updated on 18 Jun 2019

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc