Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
file?: string,
options?: any,
): ISortResult {
const items = addFallback(style, file, options || {})(StyleAPI);
const buckets: Array> = items.map(() => []);
const imports = parser.parseImports(code, {
file,
});
if (imports.length === 0) {
return {code, changes: []};
}
const eol = detectNewline.graceful(code);
const changes: Array = [];
// Fill buckets
for (const imported of imports) {
let sortedImport = imported;
const index = items.findIndex(item => {
sortedImport = sortNamedMembers(imported, item.sortNamedMembers);
return !!item.match && item.match!(sortedImport);
});
if (index !== -1) {
buckets[index].push(sortedImport);
}
}
function getCommentFormatter(file) {
var extension = file.relative.split('.').pop();
var fileContents = file.contents.toString();
var newline = detectNewline.graceful(fileContents || '');
var commentFormatter = commentFormatters.default;
if (file.sourceMap.preExistingComment) {
commentFormatter = (commentFormatters[extension] || commentFormatter).bind(undefined, '', newline);
debug(function() {
return 'preExistingComment commentFormatter ' + commentFormatter.name;
});
} else {
commentFormatter = (commentFormatters[extension] || commentFormatter).bind(undefined, newline, newline);
}
debug(function() {
return 'commentFormatter ' + commentFormatter.name;
});
return commentFormatter;
encode( str, sourceUrl ) {
const eol = detectNewline.graceful( str );
let headers = [
'Version:0.9',
'StartHTML:00000000',
'EndHTML:00000000',
'StartFragment:00000000',
'EndFragment:00000000'
];
if ( sourceUrl ) {
headers.push( 'SourceURL:' + sourceUrl );
}
str = this._calculateHeaders( headers, str, eol );
headers.push( str );
function editStringJSON(json, over) {
if (typeof json === 'string') {
const { indent } = detectIndent(json)
const endCharacters = json.slice(-1) === '\n' ? '\n' : ''
const newline = detectNewline(json)
json = JSON.parse(json)
let result = JSON.stringify(over(json), null, indent) + endCharacters
if (newline === '\r\n') {
result = result.replace(/\n/g, newline)
}
return result
}
return over(json)
}
if (options == null) {
options = {};
};
options.start_comment = options.start_comment == null ? 'test-code' : options.start_comment;
options.end_comment = options.end_comment == null ? 'end-test-code' : options.end_comment;
options.keep_comments = options.keep_comments == null ? false : options.keep_comments;
options.comment_all = options.comment_all == null ? false : options.comment_all;
if (options.comment_all){
var pattern = options.pattern || new RegExp("([\\t ]*\\/\\* ?" + options.start_comment + ")[\\s\\S]*?(" + options.end_comment + " ?\\*\\/[\\t ]*\\r?\\n?)", "g");
} else{
var pattern = options.pattern || new RegExp("([\\t ]*\\/\\* ?" + options.start_comment + " ?\\*\\/)[\\s\\S]*?(\\/\\* ?" + options.end_comment + " ?\\*\\/[\\t ]*\\r?\\n?)", "g");
}
var eol = detectNewline.graceful(String(file.contents));
if (isBuffer) {
if(options.keep_comments){
file.contents = Buffer.from(String(file.contents).replace(pattern, "$1" + eol + "$2"));
}
else{
file.contents = Buffer.from(String(file.contents).replace(pattern, ""));
}
return callback(null, file);
}
callback(null, file);
};