Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

move utils to util.js

  • Loading branch information...
commit daf8cb83c8a7f4769bf2e140733464a44d87b38d 1 parent 9622f35
@eldargab authored
View
7 lib/app.js
@@ -1,6 +1,7 @@
-var resolve = require('./path-resolve')
-var parseDeps = require('./parse-dependencies')
var Box = require('./box')
+var util = require('./util')
+var resolve = util.resolvePath
+
module.exports = App
@@ -14,7 +15,7 @@ App.prototype.use = function (fn, var_args) {
App.prototype.def = function (path, deps, fn) {
if (typeof deps == 'function') {
fn = deps
- deps = fn.deps || parseDeps(fn)
+ deps = fn.deps || util.parseDeps(fn)
}
fn = fn || NOOP
deps = deps || []
View
4 lib/box.js
@@ -1,4 +1,4 @@
-var resolve = require('./path-resolve')
+var util = require('./util')
module.exports = Box
module.exports.Evaluated = EvaluatedBox
@@ -10,7 +10,7 @@ function Box (path, deps, fn) {
this.path = path
this.isSync = fn.length < 2
this.deps = deps.map(function (dep) {
- return resolve(path, dep)
+ return util.resolvePath(path, dep)
})
}
View
19 lib/parse-dependencies.js
@@ -1,19 +0,0 @@
-
-module.exports = function parseDependencies (fn) {
- var deps = []
- var src = fn.toString()
-
- src = src.replace(/(\/\*([\s\S]*?)\*\/|\/\/(.*)$)/mg, '') // remove comments
-
- var m = /^function(?:\s+\w+)?\s*\((\w+)/.exec(src) // determine the name of the get function
- if (!m) return deps
- var get = m[1]
-
- var regex = new RegExp('(\\.\\s*)?' + get + '\\(\\s*["\']([^\'"\\s]+)["\']\\s*\\)', 'g')
-
- src.replace(regex, function (_, isProp, dep) {
- !isProp && deps.push(dep)
- })
-
- return deps
-}
View
21 lib/path-resolve.js
@@ -1,21 +0,0 @@
-
-module.exports = function resolvePath (from, to) {
- if (to[0] != '.' && to[0] != '&') return to
-
- var path = from.split('/')
- var segs = to.split('/')
- if (to[0] != '&') path.pop()
- segs.forEach(function (seg, index) {
- if (seg == '.' || seg == '&') return
- if (seg == '..') {
- path.pop()
- return
- }
- path.push(seg)
- })
- return trimSlash(path.join('/'))
-}
-
-function trimSlash (s) {
- return s[0] == '/' ? s.slice(1) : s
-}
View
40 lib/util.js
@@ -0,0 +1,40 @@
+exports.resolvePath = function resolvePath (from, to) {
+ if (to[0] != '.' && to[0] != '&') return to
+
+ var path = from.split('/')
+ var segs = to.split('/')
+ if (to[0] != '&') path.pop()
+ segs.forEach(function (seg, index) {
+ if (seg == '.' || seg == '&') return
+ if (seg == '..') {
+ path.pop()
+ return
+ }
+ path.push(seg)
+ })
+ return trimSlash(path.join('/'))
+}
+
+function trimSlash (s) {
+ return s[0] == '/' ? s.slice(1) : s
+}
+
+
+exports.parseDeps = function parseDependencies (fn) {
+ var deps = []
+ var src = fn.toString()
+
+ src = src.replace(/(\/\*([\s\S]*?)\*\/|\/\/(.*)$)/mg, '') // remove comments
+
+ var m = /^function(?:\s+\w+)?\s*\((\w+)/.exec(src) // determine the name of the get function
+ if (!m) return deps
+ var get = m[1]
+
+ var regex = new RegExp('(\\.\\s*)?' + get + '\\(\\s*["\']([^\'"\\s]+)["\']\\s*\\)', 'g')
+
+ src.replace(regex, function (_, isProp, dep) {
+ !isProp && deps.push(dep)
+ })
+
+ return deps
+}
View
2  test/parse-dependencies.js
@@ -1,4 +1,4 @@
-var parse = require('../lib/parse-dependencies')
+var parse = require('../lib/util').parseDeps
describe('Dependencies parsing', function () {
it('Should determine getter name', function () {
View
2  test/path-resolve.js
@@ -1,4 +1,4 @@
-var resolve = require('../lib/path-resolve')
+var resolve = require('../lib/util').resolvePath
describe('Path resolve', function () {
test('a/b/c', 'd/f', 'd/f')
Please sign in to comment.
Something went wrong with that request. Please try again.