diff options
author | Ryan Van Etten <ryanve@gmail.com> | 2017-01-06 21:19:13 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-06 21:19:13 -0800 |
commit | b6985f27f8be42086bc6e5e74c3fd50970e2f6a6 (patch) | |
tree | 7ed75c6f15b5f6f6ca3190cd378a5e473a5bea8d | |
parent | 7e473b08d95784c191e5f07754217d364248a92d (diff) | |
parent | 60da9f6bdd1b475094371e525a85eb2f56342d96 (diff) | |
download | actual-b6985f27f8be42086bc6e5e74c3fd50970e2f6a6.zip actual-b6985f27f8be42086bc6e5e74c3fd50970e2f6a6.tar.gz actual-b6985f27f8be42086bc6e5e74c3fd50970e2f6a6.tar.bz2 |
Merge pull request #1 from ryanve/next
Flatten structure and use npm scripts for 0.3.0 release
-rw-r--r-- | .editorconfig | 7 | ||||
-rw-r--r-- | .gitattributes | 1 | ||||
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | GruntFile.js | 64 | ||||
-rw-r--r-- | README.md | 112 | ||||
-rw-r--r-- | actual.js | 20 | ||||
-rw-r--r-- | actual.min.js | 6 | ||||
-rw-r--r-- | index.html | 28 | ||||
-rw-r--r-- | package.json | 47 | ||||
-rw-r--r-- | src/index.js | 63 | ||||
-rw-r--r-- | test.js | 18 | ||||
-rw-r--r-- | test/index.html | 27 | ||||
-rw-r--r-- | test/index.js | 10 |
13 files changed, 155 insertions, 250 deletions
diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..b3dfee7 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto @@ -1 +1 @@ -node_modules
\ No newline at end of file +node_modules diff --git a/GruntFile.js b/GruntFile.js deleted file mode 100644 index 905fd6c..0000000 --- a/GruntFile.js +++ /dev/null @@ -1,64 +0,0 @@ -module.exports = function(grunt) { - var _ = grunt.util._, - pkg = grunt.file.readJSON('package.json'), - path = require('path'), - from = 'src/', - main = pkg.main && path.basename(pkg.main) || 'index.js', - source = [_.find([from + 'index.js', from + main, from + pkg.name], function(v) { - return this.existsSync(v); - }, require('fs'))], - holder = (function(who) { - return typeof who == 'string' ? who.split(/\s+</)[0].trim() : who && who.name || ''; - }(pkg.author)); - - grunt.initConfig({ - pkg: pkg, - aok: { test: ['./test'] }, - jshint: { - // gruntjs.com/configuring-tasks#globbing-patterns - // **/** matches in current and sub dirs - all: ['./'], // current dir and sub dirs - sub: ['*/'], // sub dirs - dir: ['*.js'], // current dir - src: ['src/'], - test: ['test/'], - grunt: [path.basename(__filename)], - build: [main], - options: { - ignores: ['**/**/node_modules/', '**/**/vendor/', '**/**.min.js'], - debug:true, expr:true, sub:true, boss:true, supernew:true, node:true, - undef:true, unused:true, devel:true, evil:true, laxcomma:true, eqnull:true, - browser:true, globals:{ender:true, define:true}, jquery:true, maxerr:10 - } - }, - concat: { - options: { - banner: [ - '/*!', - ' * <%= pkg.name %> <%= pkg.version %>+<%= grunt.template.today("UTC:yyyymmddHHMM") %>', - ' * <%= pkg.homepage %>', - ' * MIT License <%= grunt.template.today("UTC:yyyy") %> ' + holder, - ' */\n\n' - ].join('\n') - }, - build: { - files: _.object([main], [source]) - } - }, - uglify: { - options: { - report: 'gzip', - preserveComments: 'some' - }, - build: { - files: _.object([main.replace(/\.js$/i, '.min.js')], [main]) - } - } - }); - - grunt.loadNpmTasks('aok'); - grunt.loadNpmTasks('grunt-contrib-jshint'); - grunt.loadNpmTasks('grunt-contrib-concat'); - grunt.loadNpmTasks('grunt-contrib-uglify'); - grunt.registerTask('default', ['jshint:grunt', 'jshint:sub', 'concat', 'jshint:build', 'uglify']); -};
\ No newline at end of file @@ -1,25 +1,25 @@ -# [actual](../../)
-
-#### Determine actual `@media` breakpoints for [CSS <b>range</b> features](http://dev.w3.org/csswg/mediaqueries4/#media-descriptor-table)
-
-- <b>actual</b> calculates responsive breakpoints that <em>accurately</em> match CSS media queries
-- <b>actual</b> is based on [this gist](https://gist.github.com/ryanve/7924792)
-
-## API ([0.2](../../releases))
-
-### `actual(feature, unit?, init?, step?)`
+# actual + +#### Determine actual `@media` breakpoints for [CSS <b>range</b> features](http://dev.w3.org/csswg/mediaqueries4/#media-descriptor-table) + +- <b>actual</b> calculates responsive breakpoints that <em>accurately</em> match CSS media queries +- <b>actual</b> is based on [this gist](https://gist.github.com/ryanve/7924792) + +## API + +### `actual(feature, unit?, init?, step?)` - <var>feature</var>: [CSS range feature name](http://dev.w3.org/csswg/mediaqueries4/#media-descriptor-table) - <var>unit</var>: applicable CSS unit (default: unitless) - <var>init</var>: initial guess (default: `1`) - <var>step</var>: step size (default: varies by unit) - <b>@return</b> number (breakpoint) -
-```js
-actual('width', 'em') // => 87.40625
-actual('device-width', 'px') // => 1440
-actual('resolution', 'dpi') // => 96
-actual('color') // => 10
+ +```js +actual('width', 'em') // => 87.40625 +actual('device-width', 'px') // => 1440 +actual('resolution', 'dpi') // => 96 +actual('color') // => 10 ``` ### `actual.mq(query)` @@ -29,48 +29,42 @@ actual('color') // => 10 ```js actual.mq('tv') actual.mq('(width:30em)') -```
-
-### `actual.feature(feature)`
+``` + +### `actual.feature(feature)` - Create a partial function that gets <var>feature</var> in a given unit -- <b>@return</b> function
-
-```js
-['px', 'em', 'pt', 'in', 'cm', 'mm'].map(actual.feature('width'))
-```
-
-### `actual.as(unit)`
+- <b>@return</b> function + +```js +['px', 'em', 'pt', 'in', 'cm', 'mm'].map(actual.feature('width')) +``` + +### `actual.as(unit)` - Create a partial function that gets a given feature in <var>unit</var> -- <b>@return</b> function
-
-```js
-['width', 'height', 'device-width', 'device-height'].map(actual.as('px'))
-```
-
-## Compatibility
-
-- Chrome 9+, FF6+, IE9+, Opera 12.1, Safari 5.1 or elsewhere via [`matchMedia`](https://developer.mozilla.org/en-US/docs/Web/API/Window.matchMedia#Browser_compatibility) or `msMatchMedia`
-- Results depend on browser `@media` support for the feature in question
-
-## [NPM](//npmjs.org/package/actual)
-
-```sh
-$ npm install actual
-```
-
-## Contribute
-
-Contribute by making edits in [`/src`](./src) or reporting [issues](../../issues).
-
-```sh
-$ npm install
-$ grunt jshint:src
-```
-
-## Fund
-
-<b>[Tip the developer](https://www.gittip.com/ryanve/)</b> =)
-
-## License
-
-[MIT](LICENSE.md)
\ No newline at end of file +- <b>@return</b> function + +```js +['width', 'height', 'device-width', 'device-height'].map(actual.as('px')) +``` + +## Compatibility + +- Chrome 9+, FF6+, IE9+, Opera 12.1, Safari 5.1 or elsewhere via [`matchMedia`](https://developer.mozilla.org/en-US/docs/Web/API/Window.matchMedia#Browser_compatibility) or `msMatchMedia` +- Results depend on browser `@media` support for the feature in question + +## [npm](https://www.npmjs.com/package/actual) + +``` +npm install actual --save +``` + +## Contribute + +``` +npm install +npm test +``` + +## Fund + +<b>[Tip the developer](https://www.gittip.com/ryanve/)</b> =) @@ -1,11 +1,5 @@ -/*! - * actual 0.2.0+201402061122 - * https://github.com/ryanve/actual - * MIT License 2014 Ryan Van Etten - */ - -(function(root, name, make) { - if (typeof module != 'undefined' && module['exports']) module['exports'] = make(); +!function(root, name, make) { + if (typeof module != 'undefined' && module.exports) module.exports = make(); else root[name] = make(); }(this, 'actual', function() { @@ -34,7 +28,7 @@ } return 0; } - + /** * @param {string} unit * @return {Function} @@ -44,7 +38,7 @@ return actual(feature, unit); }; } - + /** * @param {string} feat * @return {Function} @@ -54,7 +48,7 @@ return actual(feat, unit); }; } - + var media = 'matchMedia', win = typeof window != 'undefined' && window; actual['actual'] = actual; actual['feature'] = feature; @@ -64,6 +58,6 @@ } : function() { return false; }; - + return actual; -}));
\ No newline at end of file +}); diff --git a/actual.min.js b/actual.min.js deleted file mode 100644 index c4ebc57..0000000 --- a/actual.min.js +++ /dev/null @@ -1,6 +0,0 @@ -/*! - * actual 0.2.0+201402061122 - * https://github.com/ryanve/actual - * MIT License 2014 Ryan Van Etten - */ -!function(a,b,c){"undefined"!=typeof module&&module.exports?module.exports=c():a[b]=c()}(this,"actual",function(){function a(b,c,d,e){var f,g,h,i,j=a.mq;for(c="string"==typeof c?c:"",d=d>0?c?+d:d>>0:1,e=e>0?+e:0>e?-e:"px"==c?256:c?32:1,b+=":",c+=")",i=d;e&&i>=0;i+=e){if(h=j("(min-"+b+i+c),g=j("(max-"+b+i+c),h&&g)return j("("+b+(i>>0)+c)?i>>0:i;null==f?e=(f=!g)?h&&e:-e:(g?f:!f)&&(f=!f,e=-e/2)}return 0}function b(b){return function(c){return a(c,b)}}function c(b){return function(c){return a(b,c)}}var d="matchMedia",e="undefined"!=typeof window&&window;return a.actual=a,a.feature=c,a.as=b,a.mq=e[d]||e[d="msMatchMedia"]?function(a){return!!e[d](a).matches}:function(){return!1},a});
\ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..4df38e9 --- /dev/null +++ b/index.html @@ -0,0 +1,28 @@ +<!DOCTYPE html> +<html lang="en-US"> +<title>actual: Determine actual @media breakpoints</title> +<meta name="viewport" content="width=device-width, initial-scale=1"> +<meta name="description" content="actual JavaScript module tests"> +<style> + ::selection { background: MediumBlue; color: AliceBlue } + html { background: AliceBlue; color: black } + *, :before, :after { box-sizing: border-box } + html { font: 1em/2 sans-serif; } + body { width: 100%; margin: auto; padding: 1em } + button:enabled:hover { cursor: pointer } + pre, code { -moz-tab-size: 2; -o-tab-size: 2; tab-size: 2 } + pre { white-space: pre-wrap; word-wrap: break-word; overflow: auto } + h1, h2 { line-height: 1 } + h2 { font-size: 1.5em } + p code { font-weight: bold; } +</style> + +<h1>actual</h1> +<p>Check tests and play with <code>actual</code> in the console.</p> +<ul> + <li><a href="https://github.com/ryanve/actual">Github</a></li> + <li><a href="https://www.npmjs.com/package/actual">npm</a></li> +</ul> + +<script src="actual.js"></script> +<script src="test.js"></script> diff --git a/package.json b/package.json index 524d771..294d50f 100644 --- a/package.json +++ b/package.json @@ -5,17 +5,50 @@ "homepage": "https://github.com/ryanve/actual", "license": "MIT", "author": "Ryan Van Etten", - "keywords": ["breakpoint", "breakpoints", "responsive", "media queries", "viewport", "dimensions", "ender"], + "scripts": { + "pretest": "jshint actual.js && jshint test.js", + "test": "node test.js" + }, + "keywords": [ + "breakpoint", + "breakpoints", + "responsive", + "media queries", + "media query", + "matchmedia", + "@media", + "media", + "viewport", + "resolution" + "dimensions", + "javascript", + "browser", + "ender" + ], "main": "./actual.js", "repository": { "type": "git", "url": "https://github.com/ryanve/actual.git" }, + "bugs": { + "url": "https://github.com/ryanve/actual/issues" + }, + "jshintConfig": { + "asi": false, + "boss": true, + "browser": true, + "eqnull": true, + "expr": true, + "supernew": true, + "lastsemic": true, + "latedef": "nofunc", + "maxerr": 5, + "node": true, + "sub": true, + "undef": true, + "unused": true + }, "devDependencies": { - "aok": "~1.7.0", - "grunt": "~0.4.2", - "grunt-contrib-uglify": "~0.3.0", - "grunt-contrib-concat": "~0.3.0", - "grunt-contrib-jshint": "~0.8.0" + "jshint": "^2.9.4" } -}
\ No newline at end of file +} diff --git a/src/index.js b/src/index.js deleted file mode 100644 index 3e173a7..0000000 --- a/src/index.js +++ /dev/null @@ -1,63 +0,0 @@ -(function(root, name, make) { - if (typeof module != 'undefined' && module['exports']) module['exports'] = make(); - else root[name] = make(); -}(this, 'actual', function() { - - /** - * @param {string} feature range feature name e.g. "width" - * @param {string=} unit CSS unit for feature e.g. "em" - * @param {number=} init initial guess - * @param {number=} step size for iterations - * @return {number} breakpoint (0 if invalid unit or feature) - */ - function actual(feature, unit, init, step) { - var up, gte, lte, curr, mq = actual['mq']; - unit = typeof unit == 'string' ? unit : ''; - init = 0 < init ? (unit ? +init : init>>0) : 1; - // Step starts positive. Minimize iterations, unless feat may be "integer" type. - step = 0 < step ? +step : 0 > step ? -step : 'px' == unit ? 256 : unit ? 32 : 1; - for (feature += ':', unit += ')', curr = init; step && 0 <= curr; curr+=step) { - lte = mq('(min-' + feature + curr + unit); - gte = mq('(max-' + feature + curr + unit); - // Found: Use the floored value if it makes an exact match. Else return as is. - if (lte && gte) return mq('(' + feature + (curr>>0) + unit) ? curr>>0 : curr; - // 1st iteration: Save direction. Flip if down. Break if neither b/c unknown. - if (null == up) step = (up = !gte) ? lte && step : -step; - // Later iterations: If skipped, reverse direction and raise precision. - else if (gte ? up : !up) up = !up, step = -step/2; - } - return 0; - } - - /** - * @param {string} unit - * @return {Function} - */ - function as(unit) { - return function(feature) { - return actual(feature, unit); - }; - } - - /** - * @param {string} feat - * @return {Function} - */ - function feature(feat) { - return function(unit) { - return actual(feat, unit); - }; - } - - var media = 'matchMedia', win = typeof window != 'undefined' && window; - actual['actual'] = actual; - actual['feature'] = feature; - actual['as'] = as; - actual['mq'] = win[media] || win[media = 'msMatchMedia'] ? function(q) { - return !!win[media](q).matches; - } : function() { - return false; - }; - - return actual; -}));
\ No newline at end of file @@ -0,0 +1,18 @@ +!function(root) { + var common = typeof module != 'undefined' && !!module.exports; + var actual = common ? require('./') : root.actual; + + function ok(result, correct) { + if (result !== correct) { + throw new Error(result + ' should be ' + correct); + } + } + + ok(typeof actual('width'), 'number'); + ok(typeof actual.mq(''), 'boolean'); + ok(actual.actual, actual); + ok(actual.feature('width')('px'), actual('width', 'px')); + ok(actual.as('px')('width'), actual('width', 'px')); + + console.log('All tests passed =)'); +}(this); diff --git a/test/index.html b/test/index.html deleted file mode 100644 index 6b99a7f..0000000 --- a/test/index.html +++ /dev/null @@ -1,27 +0,0 @@ -<!DOCTYPE html> -<title>Tests</title> -<style> - html { font-family:sans-serif; background:#efefef; color:#111 } - body { width:96%; margin:auto; font-size:1em; line-height:1.6 } - pre, code, kbd { font-family:monospace; -moz-tab-size:4; -o-tab-size:4; tab-size:4 } - h3 b { font-weight:700 } - h3, pre b { font-weight:400 } - pre { padding:0 .5em; white-space:pre-line } - pre span { white-space:pre-wrap } - pre b { color:#008080 } - pre small { font-size:inherit; font-family:inherit; font-weight:lighter; color:#707070 } - kbd { display:inline-block; padding:.2em } - pre kbd { padding:0 } -</style> - -<h1>Tests</h1> -<h3><b>Browser:</b> Check tests in the console.</h3> -<h3><b>CLI:</b> Run these commands:</h3> -<pre> - <span><b>$</b> <kbd>cd</kbd> <a href="../">aok</a> <small># Go to the package root.</small></span> - <span><b>$</b> <kbd>npm install</kbd> <small># Install dependencies.</small></span> - <span><b>$</b> <kbd>grunt aok</kbd> <small># Run tests.</small></span> -</pre> -<script src="../src/index.js"></script> -<script src="../node_modules/aok/aok.min.js"></script> -<script src="./index.js"></script>
\ No newline at end of file diff --git a/test/index.js b/test/index.js deleted file mode 100644 index 0da41ce..0000000 --- a/test/index.js +++ /dev/null @@ -1,10 +0,0 @@ -(function(root) { - var common = typeof module != 'undefined' && !!module.exports; - var aok = common ? require('../node_modules/aok') : root.aok; - var actual = common ? require('../src') : root.actual; - aok({ id:'actual', test:typeof actual('width') == 'number' }); - aok({ id:'actual.mq', test:typeof actual.mq('') == 'boolean' }); - aok({ id:'actual.actual', test:actual.actual === actual }); - aok({ id:'actual.feature', test:actual.feature('width')('px') === actual('width', 'px') }); - aok({ id:'actual.as', test:actual.as('px')('width') === actual('width', 'px') }); -}(this));
\ No newline at end of file |