MCPcopy Create free account
hub / github.com/FSGModding/FSG_Mod_Assistant / countTextFile

Function countTextFile

test/tests/packagestat.js:33–61  ·  view source on GitHub ↗
(fileList, isJS = false)

Source from the content-addressed store, hash-verified

31}
32
33const countTextFile = (fileList, isJS = false) => {
34 return fileList.reduce((total, x) => {
35 const fileContents = fs.readFileSync(x.fullpath(), 'utf-8').replace(/\r/g, '')
36
37 let thisComment = (fileContents.match(/^[\t |]*\/\/.+\r*$/gm) ?? []).length
38 const thisBlank = (fileContents.match(/^[\t ]*\r*$/gm) || []).length
39 const thisTotal = fileContents.split('\n').length
40
41 if ( isJS ) {
42 const matches = fileContents.match(/(?<=\n|^|\n\s)\/\*.+?\*\//gs)
43 if ( matches ) {
44 for ( const thisMatch of matches ) {
45 for ( const thisCommentLine of thisMatch.split('\n') ) {
46 if ( thisCommentLine !== '' ) {
47 thisComment++
48 }
49 }
50 }
51 }
52 }
53
54 total.code += (thisTotal - thisComment - thisBlank)
55 total.comment += thisComment
56 total.blank += thisBlank
57 total.size += x.size
58 total.total++
59 return total
60 }, { blank : 0, code : 0, comment : 0, size : 0, total : 0 })
61}
62
63const padData = (data, pad = 0) => data === 0 ? ''.padStart(pad) : data.toString().padStart(pad)
64

Callers 1

countFilesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected