Comparing version
70
index.js
@@ -1,5 +0,67 @@ | ||
function identity(x) { return x; } | ||
var style = document.createElement('p').style | ||
var prefixes = ['O', 'ms', 'Moz', 'Webkit'] | ||
var upper = /([A-Z])/g | ||
var memo = {} | ||
module.exports = identity; | ||
module.exports.dash = identity; | ||
module.exports.dash = identity; | ||
/** | ||
* prefix `key` | ||
* | ||
* prefix('transform') // => WebkitTransform | ||
* | ||
* @param {String} key | ||
* @return {String} | ||
* @api public | ||
*/ | ||
function prefix(key){ | ||
// Camel case | ||
key = key.replace(/-([a-z])/g, function(_, char){ | ||
return char.toUpperCase() | ||
}) | ||
// Without prefix | ||
if (style[key] !== undefined) return key | ||
// With prefix | ||
var Key = key.charAt(0).toUpperCase() + key.slice(1) | ||
var i = prefixes.length | ||
while (i--) { | ||
var name = prefixes[i] + Key | ||
if (style[name] !== undefined) return name | ||
} | ||
throw new Error('Unable to prefix ' + key) | ||
} | ||
/** | ||
* Memoized version of `prefix` | ||
* | ||
* @param {String} key | ||
* @return {String} | ||
* @api public | ||
*/ | ||
function prefixMemozied(key){ | ||
return key in memo | ||
? memo[key] | ||
: memo[key] = prefix(key) | ||
} | ||
/** | ||
* Create a dashed prefix | ||
* | ||
* @param {String} key | ||
* @return {String} | ||
* @api public | ||
*/ | ||
function prefixDashed(key){ | ||
key = prefix(key) | ||
if (upper.test(key)) { | ||
key = '-' + key.replace(upper, '-$1') | ||
upper.lastIndex = 0 | ||
} | ||
return key.toLowerCase() | ||
} | ||
if (typeof module !== 'undefined' && module.exports){ | ||
module.exports = prefixMemozied | ||
module.exports.dash = prefixDashed | ||
} |
{ | ||
"name": "prefix", | ||
"version": "0.2.4", | ||
"description": "prefix a css attribute", | ||
"version": "0.2.5", | ||
"description": "Prefix CSS attributes", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"mocha": "^2.2.5", | ||
"serve": "jkroso/serve#1.5.1" | ||
"mocha": "^2.4.5", | ||
"serve": "jkroso/serve#1.6.7" | ||
}, | ||
"repository": "git://github.com/jkroso/prefix.git", | ||
"main": "index.js", | ||
"browser": "browser.js", | ||
"keywords": ["prefix"], | ||
"keywords": [ | ||
"prefix" | ||
], | ||
"author": "Jake Rosoman", | ||
"license": "MIT", | ||
"files": ["index.js"] | ||
"license": "MIT" | ||
} |
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
5924
162.12%9
125%120
2900%0
-100%