Processes a javascript string and outputs only the required characters,
stripping out all unneeded characters.

@param string $js      The raw javascript to be minified
@param array  $options Various runtime options in an associative array
774106
protected function minifyDirectToOutput($js, $options)
	{
		$this->initialize($js, $options);
		$this->loop();
		$this->clean();
	}
209467
protected function compressInlineJsCode($js)
    {
        if (!($js = (string) $js)) {
            return $js; // Nothing to do.
        }
        if (($compressed_js = \WebSharks\JsMinifier\Core::compress($js))) {
            return '/*<![CDATA[*/'.$compressed_js.'/*]]>*/';
        }
        return $js;
    }
1191187
public function jQueryOptions()
    {
        if (!empty($this->jQueryOptions)) {
            $options = "";

            foreach ($this->jQueryOptions as $option => $value) {
                if (!empty($options)) {
                    $options .= ", ";
                }

                $options .= $option . ': ';
                /*When javascript needs to be applied as a jQuery option's value, no quotes are needed.*/
                if (is_string($value) && substr($value, 0, 3) == "js:") {
                    $options .= substr($value, 3);
                } else {
                    $options .= var_export($value, true);
                }
            }

            echo "{ ", $options, " }";
        }
    }
1362114
public function encode(array $options = [])
    {
        $options = array_replace(
            [
                'encodingOptions'       => $this->getOption('encodingOptions')
            ],
            $options
        );

        $json = json_encode($this->getContents(), $options['encodingOptions']);

        if ($json === false) {
            switch (json_last_error()) {
                case JSON_ERROR_DEPTH:
                    $msg = 'The maximum stack depth has been exceeded.';

                    break;
                case JSON_ERROR_STATE_MISMATCH:
                    $msg = 'Occurs with underflow or with the modes mismatch.';

                    break;
                case JSON_ERROR_CTRL_CHAR:
                    $msg = 'Control character error, possibly incorrectly encoded.';

                    break;
                case JSON_ERROR_UTF8:
                    $msg = 'alformed UTF-8 characters, possibly incorrectly encoded.';

                    break;
                default:
                    $msg = 'Unknown error';
            }

            throw EncodeException::create($this->getPath(), $msg);
        }

        return $json;
    }
939491
function getValidationScript($options = null)
    {
        if (isset($this->_data[$this->name])) {
            $callback = $this->_data[$this->name][0];
            $params   = ($this->_BCMode[$this->name]? "'', {jsVar}": '{jsVar}') .
                        (isset($options)? ", '{$options}'": '');
        } else {
            $callback = is_array($options)? $options[1]: $options;
            $params   = '{jsVar}';
        }
        return array('', "{jsVar} != '' && !{$callback}({$params})");
    }
1108641
public function exec($js, $immediatly=false) {
		$script=$js."\n";
		if ($immediatly)
			$this->jquery_code_for_compile[]=$script;
		return $script;
	}
133910
public static function renderJs($options = []) {
		$result = '';
		$list = [];
		$js = Application::get(['layout', 'js']);
		if (!empty($js)) {
			asort($js);
			foreach ($js as $k => $v) {
				$script = $k . (strpos($k, '?') !== false ? '&' : '?') . self::getVersion();
				$list[] = $script;
				$js_options = Application::get(['layout', 'js_options', $k]) ?? [];
				if (empty($js_options)) {
					$js_options['crossorigin'] = 'anonymous';
				}
				$js_options['type'] = 'text/javascript';
				$js_options['src'] = $script;
				$result.= \HTML::script($js_options);
			}
		}
		// list is needed for ajax form reloads
		if (!empty($options['return_list'])) {
			return $list;
		}
		return $result;
	}
726655
public function _output($array_js='') {
		if (!is_array($array_js)) {
			$array_js=array (
					$array_js
			);
		}

		foreach ( $array_js as $js ) {
			$this->jquery_code_for_compile[]="\t$js\n";
		}
	}
471581
function parse_javascript(file, options, callback) { 
  fs.readFile(file, 'utf8', function (err, source) {
    if (err) {
      callback(err);
      return;
    }
    process_jsd(source, file, options, callback);
  });
}
744983
public function output($array_js) {
		if (!is_array($array_js)) {
			$array_js=array (
					$array_js
			);
		}

		foreach ( $array_js as $js ) {
			$this->jquery_code_for_compile[]="\t$js\n";
		}
	}
608719
final public static function js(array $params)
    {
        return ("<script type='text/javascript' src='".
            FEnv::get("host.web.components.apps").strtolower(FEnv::get("framework.env"))."/".
            strtolower(FEnv::get("app.call"))."/".
            ((isset($params['path']))? $params['path']."." : "")."js'></script>");
    }
692569
function getValidationScript($options = null)
    {
        $regex = isset($this->_data[$this->name]) ? $this->_data[$this->name] : $options;

        return array("  var regex = " . $regex . ";\n", "{jsVar} != '' && !regex.test({jsVar})");
    }
1169360
protected function processOptions(&$options)
    {
        if (!isset($options['extra'])) {
            $options['extra'] = array();
        }
        $options['extra'] = CMap::mergeArray($this->extraVariables, $options['extra']);
    }
962565
public function getOutputFromHtml($html, array $options = array())
    {
        $this->log('Get output from html.');

        $html = $this->getCssConverter()->convertToString($html);
        $html = $this->getJSConverter()->convertToString($html);

        return $this->getGenerator()->getOutputFromHtml($html, $options);
    }
754048
protected function maybeCompressJsCode($js)
    {
        if (($benchmark = !empty($this->options['benchmark']) && $this->options['benchmark'] === 'details')) {
            $time = microtime(true);
        }
        $js = (string) $js; // Force string value.

        if (isset($this->options['compress_js_code'])) {
            if (!$this->options['compress_js_code']) {
                $disabled = true; // Disabled flag.
            }
        }
        if (!$js || !empty($disabled)) {
            goto finale; // Nothing to do.
        }
        if (strlen($js) > 1000000) {
            // Exclude VERY large files. Too time-consuming.
            // Should really be compressed ahead-of-time anyway.
            goto finale; // Don't compress HUGE files.
        }
        try { // Catch JS compression-related exceptions.
            if (!($compressed_js = \WebSharks\JsMinifier\Core::compress($js))) {
                // `E_USER_NOTICE` to avoid a show-stopping problem.
                trigger_error('JS compression failure.', E_USER_NOTICE);
            } else {
                $js = $compressed_js;
            } // Use compressed JS file.
        } catch (\Exception $exception) {
            trigger_error($exception->getMessage(), E_USER_NOTICE);
        }
        finale: // Target point; finale/return value.

        if ($js) {
            $js = trim($js);
        }
        if ($benchmark && !empty($time) && $js && empty($disabled)) {
            $this->benchmark->addTime(
                __FUNCTION__,
                $time, // Caller, start time, task performed.
                sprintf('compressing JS w/ checksum: `%1$s`', md5($js))
            );
        }
        return $js;
    }
35185
function getValidationScript($options = null)
    {
        switch ($this->name) {
            case 'minlength':
                $test = '{jsVar}.length < '.$options;
                break;
            case 'maxlength':
                $test = '{jsVar}.length > '.$options;
                break;
            default:
                $test = '({jsVar}.length < '.$options[0].' || {jsVar}.length > '.$options[1].')';
        }
        return array('', "{jsVar} != '' && {$test}");
    }
1126010
public function format_date( $options, $js = false ) {

		switch ( (string) pods_v( static::$type . '_type', $options, 'format', true ) ) {
			case 'wp':
				$format = get_option( 'date_format' );
				if ( $js ) {
					$format = $this->convert_format( $format, array( 'source' => 'php' ) );
				}
				break;
			case 'custom':
				if ( ! $js ) {
					$format = pods_v( static::$type . '_format_custom', $options, '' );
				} else {
					$format = pods_v( static::$type . '_format_custom_js', $options, '' );
					if ( empty( $format ) ) {
						$format = pods_v( static::$type . '_format_custom', $options, '' );
						$format = $this->convert_format( $format, array( 'source' => 'php' ) );
					}
				}
				break;
			default:
				$date_format = $this->get_date_formats( $js );
				$format      = $date_format[ pods_v( static::$type . '_format', $options, 'ymd_dash', true ) ];
				break;
		}//end switch

		return $format;
	}