New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

brexpressions

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

brexpressions

Grammar and parser for breezy expressions in brackets.

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Brexpressions

Grammar and parser for Breezy's expressions in brackets.

Travis build status

Expressions

Breezy uses expressions as placeholders that will be substituted with the value when rendered. Expression are very similar to JavaScript property lookups and function calls with the tenary operator. A full expression looks like:

path[.to.method] [args... ] [? truthy] [: falsy]

path is either a direct or dot-separated nested property lookup. args can be any number of (whitespace separated) parameters if the result of the path lookup is a function. Each parameter can either be another path or a sinlge- or doublequoted string. The optional truthy and falsy block can be used to change the return value to another value or string.

Examples:

  • Look up the name property:
    • name
  • Look up site and get the title:
    • site.title
  • Get name and call the toUpperCase string method:
    • name.toUpperCase
  • Call the helpers.equal method to check the name against a string:
    • helpers.equal name 'David'
  • Call helpers.equal method and return Yes if it matches (null otherwise):
    • helpers.equal name 'David' ? 'Yes'
  • Call helpers.equal method and return No if it does not match (null otherwise):
    • helpers.equal name 'David' : 'No'
  • Call helpers.equal method and return Yes if and No if it does not match:
    • helpers.equal name 'David' ? 'Yes' : 'No'

helpers.equal simply looks like:

{
  helpers: {
    equal: function(first, second) {
      return first === second;
    }
  }
}

Expressions can be used in Attributes or any other text when wrapped with double curly braces {{}}:

<div show-if="helpers.equal name 'David'">Hi {{name.toUpperCase}} how are you?</div>
<img src="person.png" alt="This person is: {{helpers.equal name 'David' ? 'Dave' : 'I don\'t know'}}">

Note: Dynamically adding attributes like <img {{helpers.equal name 'David' ? 'alt="This is David"'}}> is currently not supported. This can almost always be done in a more HTML-y way, anyway, for example using a custom attribute.

Keywords

FAQs

Package last updated on 28 Jan 2015

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