Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An example of custom function for node-sass #24

Open
ajhsu opened this issue Oct 16, 2017 · 0 comments
Open

An example of custom function for node-sass #24

ajhsu opened this issue Oct 16, 2017 · 0 comments

Comments

@ajhsu
Copy link
Owner

ajhsu commented Oct 16, 2017

const nodeSass = require('node-sass');

console.log(
  nodeSass.renderSync({
    data: '#{headings(2,5)} { color: #08c; }',
    functions: {
      // 0 and 6 are default values
      'headings($from: 0, $to: 6)': function(from, to) {
        console.log(from.getValue(), to.getValue())
        var i,
          f = from.getValue(),
          t = to.getValue(),
          list = new nodeSass.types.List(t - f + 1);

        for (i = f; i <= t; i++) {
          list.setValue(i - f, new nodeSass.types.String('h' + i));
        }

        return list;
      }
    }
  }).css.toString()
);

// Will gives you:
// h2, h3, h4, h5 { color: #08c; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant