2011-09-19 01:39:13 +00:00
<!DOCTYPE html> < html > < head > < title > system.js< / title > < meta http-equiv = "content-type" content = "text/html; charset=UTF-8" > < link rel = "stylesheet" media = "all" href = "../../docco.css" / > < / head > < body > < div id = "container" > < div id = "background" > < / div > < div id = "jump_to" > Jump To … < div id = "jump_wrapper" > < div id = "jump_page" > < a class = "source" href = "../..//nconf/common.html" > nconf/common.html < / a > < a class = "source" href = "../..//nconf/formats.html" > nconf/formats.html < / a > < a class = "source" href = "../..//nconf/provider.html" > nconf/provider.html < / a > < a class = "source" href = "../..//nconf/stores/file.html" > nconf/stores/file.html < / a > < a class = "source" href = "../..//nconf/stores/memory.html" > nconf/stores/memory.html < / a > < a class = "source" href = "../..//nconf/stores/system.html" > nconf/stores/system.html < / a > < a class = "source" href = "../..//nconf/stores.html" > nconf/stores.html < / a > < a class = "source" href = "../..//nconf.html" > nconf.html < / a > < / div > < / div > < / div > < table cellpadding = "0" cellspacing = "0" > < thead > < tr > < th class = "docs" > < h1 > system.js < / h1 > < / th > < th class = "code" > < / th > < / tr > < / thead > < tbody > < tr id = "section-1" > < td class = "docs" > < div class = "pilwrap" > < a class = "pilcrow" href = "#section-1" > ¶ < / a > < / div > < / td > < td class = "code" > < div class = "highlight" > < pre > < span class = "cm" > /*< / span >
< span class = "cm" > * system.js: Simple memory-based store for process environment variables and< / span >
< span class = "cm" > * command-line arguments.< / span >
< span class = "cm" > *< / span >
< span class = "cm" > * (C) 2011, Charlie Robbins< / span >
< span class = "cm" > *< / span >
< span class = "cm" > */< / span >
2015-07-07 20:06:41 +00:00
2011-09-19 01:39:13 +00:00
< span class = "kd" > var< / span > < span class = "nx" > util< / span > < span class = "o" > =< / span > < span class = "nx" > require< / span > < span class = "p" > (< / span > < span class = "s1" > ' util' < / span > < span class = "p" > ),< / span >
< span class = "nx" > Memory< / span > < span class = "o" > =< / span > < span class = "nx" > require< / span > < span class = "p" > (< / span > < span class = "s1" > ' ./memory' < / span > < span class = "p" > ).< / span > < span class = "nx" > Memory< / span > < span class = "p" > ;< / span >
< / pre > < / div > < / td > < / tr > < tr id = "section-2" > < td class = "docs" > < div class = "pilwrap" > < a class = "pilcrow" href = "#section-2" > ¶ < / a > < / div > < h3 > function System (options)< / h3 >
< h4 > @options {Object} Options for this instance.< / h4 >
< p > Constructor function for the System nconf store, a simple abstraction
around the Memory store that can read process environment variables
and command-line arguments.< / p > < / td > < td class = "code" > < div class = "highlight" > < pre > < span class = "kd" > var< / span > < span class = "nx" > System< / span > < span class = "o" > =< / span > < span class = "nx" > exports< / span > < span class = "p" > .< / span > < span class = "nx" > System< / span > < span class = "o" > =< / span > < span class = "kd" > function< / span > < span class = "p" > (< / span > < span class = "nx" > options< / span > < span class = "p" > )< / span > < span class = "p" > {< / span >
< span class = "nx" > options< / span > < span class = "o" > =< / span > < span class = "nx" > options< / span > < span class = "o" > ||< / span > < span class = "p" > {};< / span >
< span class = "nx" > Memory< / span > < span class = "p" > .< / span > < span class = "nx" > call< / span > < span class = "p" > (< / span > < span class = "k" > this< / span > < span class = "p" > ,< / span > < span class = "nx" > options< / span > < span class = "p" > );< / span >
< span class = "k" > this< / span > < span class = "p" > .< / span > < span class = "nx" > type< / span > < span class = "o" > =< / span > < span class = "s1" > ' system' < / span > < span class = "p" > ;< / span >
< span class = "k" > this< / span > < span class = "p" > .< / span > < span class = "nx" > overrides< / span > < span class = "o" > =< / span > < span class = "nx" > options< / span > < span class = "p" > .< / span > < span class = "nx" > overrides< / span > < span class = "o" > ||< / span > < span class = "kc" > null< / span > < span class = "p" > ;< / span >
< span class = "k" > this< / span > < span class = "p" > .< / span > < span class = "nx" > env< / span > < span class = "o" > =< / span > < span class = "nx" > options< / span > < span class = "p" > .< / span > < span class = "nx" > env< / span > < span class = "o" > ||< / span > < span class = "kc" > false< / span > < span class = "p" > ;< / span >
< span class = "k" > this< / span > < span class = "p" > .< / span > < span class = "nx" > argv< / span > < span class = "o" > =< / span > < span class = "nx" > options< / span > < span class = "p" > .< / span > < span class = "nx" > argv< / span > < span class = "o" > ||< / span > < span class = "kc" > false< / span > < span class = "p" > ;< / span >
< span class = "p" > };< / span > < / pre > < / div > < / td > < / tr > < tr id = "section-3" > < td class = "docs" > < div class = "pilwrap" > < a class = "pilcrow" href = "#section-3" > ¶ < / a > < / div > < p > Inherit from the Memory store< / p > < / td > < td class = "code" > < div class = "highlight" > < pre > < span class = "nx" > util< / span > < span class = "p" > .< / span > < span class = "nx" > inherits< / span > < span class = "p" > (< / span > < span class = "nx" > System< / span > < span class = "p" > ,< / span > < span class = "nx" > Memory< / span > < span class = "p" > );< / span > < / pre > < / div > < / td > < / tr > < tr id = "section-4" > < td class = "docs" > < div class = "pilwrap" > < a class = "pilcrow" href = "#section-4" > ¶ < / a > < / div > < h3 > function loadSync ()< / h3 >
< p > Loads the data passed in from < code > process.env< / code > into this instance.< / p > < / td > < td class = "code" > < div class = "highlight" > < pre > < span class = "nx" > System< / span > < span class = "p" > .< / span > < span class = "nx" > prototype< / span > < span class = "p" > .< / span > < span class = "nx" > loadSync< / span > < span class = "o" > =< / span > < span class = "kd" > function< / span > < span class = "p" > ()< / span > < span class = "p" > {< / span >
< span class = "k" > if< / span > < span class = "p" > (< / span > < span class = "k" > this< / span > < span class = "p" > .< / span > < span class = "nx" > env< / span > < span class = "p" > )< / span > < span class = "p" > {< / span >
< span class = "k" > this< / span > < span class = "p" > .< / span > < span class = "nx" > loadEnv< / span > < span class = "p" > ();< / span >
< span class = "p" > }< / span >
2015-07-07 20:06:41 +00:00
2011-09-19 01:39:13 +00:00
< span class = "k" > if< / span > < span class = "p" > (< / span > < span class = "k" > this< / span > < span class = "p" > .< / span > < span class = "nx" > argv< / span > < span class = "p" > )< / span > < span class = "p" > {< / span >
< span class = "k" > this< / span > < span class = "p" > .< / span > < span class = "nx" > loadArgv< / span > < span class = "p" > ();< / span >
< span class = "p" > }< / span >
2015-07-07 20:06:41 +00:00
2011-09-19 01:39:13 +00:00
< span class = "k" > if< / span > < span class = "p" > (< / span > < span class = "k" > this< / span > < span class = "p" > .< / span > < span class = "nx" > overrides< / span > < span class = "p" > )< / span > < span class = "p" > {< / span >
< span class = "k" > this< / span > < span class = "p" > .< / span > < span class = "nx" > loadOverrides< / span > < span class = "p" > ();< / span >
< span class = "p" > }< / span >
2015-07-07 20:06:41 +00:00
2011-09-19 01:39:13 +00:00
< span class = "k" > return< / span > < span class = "k" > this< / span > < span class = "p" > .< / span > < span class = "nx" > store< / span > < span class = "p" > ;< / span >
< span class = "p" > };< / span > < / pre > < / div > < / td > < / tr > < tr id = "section-5" > < td class = "docs" > < div class = "pilwrap" > < a class = "pilcrow" href = "#section-5" > ¶ < / a > < / div > < h3 > function loadOverrides ()< / h3 >
< p > Loads any overrides set on this instance into
the underlying managed < code > Memory< / code > store.< / p > < / td > < td class = "code" > < div class = "highlight" > < pre > < span class = "nx" > System< / span > < span class = "p" > .< / span > < span class = "nx" > prototype< / span > < span class = "p" > .< / span > < span class = "nx" > loadOverrides< / span > < span class = "o" > =< / span > < span class = "kd" > function< / span > < span class = "p" > ()< / span > < span class = "p" > {< / span >
< span class = "k" > if< / span > < span class = "p" > (< / span > < span class = "o" > !< / span > < span class = "k" > this< / span > < span class = "p" > .< / span > < span class = "nx" > overrides< / span > < span class = "p" > )< / span > < span class = "p" > {< / span >
< span class = "k" > return< / span > < span class = "p" > ;< / span >
< span class = "p" > }< / span >
2015-07-07 20:06:41 +00:00
2011-09-19 01:39:13 +00:00
< span class = "kd" > var< / span > < span class = "nx" > self< / span > < span class = "o" > =< / span > < span class = "k" > this< / span > < span class = "p" > ,< / span >
< span class = "nx" > keys< / span > < span class = "o" > =< / span > < span class = "nb" > Object< / span > < span class = "p" > .< / span > < span class = "nx" > keys< / span > < span class = "p" > (< / span > < span class = "k" > this< / span > < span class = "p" > .< / span > < span class = "nx" > overrides< / span > < span class = "p" > );< / span >
2015-07-07 20:06:41 +00:00
2011-09-19 01:39:13 +00:00
< span class = "nx" > keys< / span > < span class = "p" > .< / span > < span class = "nx" > forEach< / span > < span class = "p" > (< / span > < span class = "kd" > function< / span > < span class = "p" > (< / span > < span class = "nx" > key< / span > < span class = "p" > )< / span > < span class = "p" > {< / span >
< span class = "nx" > self< / span > < span class = "p" > .< / span > < span class = "nx" > set< / span > < span class = "p" > (< / span > < span class = "nx" > key< / span > < span class = "p" > ,< / span > < span class = "nx" > self< / span > < span class = "p" > .< / span > < span class = "nx" > overrides< / span > < span class = "p" > [< / span > < span class = "nx" > key< / span > < span class = "p" > ]);< / span >
< span class = "p" > });< / span >
2015-07-07 20:06:41 +00:00
2011-09-19 01:39:13 +00:00
< span class = "k" > return< / span > < span class = "k" > this< / span > < span class = "p" > .< / span > < span class = "nx" > store< / span > < span class = "p" > ;< / span >
< span class = "p" > };< / span > < / pre > < / div > < / td > < / tr > < tr id = "section-6" > < td class = "docs" > < div class = "pilwrap" > < a class = "pilcrow" href = "#section-6" > ¶ < / a > < / div > < h3 > function loadArgv ()< / h3 >
2015-07-07 20:06:41 +00:00
< p > Loads the data passed in from the command-line arguments
2011-09-19 01:39:13 +00:00
into this instance.< / p > < / td > < td class = "code" > < div class = "highlight" > < pre > < span class = "nx" > System< / span > < span class = "p" > .< / span > < span class = "nx" > prototype< / span > < span class = "p" > .< / span > < span class = "nx" > loadArgv< / span > < span class = "o" > =< / span > < span class = "kd" > function< / span > < span class = "p" > ()< / span > < span class = "p" > {< / span >
2015-07-07 20:06:41 +00:00
< span class = "kd" > var< / span > < span class = "nx" > self< / span > < span class = "o" > =< / span > < span class = "k" > this< / span > < span class = "p" > ,< / span >
2011-09-19 01:39:13 +00:00
< span class = "nx" > argv< / span > < span class = "p" > ;< / span >
2015-07-07 20:06:41 +00:00
2011-09-19 01:39:13 +00:00
< span class = "k" > if< / span > < span class = "p" > (< / span > < span class = "k" > typeof< / span > < span class = "k" > this< / span > < span class = "p" > .< / span > < span class = "nx" > argv< / span > < span class = "o" > ===< / span > < span class = "s1" > ' object' < / span > < span class = "p" > )< / span > < span class = "p" > {< / span >
2015-07-07 20:06:41 +00:00
< span class = "nx" > argv< / span > < span class = "o" > =< / span > < span class = "nx" > require< / span > < span class = "p" > (< / span > < span class = "s1" > ' yargs' < / span > < span class = "p" > ).< / span > < span class = "nx" > options< / span > < span class = "p" > (< / span > < span class = "k" > this< / span > < span class = "p" > .< / span > < span class = "nx" > argv< / span > < span class = "p" > ).< / span > < span class = "nx" > argv< / span > < span class = "p" > ;< / span >
2011-09-19 01:39:13 +00:00
< span class = "p" > }< / span >
< span class = "k" > else< / span > < span class = "k" > if< / span > < span class = "p" > (< / span > < span class = "k" > this< / span > < span class = "p" > .< / span > < span class = "nx" > argv< / span > < span class = "p" > )< / span > < span class = "p" > {< / span >
2015-07-07 20:06:41 +00:00
< span class = "nx" > argv< / span > < span class = "o" > =< / span > < span class = "nx" > require< / span > < span class = "p" > (< / span > < span class = "s1" > ' yargs' < / span > < span class = "p" > ).< / span > < span class = "nx" > argv< / span > < span class = "p" > ;< / span >
2011-09-19 01:39:13 +00:00
< span class = "p" > }< / span >
2015-07-07 20:06:41 +00:00
2011-09-19 01:39:13 +00:00
< span class = "k" > if< / span > < span class = "p" > (< / span > < span class = "o" > !< / span > < span class = "nx" > argv< / span > < span class = "p" > )< / span > < span class = "p" > {< / span >
< span class = "k" > return< / span > < span class = "p" > ;< / span >
< span class = "p" > }< / span >
2015-07-07 20:06:41 +00:00
2011-09-19 01:39:13 +00:00
< span class = "nb" > Object< / span > < span class = "p" > .< / span > < span class = "nx" > keys< / span > < span class = "p" > (< / span > < span class = "nx" > argv< / span > < span class = "p" > ).< / span > < span class = "nx" > forEach< / span > < span class = "p" > (< / span > < span class = "kd" > function< / span > < span class = "p" > (< / span > < span class = "nx" > key< / span > < span class = "p" > )< / span > < span class = "p" > {< / span >
< span class = "nx" > self< / span > < span class = "p" > .< / span > < span class = "nx" > set< / span > < span class = "p" > (< / span > < span class = "nx" > key< / span > < span class = "p" > ,< / span > < span class = "nx" > argv< / span > < span class = "p" > [< / span > < span class = "nx" > key< / span > < span class = "p" > ]);< / span >
< span class = "p" > });< / span >
2015-07-07 20:06:41 +00:00
2011-09-19 01:39:13 +00:00
< span class = "k" > return< / span > < span class = "k" > this< / span > < span class = "p" > .< / span > < span class = "nx" > store< / span > < span class = "p" > ;< / span >
< span class = "p" > };< / span > < / pre > < / div > < / td > < / tr > < tr id = "section-7" > < td class = "docs" > < div class = "pilwrap" > < a class = "pilcrow" href = "#section-7" > ¶ < / a > < / div > < h3 > function loadEnv ()< / h3 >
< p > Loads the data passed in from < code > process.env< / code > into this instance.< / p > < / td > < td class = "code" > < div class = "highlight" > < pre > < span class = "nx" > System< / span > < span class = "p" > .< / span > < span class = "nx" > prototype< / span > < span class = "p" > .< / span > < span class = "nx" > loadEnv< / span > < span class = "o" > =< / span > < span class = "kd" > function< / span > < span class = "p" > ()< / span > < span class = "p" > {< / span >
< span class = "kd" > var< / span > < span class = "nx" > self< / span > < span class = "o" > =< / span > < span class = "k" > this< / span > < span class = "p" > ;< / span >
2015-07-07 20:06:41 +00:00
2011-09-19 01:39:13 +00:00
< span class = "k" > if< / span > < span class = "p" > (< / span > < span class = "o" > !< / span > < span class = "k" > this< / span > < span class = "p" > .< / span > < span class = "nx" > env< / span > < span class = "p" > )< / span > < span class = "p" > {< / span >
< span class = "k" > return< / span > < span class = "p" > ;< / span >
< span class = "p" > }< / span >
2015-07-07 20:06:41 +00:00
2011-09-19 01:39:13 +00:00
< span class = "nb" > Object< / span > < span class = "p" > .< / span > < span class = "nx" > keys< / span > < span class = "p" > (< / span > < span class = "nx" > process< / span > < span class = "p" > .< / span > < span class = "nx" > env< / span > < span class = "p" > ).< / span > < span class = "nx" > filter< / span > < span class = "p" > (< / span > < span class = "kd" > function< / span > < span class = "p" > (< / span > < span class = "nx" > key< / span > < span class = "p" > )< / span > < span class = "p" > {< / span >
< span class = "k" > return< / span > < span class = "o" > !< / span > < span class = "nx" > self< / span > < span class = "p" > .< / span > < span class = "nx" > env< / span > < span class = "p" > .< / span > < span class = "nx" > length< / span > < span class = "o" > ||< / span > < span class = "nx" > self< / span > < span class = "p" > .< / span > < span class = "nx" > env< / span > < span class = "p" > .< / span > < span class = "nx" > indexOf< / span > < span class = "p" > (< / span > < span class = "nx" > key< / span > < span class = "p" > )< / span > < span class = "o" > !==< / span > < span class = "o" > -< / span > < span class = "mi" > 1< / span > < span class = "p" > ;< / span >
< span class = "p" > }).< / span > < span class = "nx" > forEach< / span > < span class = "p" > (< / span > < span class = "kd" > function< / span > < span class = "p" > (< / span > < span class = "nx" > key< / span > < span class = "p" > )< / span > < span class = "p" > {< / span >
< span class = "nx" > self< / span > < span class = "p" > .< / span > < span class = "nx" > set< / span > < span class = "p" > (< / span > < span class = "nx" > key< / span > < span class = "p" > ,< / span > < span class = "nx" > process< / span > < span class = "p" > .< / span > < span class = "nx" > env< / span > < span class = "p" > [< / span > < span class = "nx" > key< / span > < span class = "p" > ]);< / span >
< span class = "p" > });< / span >
2015-07-07 20:06:41 +00:00
2011-09-19 01:39:13 +00:00
< span class = "k" > return< / span > < span class = "k" > this< / span > < span class = "p" > .< / span > < span class = "nx" > store< / span > < span class = "p" > ;< / span >
< span class = "p" > };< / span >
2015-07-07 20:06:41 +00:00
< / pre > < / div > < / td > < / tr > < / tbody > < / table > < / div > < / body > < / html >