Home Manual Reference Source Test
import NewlinesTransformer from 'atscm/src/transform/Newlines.js'
public class | source

NewlinesTransformer

Extends:

src/lib/transform/PartialTransformer.js~PartialTransformer → NewlinesTransformer

A transformer that handles newline characters in files. During a pull, all breaks are converted the OS-native EOL character and (optionally) a trailing newline is added (for better git diffs). On push, CRLF characters are used and those trailing newlines are removed again.

Constructor Summary

Public Constructor
public

constructor(options: Object)

Creates a new newline transformer.

Member Summary

Public Members
public get

true because we want to transform all files.

Private Members
private

If newlines should be added to pulled files.

Method Summary

Public Methods
public

Returns true for all files except binary ones.

public

transformFromDB(file: AtviseFile, enc: string, callback: function(err: ?Error, data: ?AtviseFile))

Adds converts line breaks to the current OS's native EOL characters and adds trailing newlines.

public

transformFromFilesystem(file: AtviseFile, enc: string, callback: function(err: ?Error, data: ?AtviseFile))

Removes trailing newlines and converts all breaks to CRLF.

Public Constructors

public constructor(options: Object) source

Creates a new newline transformer.

Params:

NameTypeAttributeDescription
options Object
  • optional
  • default: {}

The options to use.

options.trailingNewlines boolean
  • optional

If trailing newlines should be added. Pass true for better git diffs.

Public Members

public get transformsReferenceConfigFiles: boolean source

true because we want to transform all files.

Private Members

private _addTrailingNewlines: boolean source

If newlines should be added to pulled files.

Public Methods

public shouldBeTransformed(file: AtviseFile): boolean source

Returns true for all files except binary ones.

Params:

NameTypeAttributeDescription
file AtviseFile

The file being transformed.

Return:

boolean

Always true.

Test:

public transformFromDB(file: AtviseFile, enc: string, callback: function(err: ?Error, data: ?AtviseFile)) source

Adds converts line breaks to the current OS's native EOL characters and adds trailing newlines.

Params:

NameTypeAttributeDescription
file AtviseFile

The file being transformed.

enc string

The encoding used.

callback function(err: ?Error, data: ?AtviseFile)

Called with the corrected file.

Test:

public transformFromFilesystem(file: AtviseFile, enc: string, callback: function(err: ?Error, data: ?AtviseFile)) source

Removes trailing newlines and converts all breaks to CRLF.

Params:

NameTypeAttributeDescription
file AtviseFile

The file being transformed.

enc string

The encoding used.

callback function(err: ?Error, data: ?AtviseFile)

Called with resulting file.

Test: