Skip to content

Instantly share code, notes, and snippets.

@eldargab
Created March 5, 2012 15:18
Show Gist options
  • Save eldargab/1978707 to your computer and use it in GitHub Desktop.
Save eldargab/1978707 to your computer and use it in GitHub Desktop.
Wrap commonJS file for use in browser
param(
$file,
$global
)
function camelize ($s) {
($s -Split "[\-_]", 0, "RegexMatch" | foreach {
$_.Substring(0, 1).toUpper() + $_.Substring(1)
}) -Join ""
}
$f = Get-Item $file
if (-not $global) {
$global = camelize($f.BaseName)
}
$out = @"
(function () {
var module = {
exports: {}
}
var exports = module.exports;
$(Get-Content $f | Out-String)
window.$global = module.exports;
})();
"@
$out.Replace("`r", "").Replace("`n", "`r`n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment