Skip to content

Latest commit

 

History

History
337 lines (251 loc) · 16.8 KB

Reference.md

File metadata and controls

337 lines (251 loc) · 16.8 KB

Objects

JScrewIt : object

Typedefs

FeatureElement : Feature | string

A feature object or name or alias of a predefined feature.

CompatibleFeatureArray : Array.<FeatureElement>

An array containing any number of feature objects or names or aliases of predefined features, in no particular order.

All of the specified features need to be compatible, so that their union can be constructed.

JScrewIt : object

Kind: global namespace

JScrewIt.Feature

Objects of this type indicate which of the capabilities that JScrewIt can use to minimize the length of its output are available in a particular JavaScript engine.

JScrewIt comes with a set of predefined feature objects exposed as property values of JScrewIt.Feature or JScrewIt.Feature.ALL, where the property name is the feature's name or an alias thereof.

Besides these predefined features, it is possible to construct custom features from the union or intersection of other features.

Among the predefined features, there are some special ones called elementary features that cannot be expressed as a union of any number of other elementary features. All other features, called composite features, can be constructed as a union of zero or more elementary features. Two of the predefined composite features are particularly important: DEFAULT is the empty feature, indicating that no elementary feature is available at all; AUTO is the union of all elementary features available in the current engine.

Not all features can be available at the same time: some features are necessarily incompatible, meaning that they mutually exclude each other, and thus their union cannot be constructed.

Kind: static class of JScrewIt

new Feature([...feature])

Creates a new feature object from the union of the specified features.

The constructor can be used with or without the new operator, e.g. new JScrewIt.Feature(feature1, feature2) or JScrewIt.Feature(feature1, feature2). If no arguments are specified, the new feature object will be equivalent to DEFAULT.

Throws:

  • Error The specified features are not compatible with each other.
Param Type
[...feature] FeatureElement | CompatibleFeatureArray

Example
The following statements are equivalent, and will all construct a new feature object including both ANY_DOCUMENT and ANY_WINDOW.

new JScrewIt.Feature("ANY_DOCUMENT", "ANY_WINDOW");
new JScrewIt.Feature(JScrewIt.Feature.ANY_DOCUMENT, JScrewIt.Feature.ANY_WINDOW);
new JScrewIt.Feature([JScrewIt.Feature.ANY_DOCUMENT, JScrewIt.Feature.ANY_WINDOW]);

feature.canonicalNames : Array.<string>

An array of all elementary feature names included in this feature object, without aliases and implied features.

Kind: instance property of Feature

feature.description : string | undefined

A short description of this feature object in plain English.

All predefined features have a description. If desired, custom features may be assigned a description, too.

Kind: instance property of Feature

feature.elementaryNames : Array.<string>

An array of all elementary feature names included in this feature object, without aliases.

Kind: instance property of Feature

feature.name : string | undefined

The primary name of this feature object, useful for identification purpose.

All predefined features have a name. If desired, custom features may be assigned a name, too.

Kind: instance property of Feature

feature.includes([...feature]) ⇒ boolean

Determines whether this feature object includes all of the specified features.

Kind: instance method of Feature
Returns: boolean - true if this feature object includes all of the specified features; otherwise, false. If no arguments are specified, the return value is true.

Param Type
[...feature] FeatureElement | CompatibleFeatureArray

feature.restrict(environment, [referenceFeatureObjs]) ⇒ Feature

Creates a new feature object from this feature by removing elementary features that are not available inside a particular environment.

This method is useful to selectively exclude features that are available inside a web worker.

Kind: instance method of Feature
Returns: Feature - A feature object.

Param Type Description
environment string The environment to which this feature should be restricted. Two environments are currently supported.
"forced-strict-mode"
Removes features that are not available in environments that require strict mode code.
"web-worker"
Removes features that are not available inside web workers.
[referenceFeatureObjs] Array.<Feature> An array of predefined feature objects, each corresponding to a particular engine in which the restriction should be enacted. If this parameter is omitted, the restriction is enacted in all engines.

feature.toString() ⇒ string

Returns a string representation of this feature object.

Kind: instance method of Feature
Returns: string - A string representation of this feature object.

Feature.ALL : object

A map of predefined feature objects accessed by name or alias.

For an exhaustive list of all features, see the Feature Reference.

Kind: static property of Feature
Example
This will produce an array with the names and aliases of all predefined features.

Object.keys(JScrewIt.Feature.ALL)

This will determine if a particular feature object is predefined or not.

featureObj === JScrewIt.Feature.ALL[featureObj.name]

Feature.areCompatible([features]) ⇒ boolean

Determines whether the specified features are compatible with each other.

Kind: static method of Feature
Returns: boolean - true if the specified features are compatible with each other; otherwise, false. If the array argument contains less than two features, the return value is true.

Param Type
[features] Array.<FeatureElement>

Example

// false: only one of "V8_SRC" or "IE_SRC" may be available.
JScrewIt.Feature.areCompatible(["V8_SRC", "IE_SRC"])
// true
JScrewIt.Feature.areCompatible([JScrewIt.Feature.DEFAULT, JScrewIt.Feature.FILL])

Feature.areEqual([...feature]) ⇒ boolean

Determines whether all of the specified features are equivalent.

Different features are considered equivalent if they include the same set of elementary features, regardless of any other difference.

Kind: static method of Feature
Returns: boolean - true if all of the specified features are equivalent; otherwise, false. If less than two arguments are specified, the return value is true.

Param Type
[...feature] FeatureElement | CompatibleFeatureArray

Example

// false
JScrewIt.Feature.areEqual(JScrewIt.Feature.CHROME, JScrewIt.Feature.FIREFOX)
// true
JScrewIt.Feature.areEqual("DEFAULT", [])

Feature.commonOf([...feature]) ⇒ Feature | null

Creates a new feature object equivalent to the intersection of the specified features.

Kind: static method of Feature
Returns: Feature | null - A feature object, or null if no arguments are specified.

Param Type
[...feature] FeatureElement | CompatibleFeatureArray

Example
This will create a new feature object equivalent to NAME.

var newFeature = JScrewIt.Feature.commonOf(["ATOB", "NAME"], ["NAME", "SELF"]);

This will create a new feature object equivalent to ANY_DOCUMENT. This is because both HTMLDOCUMENT and DOCUMENT imply ANY_DOCUMENT.

var newFeature = JScrewIt.Feature.commonOf("HTMLDOCUMENT", "DOCUMENT");

JScrewIt.encode(input, [options]) ⇒ string

Encodes a given string into JSFuck.

Kind: static method of JScrewIt
Returns: string - The encoded string.
Throws:

  • An Error is thrown under the following circumstances.
  • The specified string cannot be encoded with the specified options.
  • Some unknown features were specified.
  • A combination of mutually incompatible features was specified.
  • The option runAs (or wrapWith) was specified with an invalid value.

Also, an out of memory condition may occur when processing very large data.

Param Type Default Description
input string The string to encode.
[options] object { } An optional object specifying encoding options.
[options.features] FeatureElement | CompatibleFeatureArray JScrewIt.Feature.DEFAULT

Specifies the features available in the engines that evaluate the encoded output.

If this parameter is unspecified, JScrewIt.Feature.DEFAULT is assumed: this ensures maximum compatibility but also generates the largest code. To generate shorter code, specify all features available in all target engines explicitly.

[options.runAs] string "express-eval" This option controls the type of code generated from the given input. Allowed values are listed below.
"call"
Produces code evaluating to a call to a function whose body contains the specified input string.
"eval"
Produces code evaluating to the result of invoking eval with the specified input string as parameter.
"express"
Attempts to interpret the specified string as JavaScript code and produce functionally equivalent JSFuck code. Fails if the specified string cannot be expressed as JavaScript, or if no functionally equivalent JSFuck code can be generated.
"express-call"
Applies the code generation process of both "express" and "call" and returns the shortest output.
"express-eval"
Applies the code generation process of both "express" and "eval" and returns the shortest output.
"none" (default)
Produces JSFuck code that translates to the specified input string (except for trimmed parts when used in conjunction with the option trimCode). Unlike other methods, "none" does not generate executable code but just a plain string.
[options.trimCode] boolean false

If this parameter is truthy, lines in the beginning and in the end of the file containing nothing but space characters and JavaScript comments are removed from the generated output. A newline terminator in the last preserved line is also removed.

This option is especially useful to strip banner comments and trailing newline characters which are sometimes found in minified scripts.

Using this option may produce unexpected results if the input is not well-formed JavaScript code.

[options.wrapWith] string "express-eval" An alias for runAs.

FeatureElement : Feature | string

A feature object or name or alias of a predefined feature.

Kind: global typedef
Throws:

  • Error The specified value is neither a feature object nor a name or alias of a predefined feature.

CompatibleFeatureArray : Array.<FeatureElement>

An array containing any number of feature objects or names or aliases of predefined features, in no particular order.

All of the specified features need to be compatible, so that their union can be constructed.

Kind: global typedef
Throws:

  • Error The specified features are not compatible with each other.