Skip to content

Instantly share code, notes, and snippets.

@staltz
Last active May 6, 2024 03:12
Show Gist options
  • Save staltz/323c9e661214b588fe8f to your computer and use it in GitHub Desktop.
Save staltz/323c9e661214b588fe8f to your computer and use it in GitHub Desktop.
A node.js script to check how often are RxJS operators used
var operators = [
'\\.case',
'\\.create',
'\\.defer',
'\\.empty',
'\\.forkJoin',
'\\.from',
'\\.fromCallback',
'\\.fromEvent',
'\\.fromEventPattern',
'\\.fromNodeCallback',
'\\.fromPromise',
'\\.generate',
'\\.generateWithAbsoluteTime',
'\\.generateWithRelativeTime',
'\\.interval',
'\\.just',
'\\.mergeDelayError',
'\\.never',
'\\.of',
'\\.ofWithScheduler',
'\\.onErrorResumeNext',
'\\.pairs',
'\\.range',
'\\.spawn',
'\\.start',
'\\.startAsync',
'\\.throw',
'\\.timer',
'\\.toAsync',
'\\.using',
'\\.when',
'\\.wrap',
'\\.amb',
'\\.and',
'\\.asObservable',
'\\.average',
'\\.buffer',
'\\.bufferWithCount',
'\\.bufferWithTime',
'\\.bufferWithTimeOrCount',
'\\.catch',
'combineLatest',
'concat',
'\\.concatAll',
'\\.concatMap',
'\\.concatMapObserver',
'\\.connect',
'\\.controlled',
'\\.count',
'\\.debounce',
'\\.defaultIfEmpty',
'\\.delay',
'\\.delaySubscription',
'\\.dematerialize',
'\\.distinct',
'\\.distinctUntilChanged',
'\\.do',
'\\.doOnNext',
'\\.doOnError',
'\\.doOnCompleted',
'\\.doWhile',
'\\.elementAt',
'\\.every',
'\\.expand',
'\\.extend',
'\\.filter',
'\\.finally',
'\\.find',
'\\.findIndex',
'\\.first',
'\\.flatMap',
'\\.flatMapFirst',
'\\.flatMapLatest',
'\\.flatMapObserver',
'\\.flatMapWithMaxConcurrent',
'\\.forkJoin',
'\\.groupBy',
'\\.groupByUntil',
'\\.groupJoin',
'\\.ignoreElements',
'\\.includes',
'\\.indexOf',
'\\.isEmpty',
'\\.join',
'\\.jortSort',
'\\.jortSortUntil',
'\\.last',
'\\.lastIndexOf',
'\\.let',
'\\.manySelect',
'\\.map',
'\\.max',
'\\.maxBy',
'merge',
'\\.mergeAll',
'\\.min',
'\\.minBy',
'\\.multicast',
'\\.observeOn',
'\\.onErrorResumeNext',
'\\.pairwise',
'\\.partition',
'\\.pausable',
'\\.pausableBuffered',
'\\.pluck',
'\\.publish',
'\\.publishLast',
'\\.publishValue',
'\\.share',
'\\.shareReplay',
'\\.shareValue',
'\\.refCount',
'\\.reduce',
'\\.repeat',
'\\.repeatWhen',
'\\.replay',
'\\.retry',
'\\.retryWhen',
'\\.sample',
'\\.scan',
'\\.select',
'\\.selectConcat',
'\\.selectConcatObserver',
'\\.selectMany',
'\\.selectManyObserver',
'\\.sequenceEqual',
'\\.single',
'\\.singleInstance',
'\\.skip',
'\\.skipLast',
'\\.skipLastWithTime',
'\\.skipUntil',
'\\.skipUntilWithTime',
'\\.skipWhile',
'\\.slice',
'\\.some',
'\\.startWith',
'\\.subscribe',
'\\.subscribeOnNext',
'\\.subscribeOnError',
'\\.subscribeOnCompleted',
'\\.subscribeOn',
'\\.sum',
'\\.switch',
'\\.switchFirst',
'\\.take',
'\\.takeLast',
'\\.takeLastBuffer',
'\\.takeLastBufferWithTime',
'\\.takeLastWithTime',
'\\.takeUntil',
'\\.takeUntilWithTime',
'\\.takeWhile',
'\\.tap',
'\\.tapOnNext',
'\\.tapOnError',
'\\.tapOnCompleted',
'\\.throttle',
'\\.timeInterval',
'\\.timeout',
'\\.timeoutWithSelector',
'\\.timestamp',
'\\.toArray',
'\\.toMap',
'\\.toPromise',
'\\.toSet',
'\\.transduce',
'\\.where',
'\\.window',
'\\.windowWithCount',
'\\.windowWithTime',
'\\.windowWithTimeOrCount',
'\\.withLatestFrom',
'\\.zip',
'\\.zipIterable',
];
var fs = require('fs');
var dict = {};
var i;
for (i = operators.length - 1; i >= 0; i--) {
dict[operators[i]] = 0;
}
process.argv.shift();
process.argv.shift();
process.argv.forEach(function (filename) {
var content = fs.readFileSync(filename, 'utf8');
for (var i = operators.length - 1; i >= 0; i--) {
dict[operators[i]] += (content.match(new RegExp(operators[i] + '\\b', 'g')) || []).length;
}
});
// console.log(JSON.stringify(dict, null, ' '));
var ordered = [];
for (i = operators.length - 1; i >= 0; i--) {
ordered.push([ operators[i], dict[operators[i]] ])
}
ordered = ordered.sort(function compare(a, b) {
if (a[1] < b[1]) {
return -1;
}
if (a[1] > b[1]) {
return 1;
}
return 0;
});
for (i = ordered.length - 1; i >= 0; i--) {
if (ordered[i][1] > 0) {
console.log(ordered[i][0].replace('\\\.','') + '\n' + ordered[i][1] + '\n');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment