-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathUserRightsDiffStringProcessor.js
More file actions
32 lines (27 loc) · 1.08 KB
/
Copy pathUserRightsDiffStringProcessor.js
File metadata and controls
32 lines (27 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
export class UserRightsDiffStringProcessor {
/** Returns 2 arrays. For example: [ [ 'autopatrolled' ], [ 'sysop' ] ] */
logEntryStringToArrays( text ) {
const fromMatches = /revoked ([^;(]+)/.exec( text );
const fromMatch = fromMatches && fromMatches[ 1 ];
const from = this.permStringToArray( fromMatch );
const toMatches = /granted ([^;(]+)/.exec( text );
const toMatch = toMatches && toMatches[ 1 ];
let to = this.permStringToArray( toMatch );
const autoUpdatedMatches = /automatically updated .+ to ([a-z ]+)/.exec( text );
const autoUpdateMatch = autoUpdatedMatches && autoUpdatedMatches[ 1 ];
const autoUpdate = this.permStringToArray( autoUpdateMatch );
// array_merge( to, autoUpdate )
to = to.concat( autoUpdate.filter( ( x ) => !to.includes( x ) ) );
return [ from, to ];
}
permStringToArray( string ) {
if ( string === null ) {
return [];
}
// trim(), to get the space between the last perm and a parenthesis
string = string.trim();
string = string.replace( /^(.*) and (.*?$)/, '$1, $2' );
const array = string.split( ', ' );
return array;
}
}