'Programming/node.js'에 해당되는 글 139건

  1. 2019.09.15 js nested function과 변수 scope
  2. 2019.09.10 node.js util.format / sprintf?
  3. 2019.09.10 node.js xpath 지원함수 목록
  4. 2019.08.21 node.js csv2json
  5. 2019.08.12 node.js regex
  6. 2019.08.08 node.js xpath 모듈
  7. 2019.08.07 xpath text()
  8. 2019.07.31 node.js readline과 r/w stream
  9. 2019.07.25 node.js xpath select() select1()
  10. 2019.07.25 node.js xpath apidoc
Programming/node.js2019. 9. 15. 18:30

함수 내부의 함수는

내부 함수가 포함된 영역의 변수까진 유효하게 건드릴수 있는 듯 하다.

[링크 : https://www.w3schools.com/js/js_function_closures.asp]

'Programming > node.js' 카테고리의 다른 글

postgres on node.js  (0) 2019.09.24
json2csv / node.js 에서 NULL 값 출력하기  (0) 2019.09.18
node.js util.format / sprintf?  (0) 2019.09.10
node.js xpath 지원함수 목록  (0) 2019.09.10
node.js csv2json  (0) 2019.08.21
Posted by 구차니
Programming/node.js2019. 9. 10. 12:45

sprintf() 처럼 %d로 치환해서 출력가능한 모듈이 util.format()으로 존재한다.

 

[링크 : https://nodejs.org/api/util.html#util_util_format_format_args]

'Programming > node.js' 카테고리의 다른 글

json2csv / node.js 에서 NULL 값 출력하기  (0) 2019.09.18
js nested function과 변수 scope  (0) 2019.09.15
node.js xpath 지원함수 목록  (0) 2019.09.10
node.js csv2json  (0) 2019.08.21
node.js regex  (0) 2019.08.12
Posted by 구차니
Programming/node.js2019. 9. 10. 10:24

count()가 잘 안되서 지원이 안되는건줄 알았는데 엉뚱한 경로를 해놓고 헤매고 있었다..

FunctionResolver.prototype.addStandardFunctions = function() {
this.functions["{}last"] = Functions.last;
this.functions["{}position"] = Functions.position;
this.functions["{}count"] = Functions.count;
this.functions["{}id"] = Functions.id;
this.functions["{}local-name"] = Functions.localName;
this.functions["{}namespace-uri"] = Functions.namespaceURI;
this.functions["{}name"] = Functions.name;
this.functions["{}string"] = Functions.string;
this.functions["{}concat"] = Functions.concat;
this.functions["{}starts-with"] = Functions.startsWith;
this.functions["{}contains"] = Functions.contains;
this.functions["{}substring-before"] = Functions.substringBefore;
this.functions["{}substring-after"] = Functions.substringAfter;
this.functions["{}substring"] = Functions.substring;
this.functions["{}string-length"] = Functions.stringLength;
this.functions["{}normalize-space"] = Functions.normalizeSpace;
this.functions["{}translate"] = Functions.translate;
this.functions["{}boolean"] = Functions.boolean_;
this.functions["{}not"] = Functions.not;
this.functions["{}true"] = Functions.true_;
this.functions["{}false"] = Functions.false_;
this.functions["{}lang"] = Functions.lang;
this.functions["{}number"] = Functions.number;
this.functions["{}sum"] = Functions.sum;
this.functions["{}floor"] = Functions.floor;
this.functions["{}ceiling"] = Functions.ceiling;
this.functions["{}round"] = Functions.round;
};

[링크 : https://github.com/goto100/xpath/blob/master/xpath.js]

'Programming > node.js' 카테고리의 다른 글

js nested function과 변수 scope  (0) 2019.09.15
node.js util.format / sprintf?  (0) 2019.09.10
node.js csv2json  (0) 2019.08.21
node.js regex  (0) 2019.08.12
node.js xpath 모듈  (0) 2019.08.08
Posted by 구차니
Programming/node.js2019. 8. 21. 18:23

csv 파일을 받아서(파일명으로만) 읽어온 뒤 array로 만들어 주는 참한 녀석

(스트림으로 읽는진 모르겠어서 대용량 처리 가능한진 모르겠다)

 

const csvFilePath = 'test.csv'
const csv = require('csvtojson')
csv()
    .fromFile(csvFilePath)
    .then((jsonObj) => {
        jsonObj.forEach(ele => {
            // console.log(ele.idx)
            // console.log(ele.disease_name)
            // console.log(ele.doid)
            // console.log(ele.refsite)
            // console.log(ele.ref_id)

            var dis = ele.disease_name.split(';')
            var ret = "";
            // console.log(dis)
            // console.log(dis.length)
            if(dis.length > 1)
            {
                dis.forEach(ele2 => {
                    ret = '"' + ele.idx + '"';
                    ret += ","
                    ret += '"' + ele2 + '"';
                    ret += ","
                    ret += '"' + ele.doid + '"';
                    ret += ","
                    ret += '"' + ele.refsite + '"';
                    ret += ","
                    ret += '"' + ele.ref_id + '"';
                    console.log(ret)
                })
            }
            else{
                ret = '"' + ele.idx + '"';
                ret += ","
                ret += '"' + ele.disease_name + '"';
                ret += ","
                ret += '"' + ele.doid + '"';
                ret += ","
                ret += '"' + ele.refsite + '"';
                ret += ","
                ret += '"' + ele.ref_id + '"';
                console.log(ret)
            }
            
        })

    })

[링크 : https://www.npmjs.com/package/csvtojson]

'Programming > node.js' 카테고리의 다른 글

node.js util.format / sprintf?  (0) 2019.09.10
node.js xpath 지원함수 목록  (0) 2019.09.10
node.js regex  (0) 2019.08.12
node.js xpath 모듈  (0) 2019.08.08
xpath text()  (0) 2019.08.07
Posted by 구차니
Programming/node.js2019. 8. 12. 16:57

별다른 모듈 끌어오지 않아도 기본으로

new RegExp()를 통해 생성이 가능하다.

 

아래는 파일명에서 YYYY-MM 으로 된 녀석을 검색하는 예제

음.. 근데 딱 그 부분만 빼내는 법은 없나?

> var regex =  new RegExp('[0-9]{4}-[0-9]{2}')
undefined
> regex
/[0-9]{4}-[0-9]{2}/
> var fn = "ClinVarFullRelease_2019-07.xml"
undefined
fn.match(regex);
[ '2019-07', index: 19, input: 'ClinVarFullRelease_2019-07.xml' ]

[링크 : https://stackoverflow.com/questions/5675315/node-js-regular-expression-to-get-from-and-to]

 

+

regex.exec(fn)

[링크 : https://opentutorials.org/course/50/43]

 

+

()로 묶으면 완전히 매칭되는 부분만 결과를 돌려준다.

> var regex =  new RegExp('([0-9]{4}-[0-9]{2})')
undefined
fn.match(regex);
[ '2019-07',
  '2019-07',
  index: 19,
  input: 'ClinVarFullRelease_2019-07.xml' ]

[링크 : https://bradbury.tistory.com/47]

'Programming > node.js' 카테고리의 다른 글

node.js xpath 지원함수 목록  (0) 2019.09.10
node.js csv2json  (0) 2019.08.21
node.js xpath 모듈  (0) 2019.08.08
xpath text()  (0) 2019.08.07
node.js readline과 r/w stream  (0) 2019.07.31
Posted by 구차니
Programming/node.js2019. 8. 8. 11:04

이것저것 테스트 하다가 가장 무난한게 select1 인것 같고

검색이 되지 않으면 탭이나 콤마를

검색이 되었으나 값의 저장위치에 따라 value와 firstChild.data로 저장이 된다.

firstChild.data는 element 자체의 내용(content라고 해야하나 머라고 해야하나?)이 저장되는 장소이다.

 

var result_attr = xpath.select1(ele, doc);
                    // var result_ele = xpath.select(ele, doc);

                    if (result_attr != undefined) {
                        if (result_attr.value != undefined) {
                            // record += (result_attr.firstChild + delimiter)
                            record += ('"' + result_attr.value + '"' + delimiter)
                            // console.log(result_attr.value);
                        }
                        else {
                            record += ('"' + result_attr.firstChild.data + '"' + delimiter)
                            // console.log(result_attr.firstChild.data);
                        }
                    }
                    else {
                        record += delimiter;
                    }

 

 

 

'Programming > node.js' 카테고리의 다른 글

node.js csv2json  (0) 2019.08.21
node.js regex  (0) 2019.08.12
xpath text()  (0) 2019.08.07
node.js readline과 r/w stream  (0) 2019.07.31
node.js xpath select() select1()  (0) 2019.07.25
Posted by 구차니
Programming/node.js2019. 8. 7. 23:15

<element>text</element>

에서 text만 꺼내주는 함수(?)

'Programming > node.js' 카테고리의 다른 글

node.js regex  (0) 2019.08.12
node.js xpath 모듈  (0) 2019.08.08
node.js readline과 r/w stream  (0) 2019.07.31
node.js xpath select() select1()  (0) 2019.07.25
node.js xpath apidoc  (0) 2019.07.25
Posted by 구차니
Programming/node.js2019. 7. 31. 18:12

일단은.. 8기가 짜리 파일을 잘 토막쳐서 읽고 있다.

예전에는 멀 잘못했는지 오래걸리기도 했고, 조금 읽다 보면 버버버버벅했는데

스트림으로 변경하고 나니 속도 저하도 없고

메모리 사용율 문제나 크래시도 발생하지 않고 있다.

 

다만.. readline 모듈의 경우 output을 process.stdout으로 해주면 프롬프트랑 섞이면서 난리나고

output을 다른 파일로 연결을 하는법을 아직 찾지 못해 헤매는 중..

(그냥 다른 파일로 직접 쓰는 중)

'Programming > node.js' 카테고리의 다른 글

node.js xpath 모듈  (0) 2019.08.08
xpath text()  (0) 2019.08.07
node.js xpath select() select1()  (0) 2019.07.25
node.js xpath apidoc  (0) 2019.07.25
node.js readline()  (0) 2019.06.28
Posted by 구차니
Programming/node.js2019. 7. 25. 14:41

select1()은 attribute 빼낼때 .value로 쓸수 있고

select()는 element 단위로 빼낼때 쓰는 듯

 

xpath 에서 attribute 빼내려면

/Ele@Attr이 아니라

/Ele/@Attr로 해야지 정상적으로 인식한다.

'Programming > node.js' 카테고리의 다른 글

xpath text()  (0) 2019.08.07
node.js readline과 r/w stream  (0) 2019.07.31
node.js xpath apidoc  (0) 2019.07.25
node.js readline()  (0) 2019.06.28
node.js 메모리 사용 가능 용량 늘리기  (0) 2019.06.21
Posted by 구차니
Programming/node.js2019. 7. 25. 13:32

'Programming > node.js' 카테고리의 다른 글

node.js readline과 r/w stream  (0) 2019.07.31
node.js xpath select() select1()  (0) 2019.07.25
node.js readline()  (0) 2019.06.28
node.js 메모리 사용 가능 용량 늘리기  (0) 2019.06.21
node.js fs.createreadstream highWaterMark  (0) 2019.06.19
Posted by 구차니