npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-cpm

v3.2.0

Published

Computed Propery Macros for Ember.js

Downloads

175

Readme

Ember-CPM

Build Status Ember Observer Score Code Climate Dependency Status devDependency Status Ember Version

Computed Property Macros for Ember

Requirements

Version 2.0+ will only work with Ember 2.0+ Version 3.0+ is only tested in the last 2 LTS.

Installation

Just run ember install ember-cpm

Usage

Just import individual macros from ember-cpm/macros/* or all macros from ember-cpm.

// Import only one macros
import ifNull from "ember-cpm/macros/if-null";
// or alternatively import all the namespace
import EmberCPM from "ember-cpm";

Contributing

To generate a new computed property macros with ember-cli

  • Run ember g macro <dasherized-macro-name>. This will generate a few files
    • ./addon/macros/dasherized-macro-name.js (the macro)
    • ./addon/tests/dummy/unit/macro/dasherized-macro-name-test.js (a test)*
    • and modify ./addon/ember-cpm.js
// import the macro
import camelizedMacroName from './macros/dasherized-macro-name.js'
...

var Macros = {
  ...
  // allows use via EmberCPM.Macros.camelizedMacroName
  camelizedMacroName: camelizedMacroName,
  ...
};

ember d macro <dasherized-macro-name> will do the reverse of these changes

Provided Macros

  • among -- returns true if the original value is among the given literals (testing using ===)
  • encodeURIComponent -- calls encodeURIComponent on the original value
  • encodeURI -- calls encodeURI on the original value
  • firstPresent -- returns the first property with a value, as determined by Ember.isPresent
  • fmt -- pass the original values into a format-string
  • htmlEscape -- escapes the original value with Handlebars.Utils.escapeExpression and wraps the result in a Handlebars.SafeString (since it's now safe)
  • ifNull -- fall back on a default value
  • promise -- wraps the original value in an already-resolved promise
  • safeString -- wraps the original value in a Handlebars.SafeString
  • join -- joins the supplied values together with a provided sepatator
  • quotient -- divides one numeric property or literal by another
  • difference -- subtracts one numeric property or literal from another
  • product -- multiplies numeric properties and literals together
  • sum -- sums numeric properties and literals together
  • conditional -- returns values based on a boolean property (good replacement for ternary operator)
  • computedPromise -- Updates computed property when supplied callback (which must return a promise) is resolved

Composable Computed Property Macros

Unlike Ember's computed property macros, the macros in this addon are composable. That means you define macros inside other macros without defining them in a separate key.

import Ember from 'ember';
import EmberCPM from 'ember-cpm';

const { Macros: { sum, difference, product } } = EmberCPM;

export default Ember.Component.extend({
  num1: 45,
  num2: 3.5,
  num3: 13.4,
  num4: -2,

  total: sum(
    sum('num1', 'num2', 'num3'),
    difference('num3', 'num2'),
    product(difference('num2', 'num1'), 'num4')
  )
});