소스 검색

Initial Commit

master
mort 8 년 전
커밋
24bf4b115f
5개의 변경된 파일177개의 추가작업 그리고 0개의 파일을 삭제
  1. 13
    0
      cli.js
  2. 26
    0
      index.js
  3. 14
    0
      package.json
  4. 39
    0
      readme.md
  5. 85
    0
      test/test.js

+ 13
- 0
cli.js 파일 보기

@@ -0,0 +1,13 @@
#!/usr/bin/env node

var prefix = require("./index.js");

var str = "";

process.stdin.on("data", function(data) {
str += data;
});

process.stdin.on("end", function() {
console.log(prefix(str));
});

+ 26
- 0
index.js 파일 보기

@@ -0,0 +1,26 @@
var regStr = "@prefix\\s+([^;]+);";
var globalRegex = new RegExp(regStr, "g");
var localRegex = new RegExp(regStr);

var prefixes = ["-moz-", "-webkit-", "-o-", "-ms-", ""];

module.exports = function(str) {
var matches = str.match(globalRegex);

if (!matches)
return str;

matches.forEach(function(m) {
var cssProperty = m.match(localRegex)[1];
var res = "";

prefixes.forEach(function(prefix) {
res += prefix+cssProperty+"; ";
});
res = res.substring(0, res.length - 1);

str = str.replace(m, res);
});

return str;
}

+ 14
- 0
package.json 파일 보기

@@ -0,0 +1,14 @@
{
"name": "browser-prefix",
"version": "0.0.0",
"description": "A utility to add browser prefixes to CSS.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Martin Dørum Nygaard",
"license": "MIT",
"bin": {
"browser-prefix": "./cli.js"
}
}

+ 39
- 0
readme.md 파일 보기

@@ -0,0 +1,39 @@
# browser-prefix

This is a simple utility to add browser prefixes to CSS. Its syntax is really simple; just add `@prefix` to the beginning of any line, and it will add all relevant browser prefixes to that line. All prefixes will be on the same line, which means all line numbers will match between your source files and the result.

## Installation

Install with npm:

`npm install browser-prefix`

To install as a command line application:

`npm install -g browser-prefix`

## Usage

### In node.js

```
var prefix = require("browser-prefix");

prefix("@prefix foo: bar;");
//returns '-moz-foo: bar; -webkit-foo: bar; -o-foo: bar; -ms-foo: bar; foo: bar;'
```

### As a CLI application

From stdin:

```
$ echo "@prefix foo: bar" | browser-prefix
# returns '-moz-foo: bar; -webkit-foo: bar; -o-foo: bar; -ms-foo: bar; foo: bar;'
```

From file:

```
$ browser-prefix < infile.css > outfile.css
```

+ 85
- 0
test/test.js 파일 보기

@@ -0,0 +1,85 @@
var assert = require("assert");
var prefix = require("../index.js");

describe("browser-prefix", function() {
it("doesn't mess with things without @prefix", function(done) {
var str = "foo: bar; prefix: none;";

if (str !== prefix(str))
throw "Input string doesn't match output string.";

done();
});

it("manages basic prefixing", function(done) {
assert.equal(
prefix("@prefix foo: bar;"),

"-moz-foo: bar; -webkit-foo: bar; -o-foo: bar; "+
"-ms-foo: bar; foo: bar;"
);

done();
});

it("deals with multiple @prefixes on the same line", function(done) {
assert.equal(
prefix("@prefix foo: bar; @prefix bar: foo;"),

"-moz-foo: bar; -webkit-foo: bar; -o-foo: bar; "+
"-ms-foo: bar; foo: bar; "+
"-moz-bar: foo; -webkit-bar: foo; -o-bar: foo; "+
"-ms-bar: foo; bar: foo;"
);

done();
});

it("deals with multiple @prefixes on separate lines", function(done) {
assert.equal(
prefix(
"@prefix foo: bar;\n"+
"foo: bar;\n"+
"@prefix bar: foo;"
),

"-moz-foo: bar; -webkit-foo: bar; -o-foo: bar; "+
"-ms-foo: bar; foo: bar;\n"+
"foo: bar;\n"+
"-moz-bar: foo; -webkit-bar: foo; -o-bar: foo; "+
"-ms-bar: foo; bar: foo;"
);

done();
});

it("deals with tabs for indentation", function(done) {
assert.equal(
prefix(
"\t\t\t"+
"@prefix foo: bar;"
),

"\t\t\t"+
"-moz-foo: bar; -webkit-foo: bar; -o-foo: bar; "+
"-ms-foo: bar; foo: bar;"
);

done();
});

it("deals with spaces for indentation", function(done) {
assert.equal(
prefix(
" "+
"@prefix foo: bar;"
),

" "+
"-moz-foo: bar; -webkit-foo: bar; -o-foo: bar; "+
"-ms-foo: bar; foo: bar;"
);

done();
});
});

Loading…
취소
저장