 #   sortByConfig data, config
 #   # => ['1', '2', '3', '4', '5']
 exports.sortByConfig = sortByConfig = (data, config) ->
+  if typeof config isnt 'object'
+    throw new TypeError 'Sorting config is not an object'
+  config.before ?= []
+  config.after ?= []
   # Clone data to a new array because we
   # don't want a side effect here.
-  [data...].sort((a, b) ->
-    compareArrayItems config.before, a, b
-  ).sort (a, b) ->
-    -(compareArrayItems config.after, a, b)
+  [data...]
+    .sort (a, b) ->
+      compareArrayItems config.before, a, b
+    .sort (a, b) ->
+      -(compareArrayItems config.after, a, b)
 
 # Sorts by pattern.
 # 

    for sourceFile in destinationFile.sourceFiles
      result.push sourceFile.data
  result

# Shell color manipulation tools.
colors =

#     ]
#   }]
#   config =
#     order:
#       'vendor/jquery.js':
#         before: ['a.coffee']
#         after: ['b.coffee']
#   sortLanguageFiles data, config
#   # => [{path: 'vendor/scripts/jquery.js', sourceFiles: [
#     {path: 'a.coffee'}, {path: 'b.coffee'}]}]
exports.sortLanguageFiles = (data, config) ->
  data.map (item) ->
    pathes = (file.path for file in item.sourceFiles)
