diff --git a/package.json b/package.json new file mode 100644 index 0000000..96e0f8e --- /dev/null +++ b/package.json @@ -0,0 +1,25 @@ +{ + "name": "gradient-parser", + "version": "0.0.0", + "description": "Parse gradient definitions and return AST.", + "main": "./parser.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://github.com/rafaelcaricio/gradient-parser.git" + }, + "keywords": [ + "parser", + "gradient", + "css", + "ast" + ], + "author": "Rafael Caricio ", + "license": "MIT", + "bugs": { + "url": "https://github.com/rafaelcaricio/gradient-parser/issues" + }, + "homepage": "https://github.com/rafaelcaricio/gradient-parser" +} diff --git a/parser.js b/parser.js new file mode 100644 index 0000000..bd6cb86 --- /dev/null +++ b/parser.js @@ -0,0 +1,65 @@ +// Copyright (c) 2014 Rafael Caricio. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +var Parser = (function() { + + var types = { + gradients: [ + 'linear-gradient', + 'radial-gradient', + 'repeating-radial-gradient' + ], + colors: [ + 'hex', + 'rgb', + 'rgba', + 'hsl', + 'literal' + ] + }; + + function Constructor() { + } + + Constructor.prototype.parse = function(input) { + return null; + } + + return Constructor; +})(); + + +var p = new Parser('linear-gradient(to right, transparent 10px, #c2c2c2 10px)'); +var ast = p.parse(); + +if (ast == [ + { + type: 'linear-gradient', + orientation: { + type: 'directional', + value: 'right' + }, + colorStops: [ + { + type: 'literal', + value: 'transparent', + length: { + value: '10', + type: 'px' + } + }, + { + type: 'hex', + value: 'c2c2c2', + length: { + value: '10', + type: 'px' + } + } + ] + }]) { + console.log('Done!'); +} else { + console.log('Keep working...'); +}