Giter VIP home page Giter VIP logo

Comments (6)

anandthakker avatar anandthakker commented on August 10, 2024 1

@dominikwilkowski There are a couple of ways:

  1. streaming (take note of the first require--doiuse/stream)
var fs = require('fs')
var doiuse = require('doiuse/stream');

fs.createReadStream('/path/to/your/file.css')
  .pipe(doiuse(['ie >= 8', '> 1%']))
  .on('data', function(usageInfo) {
     console.log(usageInfo.message)
   }
  1. as a postcss plugin
var fs= require('fs')
var postcss = require('postcss')
var doiuse = require('doiuse')

postcss(doiuse({
    browsers:['ie >= 6', '> 1%'],
    onFeatureUsage: function(usageInfo) {
        console.log(usageInfo.message);
    }
}))
.process(fs.readFileSync('/path/to/your.css')

from doiuse.

dominikwilkowski avatar dominikwilkowski commented on August 10, 2024

great! Thanks.

from doiuse.

anandthakker avatar anandthakker commented on August 10, 2024

No problem!

I'm gonna reopen this till I get a chance to add this to the readme.

from doiuse.

dominikwilkowski avatar dominikwilkowski commented on August 10, 2024

No worries...

In that case I might as well keep asking things ;)

var fs = require('fs');
var doiuse = require('doiuse');

var sourceFile = 'test/fixtures/backgrounds.css';
var OPTIONS = [];
OPTIONS.browsers = [ '> 1%', 'last 2 versions', 'Firefox ESR', 'Opera 12.1' ];

fs
    .createReadStream( sourceFile )
    .pipe( doiuse( OPTIONS.browsers ) )
    .on('data', function( usageInfo ) {
        console.log(usageInfo.message)
    });

This returns:

$ node test.js
_stream_readable.js:495
  dest.on('unpipe', onunpipe);
       ^
TypeError: undefined is not a function
    at ReadStream.Readable.pipe (_stream_readable.js:495:8)
    at Object.<anonymous> (/Users/dominikwilkowski/Sites/grunt-doiuse/test.js:10:3)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

ps I am running Node v0.12.0...

Appreciate the help.

from doiuse.

anandthakker avatar anandthakker commented on August 10, 2024

No problem. I think the issue here is in your second line. It should be:

var doiuse = require('doiuse/stream');

(doiuse is the postcss plugin, doiuse/stream is a more standalone
stream api)

from doiuse.

dominikwilkowski avatar dominikwilkowski commented on August 10, 2024

that did it! awesome

from doiuse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.