fQuery

file selection and processing for Node.js

Advertisement
0.11.0

Documentation is a work in progress... find fQuery at npm and GitHub. Currently there are two build tools included: makejs and wepp which was a separate tool before version 0.10.0.

Getting started

First require fQuery:

var fQuery = require('fquery');

or if you prefer a shorter notation:

var $ = require('fquery');

example usage

fQuery

A fQuery object is an array-like object of Blobs. It has a property length and the associated indeces are referencing the Blobs. You can create fQuery objects only through the main factory function fQuery().

A Blob stores information about a file, that might be real or virtual, with readable or binary content.

Core

fQuery()

// select files and read their content
fQuery(selector: String): fQuery
fQuery(blob: Blob): fQuery
fQuery(selector1: String, selector2: String, blob1: Blob, ...): fQuery
fQuery( [ selector1: String, selector2: String, blob1: Blob, ... ] ): fQuery
 
// select a specific file
fQuery('a.txt')
fQuery('folder/b.js')
fQuery('/home/user/README.txt')
 
// select with globstar notation
fQuery('src/css/*.less')
fQuery('src/js/**/*.js')
 
// multiple selections are separated by ','
fQuery('folder/*.txt, assets/**/*')
 
// a group of multiple selections may share a common prefix separated by a ':'
fQuery('folder/src: *.js, *.html')
 
// multiple groups are separated by ';'
fQuery('folder/src: *.js, *.html; other/project: *.html, *.js, **/*.txt')

fQuery.uid()

// returns a unique ID
fQuery.uid(): int

fQuery.plugin()

// register a plugin
fQuery.plugin(module: String)
fQuery.plugin(obj: Object)
fQuery.plugin(fn(fQuery): Function)

fQuery.selectBlob()

fQuery.virtualBlob()

.pushStack()

// push blops onto the stack
fquery.pushStack([blob1: Blob, blob2: Blob, ...]): fQuery
fquery.pushStack(blob: Blob): fQuery

.end()

// pop the stack
fquery.end(): fQuery

.get()

// get the nth blob, might be negative to count backwards
fquery.get(idx: int): Blob
fquery.get(): Array[Blob]

.each()

// iterate over all blobs
fquery.each( callback(blob, idx, fquery) ): fQuery

.edit()

// iterate over clones of all blobs and push them on the stack afterwards
fquery.each( callback(blob, idx, fquery) ): fQuery

.toString()

// returns a string representing this fQuery instance
// optionally set the max count of displayed lines per blob and the max line length
fquery.toString(): String
fquery.toString(lines: int, len: int): String

.log()

// writes a string representation of this fQuery instance to stdout
// optionally set the max count of displayed lines per blob and the max line length
fquery.log(): fQuery
fquery.log(lines: int, len: int): fQuery

Content

.content()

// returns the concatenated content of all blobs
fquery.content(): String
fquery.content(sep: String): String

.concat()

// concats the content of all blobs and puts it as a new blob on top of the stack
fquery.concat(): fQuery
fquery.concat(sep: String): fQuery

.wrap()

// wraps the content of each blob, puts the new blobs onto the stack
fquery.wrap(prepend: String, append: String): fQuery

.replace()

// replaces matched parts of the content of each blob, puts the new blobs onto the stack
fquery.replace([ [selection: String/RegExp, replacement: String], [.. , ..], ... ]): fQuery

Filter

.eq()

// selects the nth blob and puts it on top of the stack, idx might be negative to count backwards
fquery.eq(idx: int): fQuery

.first()

// selects the first blob and puts it on top of the stack
fquery.first(): fQuery

.last()

// selects the last blob and puts it on top of the stack
fquery.last(): fQuery

.not()

.add()

.oldest()

.newest()

.newerThan()

File System

!! Besides read you should be really careful with these methods since they write to your file system !!

.read()

// rereads the blob's content from the source
fquery.read(): fQuery

.remove()

// deletes the source file!
fquery.remove(): fQuery

.write()

// writes the blob's content to a file!
fquery.write( callback(blob: Blob, idx: int, fquery: fQuery): String ): fQuery
 
// if only one blob is selected
fquery.write(target: String): fQuery

.move()

// moves the blob's source file!
fquery.move( callback(blob: Blob, idx: int, fquery: fQuery): String ): fQuery
 
// if only one blob is selected
fquery.move(target: String): fQuery

.copy()

// copies the blob's source file!
fquery.copy( callback(blob: Blob, idx: int, fquery: fQuery): String ): fQuery
 
// if only one blob is selected
fquery.copy(target: String): fQuery

fQuery.OVERWRITE

// to make it a bit more safe you have pass in this object
// as first argument to overwrite existing files, e.g.
fquery.write(fQuery.OVERWRITE, target: String): fQuery
fquery.move(fQuery.OVERWRITE, target: String): fQuery
fquery.copy(fQuery.OVERWRITE, target: String): fQuery

Plugins

.cleancss()

clean-css · a well tested node.js CSS minifier

.cssmin()

cssmin · the Yahoo! CSS Compressor (YUI Compressor)

.handlebars()

Handlebars.js · minimal templating on steroids

.includify()

includify · include file content into JavaScript files

.jade()

Jade · template engine

.jshint()

JSHint · a JavaScript code quality tool

.less()

LESS · the dynamic stylesheet language

.mustache()

{‍{ mustache }} · logic-less templates

.uglifyjs()

UglifyJS · JavaScript minification

Blob

Blobs are the entities fQuery is all about. If you want to manipulate the blobs itself this section will be useful.

Properties

.source

.content

.buffer

.timestamp

.stats

Methods

.isFile()

.isDirectory()

.isVirtual()

.read()

.remove()

.write()

.move()

.copy()

.toString()

.log()

License

fQuery is provided under the terms of the MIT License.