### Build the Project and Run Tests
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/ts-node/node_modules/diff/CONTRIBUTING.md
Instructions for setting up the project by installing dependencies and running tests. The `npm test -- dev` command enables watching for tests in Node, and `karma start` can be used for manual browser testing.
```Shell
npm install
npm test
```
--------------------------------
### Nodeunit Browser Test Runner HTML Setup
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/nodeunit/README.md
An example HTML file (`test.html`) demonstrating the basic structure required to run Nodeunit tests directly in a web browser. It includes linking necessary CSS and JavaScript files, and using `nodeunit.run()` to execute defined test suites.
```HTML
Example Test Suite
Example Test Suite
```
--------------------------------
### Install Nodeunit from Source via Make
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/nodeunit/README.md
This shell command sequence outlines the process for installing Nodeunit directly from its source code. It involves cloning the repository and then using `make` to build and `sudo make install` to install the framework system-wide.
```Shell
make && sudo make install
```
--------------------------------
### Installation of labeled-stream-splicer
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/labeled-stream-splicer/readme.markdown
Instructions on how to install the `labeled-stream-splicer` package using npm.
```bash
npm install labeled-stream-splicer
```
--------------------------------
### Using setUp and tearDown for Test Lifecycle Management in Nodeunit
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/nodeunit/README.md
Shows how to define `setUp` and `tearDown` functions within a module or group to perform setup actions before each test and cleanup actions after each test completes, ensuring a clean test environment.
```JavaScript
module.exports = {
setUp: function (callback) {
this.foo = 'bar';
callback();
},
tearDown: function (callback) {
// clean up
callback();
},
test1: function (test) {
test.equals(this.foo, 'bar');
test.done();
}
};
```
--------------------------------
### Install isarray using component
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/isarray/README.md
Command to install the `isarray` package via component, a client-side package manager. This is an alternative installation method for browser environments.
```bash
$ component install juliangruber/isarray
```
--------------------------------
### Console Output of balanced-match Examples
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/balanced-match/README.md
Displays the expected output from running the JavaScript examples, illustrating the structure of the object returned by the `balanced` function, which includes `start`, `end`, `pre`, `body`, and `post` properties.
```bash
$ node example.js
{ start: 3, end: 14, pre: 'pre', body: 'in{nested}', post: 'post' }
{ start: 3,
end: 9,
pre: 'pre',
body: 'first',
post: 'between{second}post' }
{ start: 3, end: 17, pre: 'pre', body: 'in{nest}', post: 'post' }
```
--------------------------------
### Installing Browserify globally using npm
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/browserify/README.markdown
This command shows how to install the Browserify package globally using npm. The `-g` flag ensures that the `browserify` command-line tool is available system-wide. This is the first step to start using Browserify for your projects.
```Shell
npm install -g browserify
```
--------------------------------
### Install p-is-promise package
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/p-is-promise/readme.md
Instructions to install the `p-is-promise` package using npm.
```bash
$ npm install p-is-promise
```
--------------------------------
### Instantiate glob.Glob class
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/glob/README.md
Example of how to create a new `Glob` object, which is an EventEmitter that immediately starts searching the filesystem.
```javascript
var Glob = require("glob").Glob
var mg = new Glob(pattern, options, cb)
```
--------------------------------
### Usage Example for npm-run-path
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/npm-run-path/readme.md
Demonstrates how to use `npm-run-path` to modify the PATH environment variable and execute a locally installed binary using `child_process.execFileSync`.
```JavaScript
const childProcess = require('child_process');
const npmRunPath = require('npm-run-path');
console.log(process.env.PATH);
//=> '/usr/local/bin'
console.log(npmRunPath());
//=> '/Users/sindresorhus/dev/foo/node_modules/.bin:/Users/sindresorhus/dev/node_modules/.bin:/Users/sindresorhus/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/usr/local/bin'
// `foo` is a locally installed binary
childProcess.execFileSync('foo', {
env: npmRunPath.env()
});
```
--------------------------------
### Install Punycode.js via Component
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/punycode/README.md
Installs the Punycode.js library using Component.
```bash
component install bestiejs/punycode.js
```
--------------------------------
### Install mem package
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/mem/readme.md
Instructions on how to install the `mem` package using npm.
```bash
$ npm install mem
```
--------------------------------
### Installing browser-pack via npm
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/browser-pack/readme.markdown
Instructions for installing the browser-pack library and its command-line tool using npm.
```shell
npm install browser-pack
```
```shell
npm install -g browser-pack
```
--------------------------------
### Install nice-try via npm
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/nice-try/README.md
Instructions to install the nice-try package using the npm package manager.
```Shell
npm install nice-try
```
--------------------------------
### Install npm-run-path
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/npm-run-path/readme.md
Instructions to install the `npm-run-path` package using npm.
```Shell
$ npm install --save npm-run-path
```
--------------------------------
### Install Punycode.js via Bower
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/punycode/README.md
Installs the Punycode.js library using Bower.
```bash
bower install punycode
```
--------------------------------
### Install jsdiff
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/diff/README.md
Instructions for installing the jsdiff library using npm, bower, or git.
```shell
npm install diff
```
```shell
bower install jsdiff
```
```shell
git clone git://github.com/kpdecker/jsdiff.git
```
--------------------------------
### Install bn.js via npm
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/bn.js/README.md
Instructions to install the bn.js library using npm.
```shell
npm install --save bn.js
```
--------------------------------
### Install release-zalgo using npm
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/release-zalgo/README.md
Instructions to install the `release-zalgo` package as a dependency using the npm package manager.
```console
$ npm install --save release-zalgo
```
--------------------------------
### Install Development Dependencies for Punycode.js
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/url/node_modules/punycode/README.md
Instructions to install necessary development dependencies for Punycode.js, including project-specific dependencies and a global installation of Istanbul for code coverage.
```Shell
npm install --dev
npm install istanbul -g
```
--------------------------------
### Install insert-module-globals Library
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/insert-module-globals/readme.markdown
Installs the `insert-module-globals` library locally using npm.
```bash
npm install insert-module-globals
```
--------------------------------
### Install date-now npm Package
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/date-now/README.md
This command provides instructions on how to install the `date-now` package using the Node Package Manager (npm). It's a standard installation process for Node.js modules.
```bash
npm install date-now
```
--------------------------------
### Install vm-browserify via npm
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/vm-browserify/readme.markdown
This command demonstrates how to install the `vm-browserify` module directly using npm. While often a dependency of Browserify, direct installation is possible for specific use cases.
```shell
npm install vm-browserify
```
--------------------------------
### Install p-try using npm
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/p-try/readme.md
Instructions to install the p-try package using the npm package manager.
```Shell
$ npm install p-try
```
--------------------------------
### Get High-Resolution Time in Node.js
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/performance-now/README.md
This example demonstrates how to use the `performance-now` module to obtain high-resolution timestamps in Node.js. It shows how to capture start and end times and calculate the difference, highlighting the sub-millisecond precision and the typical overhead when calling the function consecutively.
```javascript
var now = require("performance-now")
var start = now()
var end = now()
console.log(start.toFixed(3)) // the number of milliseconds the current node process is running
console.log((start-end).toFixed(3)) // ~ 0.002 on my system
```
--------------------------------
### Get Parent Directories for Unix-like Paths in Node.js
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/parents/readme.markdown
This example demonstrates how to use the `parents` module to retrieve all parent directories for a given path on a Unix-like system. It uses `__dirname` as the input, which represents the directory name of the current module. The output is an array of paths, starting from the input directory and going up to the root, e.g., `['/home/user/project', '/home/user', '/home', '/']`.
```javascript
var parents = require('parents');
var dirs = parents(__dirname);
console.dir(dirs);
```
--------------------------------
### Install and Use Opener from Command Line
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/opener/README.md
This snippet demonstrates how to install the `opener` utility globally via npm and use it directly from the command line to open various targets such as URLs, local files, specific applications, or even execute npm scripts.
```bash
npm install opener -g
opener http://google.com
opener ./my-file.txt
opener firefox
opener npm run lint
```
--------------------------------
### Install pkg-dir Node.js Module
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/pkg-dir/readme.md
Instructions to install the pkg-dir module using npm.
```bash
npm install pkg-dir
```
--------------------------------
### Perform HTTP GET Request in Browser
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/stream-http/README.md
This example demonstrates how to make an HTTP GET request using the SDK's `http.get` method in a browser environment. It appends the received data and an 'END' marker to a div element on the page.
```JavaScript
http.get('/bundle.js', function (res) {
var div = document.getElementById('result');
div.innerHTML += 'GET /beep ';
res.on('data', function (buf) {
div.innerHTML += buf;
});
res.on('end', function () {
div.innerHTML += ' __END__';
});
})
```
--------------------------------
### HTML Structure for vm-browserify Example
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/vm-browserify/readme.markdown
This HTML snippet provides the basic structure for running the `vm-browserify` example. It includes jQuery and the bundled JavaScript file, and a `` element to display the result of the `vm.runInNewContext` execution.
```html
result =
```
--------------------------------
### Install nyc Globally
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/nyc/README.md
This command installs `nyc` globally on your system, making it accessible from any directory via the command line. Global installation is useful for running `nyc` directly without adding it as a project dependency.
```shell
npm i nyc -g
```
--------------------------------
### Install execa via npm
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/execa/readme.md
Instructions on how to install the execa package using npm, the Node.js package manager.
```Shell
$ npm install execa
```
--------------------------------
### Standard Proxied HTTP GET Request Example
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/request/README.md
Demonstrates a standard HTTP GET request when proxying HTTP traffic without tunneling. In this scenario, the full URL to the endpoint is included in the initial line of the request, and the proxy simply forwards it.
```HTTP
HTTP/1.1 GET http://endpoint-server.com/some-url
Host: proxy-server.com
Other-Headers: all go here
request body or whatever
```
--------------------------------
### Install Acorn by cloning repository
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/acorn/README.md
Clones the Acorn GitHub repository, navigates into the project directory, and installs its dependencies using npm to build from source.
```Shell
git clone https://github.com/acornjs/acorn.git
cd acorn
npm install
```
--------------------------------
### Perform a Full Project Release
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/ts-node/node_modules/diff/CONTRIBUTING.md
Steps to complete a full release of the project using the `release` Yeoman generator, including publishing to npm and components.
```Shell
yo release
npm publish
yo release:publish components jsdiff dist/components/
```
--------------------------------
### Install EJS via npm
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/ejs/README.md
Instructions to install the EJS templating engine using npm.
```bash
$ npm install ejs
```
--------------------------------
### Get Parent Directories for Windows Paths in Node.js
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/parents/readme.markdown
This example illustrates how to use the `parents` module to retrieve all parent directories for a specified Windows path. It explicitly sets the `platform` option to `'win32'` to ensure correct parsing of drive letters and backslashes. The output is an array of paths, starting from the input directory and going up to the drive root, e.g., `['C:\\Program Files\\Maxis\\Sim City 2000\\cities', 'C:\\Program Files\\Maxis\\Sim City 2000', 'C:\\Program Files\\Maxis', 'C:\\Program Files', 'C:']`.
```javascript
var parents = require('parents');
var dir = 'C:\\Program Files\\Maxis\\Sim City 2000\\cities';
var dirs = parents(dir, { platform : 'win32' });
console.dir(dirs);
```
--------------------------------
### Run Gulp tasks with ts-node
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/ts-node/README.md
Explains that Gulp can run TypeScript `gulpfile.ts` directly when `ts-node` is installed, simplifying the setup for Gulp tasks written in TypeScript.
```sh
gulp
```
--------------------------------
### Install Acorn Walk from Git Source
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/acorn-walk/README.md
Clones the `acorn` repository from GitHub, navigates into the directory, and installs its dependencies using npm.
```sh
git clone https://github.com/acornjs/acorn.git
cd acorn
npm install
```
--------------------------------
### Install node-elementtree via npm
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/elementtree/README.md
Instructions for installing the node-elementtree library using the npm package manager.
```bash
$ npm install elementtree
```
--------------------------------
### Instantiating SourceMapGenerator with Options
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/@babel/generator/node_modules/source-map/README.md
Example showing how to create a new `SourceMapGenerator` instance, providing initial configuration options such as the `file` name for the generated JavaScript and a `sourceRoot` URL.
```javascript
var generator = new sourceMap.SourceMapGenerator({
file: "my-generated-javascript-file.js",
sourceRoot: "http://example.com/app/js/"
});
```
--------------------------------
### Using find-cache-dir with Thunk Option
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/find-cache-dir/readme.md
Example showing how to use the `thunk` option to get a function that can join paths to the found cache directory, useful for creating files within the cache.
```js
const thunk = findCacheDir({name: 'foo', thunk: true});
thunk();
//=> '/some/path/node_modules/.cache/foo'
thunk('bar.js')
//=> '/some/path/node_modules/.cache/foo/bar.js'
thunk('baz', 'quz.js')
//=> '/some/path/node_modules/.cache/foo/baz/quz.js'
```
--------------------------------
### Get System Locale Asynchronously in JavaScript
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/os-locale/readme.md
This JavaScript example demonstrates how to use the `os-locale` package to asynchronously retrieve the current system locale. It requires Node.js and uses `async/await` for promise resolution, printing the locale to the console.
```JavaScript
const osLocale = require('os-locale');
(async () => {
console.log(await osLocale());
//=> 'en_US'
})();
```
--------------------------------
### Install brace-expansion via npm
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/brace-expansion/README.md
Instructions for installing the `brace-expansion` module using the npm package manager.
```bash
npm install brace-expansion
```
--------------------------------
### Get Current Timestamp with date-now (JavaScript)
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/date-now/README.md
This example demonstrates how to use `date-now` to obtain the current timestamp. It shows that the value returned by `require("date-now")()` is equivalent to `Date.now()`, allowing for easy mocking and testing.
```js
var now = require("date-now")
var ts = now()
var ts2 = Date.now()
assert.equal(ts, ts2)
```
--------------------------------
### Example: Perform a Full AST Walk with Acorn Walk
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/acorn-walk/README.md
Shows how to use `walk.full` to visit every node in the AST, calling a single callback function for each. This example logs the type and character position of each node.
```js
const acorn = require("acorn")
const walk = require("acorn-walk")
walk.full(acorn.parse("1 + 1"), node => {
console.log(`There's a ${node.type} node at ${node.ch}`)
})
```
--------------------------------
### Using browser-process-hrtime for time measurement
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/browser-process-hrtime/README.md
Demonstrates how to use `browser-process-hrtime` to measure time differences, independent of the environment. It prioritizes `process.hrtime` if available, otherwise falls back to the shim. The example shows capturing a start time and calculating a delta.
```JavaScript
const hrtime = require('browser-process-hrtime')
const start = hrtime()
// ...
const delta = hrtime(start)
```
--------------------------------
### Install AsyncKit via npm
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/asynckit/README.md
Instructions to install the asynckit library using npm, saving it as a dependency in the project's package.json.
```Shell
$ npm install --save asynckit
```
--------------------------------
### Encoding ASN.1 Sequence with Boolean (JavaScript)
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/asn1/README.md
Illustrates how to encode an ASN.1 sequence with a boolean value using `Ber.Writer`. The example starts a sequence, writes a boolean `true`, and then ends the sequence to generate the encoded buffer.
```javascript
var Ber = require('asn1').Ber;
var writer = new Ber.Writer();
writer.startSequence();
writer.writeBoolean(true);
writer.endSequence();
console.log(writer.buffer);
```
--------------------------------
### Set Custom HTTP Headers with Request Library
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/request/README.md
This example demonstrates how to set custom HTTP headers, such as `User-Agent`, when making requests using the `request` library in JavaScript. It shows how to include headers within the `options` object for a GET request to the GitHub API.
```js
var request = require('request');
var options = {
url: 'https://api.github.com/repos/request/request',
headers: {
'User-Agent': 'request'
}
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
console.log(info.stargazers_count + " Stars");
console.log(info.forks_count + " Forks");
}
}
request(options, callback);
```
--------------------------------
### Getting Source Map Module Reference (JavaScript)
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/combine-source-map/node_modules/source-map/README.md
Provides examples for importing or referencing the source map library in different JavaScript environments, including Node.js using require, browser builds via window.sourceMap, and Firefox's internal devtools/toolkit path.
```js
// Node.js
var sourceMap = require('source-map');
// Browser builds
var sourceMap = window.sourceMap;
// Inside Firefox
const sourceMap = require("devtools/toolkit/sourcemap/source-map.js");
```
--------------------------------
### Implement Git-Style Sub-commands with Commander.js
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/commander/Readme.md
Shows how to create sub-commands that are handled by separate executables, similar to Git. It defines `install`, `search`, and `list` commands, explaining that Commander.js will look for `program-command` executables (e.g., `pm-install`) and how to set a default sub-command or hide it from help output.
```javascript
// file: ./examples/pm
var program = require('commander');
program
.version('0.1.0')
.command('install [name]', 'install one or more packages')
.command('search [query]', 'search with optional query')
.command('list', 'list packages installed', {isDefault: true})
.parse(process.argv);
```
--------------------------------
### Check for Header Existence and Preserved Casing with `has`
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/caseless/README.md
The `has` method checks if a header exists, returning its original preserved casing if found. This example verifies that `c.has('a-header')` correctly returns `'a-Header'`.
```javascript
c.has('a-header') === 'a-Header'
```
--------------------------------
### List AWS Glacier Vaults in JavaScript
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/aws4/README.md
Example of a signed GET request to the AWS Glacier service to list vaults. It includes a specific `X-Amz-Glacier-Version` header required by the service. `aws4.sign` is used for request authentication, and the response is a JSON object.
```JavaScript
request(aws4.sign({service: 'glacier', path: '/-/vaults', headers: {'X-Amz-Glacier-Version': '2012-06-01'}}))
```
--------------------------------
### Install mkdirp via npm
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/mkdirp/readme.markdown
Instructions for installing the `mkdirp` library for programmatic use and the `mkdirp` command-line tool globally using npm.
```bash
npm install mkdirp
```
```bash
npm install -g mkdirp
```
--------------------------------
### Enable source map support programmatically in Node.js (CommonJS)
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/source-map-support/README.md
Integrates source map support into a Node.js application by requiring the module and calling its `install()` method. This line should be placed at the top of the compiled JavaScript file to ensure proper stack trace mapping from the start of execution.
```JavaScript
require('source-map-support').install();
```
--------------------------------
### Comprehensive Commander.js CLI Application Example
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/commander/Readme.md
A detailed example showcasing various Commander.js features, including defining global options, creating multiple commands with descriptions and command-specific options, using aliases, and implementing action functions. It demonstrates a typical structure for a multi-command CLI tool.
```javascript
var program = require('commander');
program
.version('0.1.0')
.option('-C, --chdir ', 'change the working directory')
.option('-c, --config ', 'set config path. defaults to ./deploy.conf')
.option('-T, --no-tests', 'ignore test hook');
program
.command('setup [env]')
.description('run setup commands for all envs')
.option("-s, --setup_mode [mode]", "Which setup mode to use")
.action(function(env, options){
var mode = options.setup_mode || "normal";
env = env || 'all';
console.log('setup for %s env(s) with %s mode', env, mode);
});
program
.command('exec ')
.alias('ex')
.description('execute the given remote cmd')
.option("-e, --exec_mode ", "Which exec mode to use")
.action(function(cmd, options){
console.log('exec "%s" using %s mode', cmd, options.exec_mode);
}).on('--help', function() {
console.log(' Examples:');
console.log();
console.log(' $ deploy exec sequential');
console.log(' $ deploy exec async');
console.log();
});
program
.command('*')
.action(function(env){
console.log('deploying "%s"', env);
});
program.parse(process.argv);
```
--------------------------------
### Example JSON Input for browser-pack
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/browser-pack/readme.markdown
Illustrates the expected JSON stream format for browser-pack, defining modules with their IDs, source code, dependencies, and entry points.
```json
[
{
"id": "a1b5af78",
"source": "console.log(require('./foo')(5))",
"deps": { "./foo": "b8f69fa5" },
"entry": true
},
{
"id": "b8f69fa5",
"source": "module.exports = function (n) { return n * 111 }",
"deps": {}
}
]
```
--------------------------------
### Example Usage of `deprecate()` Function in JavaScript
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/util-deprecate/README.md
This snippet illustrates how to apply the `deprecate()` function to mark an existing function as deprecated. It shows the initial setup where `exports.foo` is assigned the deprecated version of `foo`, and then demonstrates the console output users would see when `foo()` is invoked, displaying the specified deprecation message.
```javascript
// setup:
exports.foo = deprecate(foo, 'foo() is deprecated, use bar() instead');
// users see:
foo();
// foo() is deprecated, use bar() instead
foo();
foo();
```
--------------------------------
### JavaScript Standard `require.extensions` Transform Example
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/append-transform/readme.md
This snippet demonstrates the conventional approach to installing a transform on `require.extensions`. It involves saving the original extension, wrapping the `module._compile` method, applying the custom transformation, and then invoking the original extension. This pattern is widely used for modifying JavaScript code during module loading.
```JavaScript
const myTransform = require('my-transform');
const oldExtension = require.extensions['.js'];
require.extensions['.js'] = (module, filename) => {
const oldCompile = module._compile;
module._compile = (code, filename) => {
code = myTransform(code);
module._compile = oldCompile;
module._compile(code, filename);
};
oldExtension(module, filename);
};
```
--------------------------------
### Install hasha npm package
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/hasha/readme.md
Instructions to install the 'hasha' package using npm, saving it as a dependency in the project's package.json. This command adds the library to your project for use.
```Shell
$ npm install --save hasha
```
--------------------------------
### Inspect Cookie Jar Contents (JavaScript)
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/request/README.md
After a request, this example demonstrates how to programmatically inspect the cookies stored within a custom cookie jar. It shows how to retrieve the entire cookie string for a given URL using 'j.getCookieString()' and how to get an array of individual cookie objects using 'j.getCookies()'.
```javascript
var j = request.jar()
request({url: 'http://www.google.com', jar: j}, function () {
var cookie_string = j.getCookieString(url); // "key1=value1; key2=value2; ..."
var cookies = j.getCookies(url);
// [{key: 'key1', value: 'value1', domain: "www.google.com", ...}, ...]
})
```
--------------------------------
### Install Nodeunit Globally via npm
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/nodeunit/README.md
This shell command demonstrates the recommended way to install Nodeunit using the Node Package Manager (npm). The `-g` flag ensures a global installation, making the `nodeunit` command-line utility accessible from any directory on the system.
```Shell
npm install nodeunit -g
```
--------------------------------
### Set Header Value and Handle Clobbering with `set` Method
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/caseless/README.md
This example demonstrates the `set` method. It shows how to add a new header and how to append to an existing header by setting `clobber` to `false`, resulting in a comma-separated value.
```javascript
c.set('a-Header', 'fdas')
c.set('a-HEADER', 'more', false)
c.get('a-header') === 'fdsa,more'
```
--------------------------------
### Configure source-map-support Installation Options
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/source-map-support/README.md
This section provides various configuration options for the `source-map-support` module's `install()` method. These options allow customization of exception handling, source map retrieval, environment detection, and inline source map processing.
```JavaScript
require('source-map-support').install({
handleUncaughtExceptions: false
});
```
```JavaScript
require('source-map-support').install({
retrieveSourceMap: function(source) {
if (source === 'compiled.js') {
return {
url: 'original.js',
map: fs.readFileSync('compiled.js.map', 'utf8')
};
}
return null;
}
});
```
```JavaScript
require('source-map-support').install({
environment: 'node'
});
```
```JavaScript
require('source-map-support').install({
hookRequire: true
});
```
--------------------------------
### Browserify Standard Command-Line Options Reference
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/browserify/bin/usage.txt
Detailed documentation for the standard command-line options of the Browserify tool, including their short and long forms, and a description of their functionality.
```APIDOC
browserify:
Usage: browserify [entry files] {OPTIONS}
Standard Options:
--outfile, -o:
Description: Write the browserify bundle to this file. If unspecified, browserify prints to stdout.
--require, -r:
Description: A module name or file to bundle.require(). Optionally use a colon separator to set the target.
--entry, -e:
Description: An entry point of your app.
--ignore, -i:
Description: Replace a file with an empty stub. Files can be globs.
--exclude, -u:
Description: Omit a file from the output bundle. Files can be globs.
--external, -x:
Description: Reference a file from another bundle. Files can be globs.
--transform, -t:
Description: Use a transform module on top-level files.
--command, -c:
Description: Use a transform command on top-level files.
--standalone, -s:
Description: Generate a UMD bundle for the supplied export name. This bundle works with other module systems and sets the name given as a window global if no module system is found.
--debug, -d:
Description: Enable source maps that allow you to debug your files separately.
--help, -h:
Description: Show this message.
Note: For advanced options, type `browserify --help advanced`.
```
--------------------------------
### List AWS Elastic Transcoder Pipelines in JavaScript
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/aws4/README.md
Demonstrates how to make a signed GET request to the AWS Elastic Transcoder service to list pipelines. This example uses `aws4.sign` to handle the request signing. The expected output is a JSON object containing a list of pipelines.
```JavaScript
request(aws4.sign({service: 'elastictranscoder', path: '/2012-09-25/pipelines'}))
```
--------------------------------
### Argument Parsing Examples
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/argsparser/readme.md
Illustrates various command-line inputs and their corresponding parsed JSON output using the `argsparser`.
```Shell
node script.js // -> {"node": "script.js"}
node script.js -o // -> {"node": "script.js", "-o": true}
node script.js -o test // -> {"node": "script.js", "-o": "test"}
node script.js -a testa --b testb // -> {"node": "script.js", "-a": "testa", "--b": "testb"}
node script.js -paths /test.js /test1.js // -> {"node": "script.js", "-paths": ["/test.js", "/test1.js"]}
```
--------------------------------
### Ajv Assigning Defaults in Object Properties (JavaScript)
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/ajv/README.md
Demonstrates how Ajv's `useDefaults: true` option assigns default values to missing properties in an object based on the schema's `default` keyword. The example shows a `bar` property getting its default value 'baz' when not present in the input data.
```javascript
var ajv = new Ajv({ useDefaults: true });
var schema = {
"type": "object",
"properties": {
"foo": { "type": "number" },
"bar": { "type": "string", "default": "baz" }
},
"required": [ "foo", "bar" ]
};
var data = { "foo": 1 };
var validate = ajv.compile(schema);
console.log(validate(data)); // true
console.log(data); // { "foo": 1, "bar": "baz" }
```
--------------------------------
### Running Tests for merge-source-map
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/merge-source-map/README.md
Instructions for installing dependencies and running the test suite for the 'merge-source-map' library using npm commands.
```shell
% npm install
% npm test
```
--------------------------------
### Install mime-types using npm
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/mime-types/README.md
Instructions on how to install the `mime-types` Node.js module via the npm registry using the `npm install` command.
```sh
npm install mime-types
```
--------------------------------
### Install Lodash using npm
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/lodash/README.md
Instructions to install npm globally and then install Lodash as a project dependency using the npm package manager.
```shell
$ npm i -g npm
$ npm i --save lodash
```
--------------------------------
### Instantiating the Minimatch Class
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/minimatch/README.md
Shows how to create a new instance of the `minimatch.Minimatch` class by providing a glob pattern and an optional options object.
```javascript
var Minimatch = require("minimatch").Minimatch
var mm = new Minimatch(pattern, options)
```
--------------------------------
### Install domain-browser via Ender
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/domain-browser/README.md
Instructions for installing the `domain-browser` module using the Ender package manager. Once installed, the module can be required in your JavaScript code.
```JavaScript
ender add domain-browser
```
```JavaScript
require('domain-browser')
```
--------------------------------
### Basic Usage Example with minimist
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/mkdirp/node_modules/minimist/readme.markdown
Demonstrates how to integrate and use `minimist` to parse command-line arguments from `process.argv`, displaying the resulting parsed object.
```js
var argv = require('minimist')(process.argv.slice(2));
console.dir(argv);
```
--------------------------------
### Demonstrate Various Needle Usage Patterns (Promises, Callbacks, Streams)
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/needle/README.md
This comprehensive snippet showcases Needle's flexibility by providing examples for common HTTP GET requests using Promises, traditional callbacks, and Node.js streams. It highlights how to handle responses based on your preferred asynchronous pattern, including piping data to a file.
```javascript
needle('get', 'https://server.com/posts/12')
.then(function(resp) {
// ...
})
.catch(function(err) {
// ...
});
```
```javascript
needle.get('ifconfig.me/all.json', function(error, response, body) {
if (error) throw error;
// body is an alias for `response.body`,
// that in this case holds a JSON-decoded object.
console.log(body.ip_addr);
});
```
```javascript
var out = fs.createWriteStream('logo.png');
needle.get('https://google.com/images/logo.png').pipe(out).on('done', function() {
console.log('Pipe finished!');
});
```
--------------------------------
### Example TAP-formatted Input
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/tap-mocha-reporter/node_modules/tap-parser/readme.markdown
Provides an example of standard Test Anything Protocol (TAP) output, including test assertions, comments, and a plan line. This input is used to demonstrate what `tap-parser` processes.
```shell
$ node test.js
TAP version 13
# beep
ok 1 should be equal
ok 2 should be equivalent
# boop
ok 3 should be equal
ok 4 (unnamed assert)
1..4
# tests 4
# pass 4
# ok
```
--------------------------------
### Programmatic Usage of Opener in JavaScript
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/opener/README.md
This example illustrates how to incorporate the `opener` module into a Node.js application. It shows how to programmatically open web URLs, local files, specific applications, and execute npm scripts from within JavaScript code.
```js
var opener = require("opener");
opener("http://google.com");
opener("./my-file.txt");
opener("firefox");
opener("npm run lint");
```
--------------------------------
### Example .splunkrc Convenience File Configuration
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/README.md
This snippet provides the structure and example content for a .splunkrc convenience file. This file can store Splunk Enterprise connection details like host, port, username, password, scheme, and version, allowing SDK unit tests to use these values automatically during development. It's important to note this file is for development convenience only and not for production credentials.
```config
# Splunk Enterprise host (default: localhost)
host=localhost
# Splunk Enterprise admin port (default: 8089)
port=8089
# Splunk Enterprise username
username=admin
# Splunk Enterprise password
password=changed!
# Access scheme (default: https)
scheme=https
# Your version of Splunk Enterprise
version=9.0
```
--------------------------------
### Install invert-kv npm package
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/invert-kv/readme.md
This shell command demonstrates how to install the 'invert-kv' package using npm. Once installed, the module can be required and used in JavaScript applications.
```Shell
$ npm install invert-kv
```
--------------------------------
### Install UglifyJS 3 Globally via npm
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/uglify-js/README.md
Instructions to install UglifyJS 3 globally using npm for command-line usage. This requires Node.js to be installed.
```npm
npm install uglify-js -g
```
--------------------------------
### Install isarray module using component
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/readable-stream/node_modules/isarray/README.md
This command installs the `isarray` module using the Component package manager. It's an alternative installation method for projects that use Component.
```bash
$ component install juliangruber/isarray
```
--------------------------------
### Example TAP Protocol Input
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/tap-parser/readme.markdown
This example shows a typical Test Anything Protocol (TAP) formatted output, including version, test points with descriptions, comments, and the final plan and summary lines. This is the kind of input that `tap-parser` is designed to process.
```shell
TAP version 13
# beep
ok 1 should be equal
ok 2 should be equivalent
# boop
ok 3 should be equal
ok 4 (unnamed assert)
1..4
# tests 4
# pass 4
# ok
```
--------------------------------
### Install p-defer using npm
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/p-defer/readme.md
Instructions to install the 'p-defer' package using npm. The '--save' flag ensures it's added as a dependency in your project's package.json file.
```shell
$ npm install --save p-defer
```
--------------------------------
### Install Gulp and Development Dependencies for TypeScript
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/typescript/README.md
Installs the Gulp command-line interface globally and all development dependencies required to build and test the TypeScript compiler. Node.js and npm must be installed.
```bash
npm install -g gulp
npm install
```
--------------------------------
### Contributing to Nodeunit - Running Lint
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/nodeunit/README.md
Instructs contributors to run the `make lint` command before submitting pull requests to ensure adherence to the project's consistent coding style.
```Shell
make lint
```
--------------------------------
### Basic Usage of the TAP Command
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/tap/bin/usage.txt
Illustrates the fundamental syntax for invoking the `tap` command, specifying test files, and parsing TAP data from standard input. It executes all specified files and interprets their output as TAP formatted test results.
```Shell
Usage:
tap [options]
Executes all the files and interprets their output as TAP
formatted test result data.
To parse TAP data from stdin, specify "-" as a filename.
```
--------------------------------
### Basic Usage of bn.js
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/bn.js/README.md
Demonstrates how to initialize BN objects with different bases and perform an addition operation.
```js
const BN = require('bn.js');
var a = new BN('dead', 16);
var b = new BN('101010', 2);
var res = a.add(b);
console.log(res.toString(10)); // 57047
```
--------------------------------
### Example Bundled JavaScript Output
Source: https://github.com/splunk/splunk-sdk-javascript/blob/master/node_modules/browser-pack/readme.markdown
Shows the resulting JavaScript bundle generated by browser-pack from the provided JSON input, including the internal module loader and defined modules.
```js
(function(p,c,e){function r(n){if(!c[n]){c[n]={exports:{}};p[n][0](function(x){return r(p[n][1][x])},c[n],c[n].exports);}return c[n].exports}for(var i=0;i
description: Read from INPUT.
default: stdin
-o, --output