Comparing version 0.2.3 to 0.2.4
77
index.js
@@ -0,74 +1,5 @@ | ||
function identity(x) { return x; } | ||
var style = document.createElement('p').style | ||
var prefixes = 'O ms Moz Webkit'.split(' ') | ||
var upper = /([A-Z])/g | ||
var memo = {} | ||
/** | ||
* memoized `prefix` | ||
* | ||
* @param {String} key | ||
* @return {String} | ||
* @api public | ||
*/ | ||
module.exports = exports = function(key){ | ||
return key in memo | ||
? memo[key] | ||
: memo[key] = prefix(key) | ||
} | ||
exports.prefix = prefix | ||
exports.dash = dashedPrefix | ||
/** | ||
* 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 = capitalize(key) | ||
var i = prefixes.length | ||
while (i--) { | ||
var name = prefixes[i] + Key | ||
if (style[name] !== undefined) return name | ||
} | ||
throw new Error('unable to prefix ' + key) | ||
} | ||
function capitalize(str){ | ||
return str.charAt(0).toUpperCase() + str.slice(1) | ||
} | ||
/** | ||
* create a dasherized prefix | ||
* | ||
* @param {String} key | ||
* @return {String} | ||
* @api public | ||
*/ | ||
function dashedPrefix(key){ | ||
key = prefix(key) | ||
if (upper.test(key)) { | ||
key = '-' + key.replace(upper, '-$1') | ||
upper.lastIndex = 0 // fix #1 | ||
} | ||
return key.toLowerCase() | ||
} | ||
module.exports = identity; | ||
module.exports.dash = identity; | ||
module.exports.dash = identity; |
{ | ||
"name": "prefix", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "prefix a css attribute", | ||
@@ -11,2 +11,4 @@ "dependencies": {}, | ||
"repository": "git://github.com/jkroso/prefix.git", | ||
"main": "index.js", | ||
"browser": "browser.js", | ||
"keywords": ["prefix"], | ||
@@ -13,0 +15,0 @@ "author": "Jake Rosoman", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2260
4
1