Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tjcafferkey committed Jul 6, 2017
1 parent 72045c1 commit 90fc173
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib
node_modules
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/
node_modules/
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
# stylerjs
This is a simple JavaScript function which allows you to get and set CSS styles on DOM elements with ease.
This is a simple JavaScript function which allows you to get and set CSS styles on DOM elements with ease.

# Step 1 #

### Install ###
`npm install --save-dev stylerjs`

# Step 2 #

### Import to your project (ES5) ###

`var styler = require('stylerjs');`

### Import to your project (ES6) ###

`import styler from 'stylerjs'`

# Step 3 #

### Get Styles ###
`var styles = styler('.class-name').get(['height', 'width']);`

### Set Styles ###
`styler('.class-name').set({ 'height': '50px', 'width': '50px' });`
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "spinner",
"version": "1.0.0",
"description": "A simple class allowing you to implement and use your own loading and percentage spinners/loaders.",
"main": "src/index.js",
"scripts": {
"compile": "babel --presets es2015,stage-0 -d lib/ src/",
"prepublish": "npm run compile"
},
"repository": {
"type": "git",
"url": "git+https://github.com/tjcafferkey/stylerjs.git"
},
"author": "Tom Cafferkey",
"license": "ISC",
"bugs": {
"url": "https://github.com/tjcafferkey/stylerjs/issues"
},
"homepage": "https://github.com/tjcafferkey/stylerjs#readme",
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"chai": "^4.0.2",
"jsdom": "^11.0.0",
"jsdom-global": "^3.0.2",
"mocha": "^3.4.2"
}
}
35 changes: 35 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export function styler(element) {
function getElement() {
return element instanceof HTMLElement ? element : document.querySelector(element);
}

return {
get(styles) {
if (!Array.isArray(styles)) {
throw new Error('Second parameter of this function should be an array');
}

let elem = getElement();
let obj = {};

if (elem instanceof HTMLElement && styles) {
styles.map((style) => obj[style] = window.getComputedStyle(elem, null).getPropertyValue(style));
return obj;
}
},

set(styles) {
if (typeof styles !== 'object') {
throw new Error('Second parameter of this function should be an object');
}

let elem = getElement();

if (elem instanceof HTMLElement && styles) {
for (let i in styles) {
elem.style[i] = styles[i];
}
}
}
}
}
9 changes: 9 additions & 0 deletions test/test.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import "jsdom-global/register";
var expect = require("chai").expect;
var assert = require("chai").assert;

import styler from "../src/index";

describe("Styler", function() {

});

0 comments on commit 90fc173

Please sign in to comment.