math.js의 디자인을 개선하려고합니다.npm 모듈의 디자인 향상
개념이 많다는, 나는 작은 것들로 큰 모듈을 분리하는 것을 시도하고있다 :
내가 lib/index.js
에서 단지 하나의 수입을 가지고, 그것은 작동하는 것 같군 :
module.exports = require('./trigonometric')
하지만 두 라이너가 (또는 그 이상)의 경우,
module.exports = require('./trigonometric')
module.exports = require('./unit')
아래의 오류와 같이 오류가 발생합니다.
모든 기능이 하나의 파일에 있었지만 엄청나게 커지는 것을 보았으므로 수학 기능의 여러 영역 (예 : 단위, 삼각법 등)간에 양호한 구분이 이루어지기로 결정했습니다.
This이 노력의 첫 번째 커밋입니다. 나는 수입을 확인할 수 없기 때문에 당신이 볼 수있는 나는, 거기에 붙어 :
Failures:
1) #math.js Testing ceil function
Message:
TypeError: math.ceil is not a function
Stacktrace:
TypeError: math.ceil is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:419)
2) #math.js Testing round function
Message:
TypeError: math.round is not a function
Stacktrace:
TypeError: math.round is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:755)
3) #math.js Testing fround function
Message:
TypeError: math.fround is not a function
Stacktrace:
TypeError: math.fround is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:1104)
4) #math.js Testing floor function
Message:
TypeError: math.floor is not a function
Stacktrace:
TypeError: math.floor is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:1469)
5) #math.js Testing random function
Message:
TypeError: math.random is not a function
Stacktrace:
TypeError: math.random is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:1817)
6) #math.js Testing sign function
Message:
TypeError: math.sign is not a function
Stacktrace:
TypeError: math.sign is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:2025)
7) #math.js Testing drop digit functions
Message:
TypeError: math.dropFirstDigit is not a function
Stacktrace:
TypeError: math.dropFirstDigit is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:2366)
8) #math.js Testing format function
Message:
TypeError: math.format is not a function
Stacktrace:
TypeError: math.format is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:3022)
9) #math.js Testing abs function
Message:
TypeError: math.abs is not a function
Stacktrace:
TypeError: math.abs is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:3389)
10) #math.js Testing array functions
Message:
TypeError: math.randomElement is not a function
Stacktrace:
TypeError: math.randomElement is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:3753)
11) #math.js Testing pow function
Message:
TypeError: math.pow is not a function
Stacktrace:
TypeError: math.pow is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:4236)
12) #math.js Testing square function
Message:
TypeError: math.square is not a function
Stacktrace:
TypeError: math.square is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:4502)
13) #math.js Testing imul function
Message:
TypeError: math.imul is not a function
Stacktrace:
TypeError: math.imul is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:4770)
14) #math.js Testing cube function
Message:
TypeError: math.cube is not a function
Stacktrace:
TypeError: math.cube is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:5037)
15) #math.js Testing sqrt function
Message:
TypeError: math.sqrt is not a function
Stacktrace:
TypeError: math.sqrt is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:5299)
16) #math.js Testing cbrt function
Message:
TypeError: math.cbrt is not a function
Stacktrace:
TypeError: math.cbrt is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:5561)
17) #math.js Testing exp function
Message:
TypeError: math.exp is not a function
Stacktrace:
TypeError: math.exp is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:5825)
18) #math.js Testing exp function
Message:
TypeError: math.expm1 is not a function
Stacktrace:
TypeError: math.expm1 is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:6099)
19) #math.js Testing between function
Message:
TypeError: math.between is not a function
Stacktrace:
TypeError: math.between is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:6381)
20) #math.js Testing trunv function
Message:
TypeError: math.trunc is not a function
Stacktrace:
TypeError: math.trunc is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:6743)
21) #math.js Testing temperature functions
Message:
TypeError: math.toFahrenheit is not a function
Stacktrace:
TypeError: math.toFahrenheit is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:7097)
22) #math.js Testing hypot function
Message:
TypeError: math.hypot is not a function
Stacktrace:
TypeError: math.hypot is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:7380)
23) #math.js Testing greatestCommonDivisor function
Message:
TypeError: math.greatestCommonDivisor is not a function
Stacktrace:
TypeError: math.greatestCommonDivisor is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:7756)
24) #math.js Testing factorial function
Message:
TypeError: math.factorial is not a function
Stacktrace:
TypeError: math.factorial is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:8063)
25) #math.js Testing prime function
Message:
TypeError: math.isPrime is not a function
Stacktrace:
TypeError: math.isPrime is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:8491)
26) #math.js Testing even function
Message:
TypeError: math.isEven is not a function
Stacktrace:
TypeError: math.isEven is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:8763)
27) #math.js Testing odd function
Message:
TypeError: math.isOdd is not a function
Stacktrace:
TypeError: math.isOdd is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:9033)
28) #math.js Common log tests
Message:
TypeError: math.log is not a function
Stacktrace:
TypeError: math.log is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:9298)
29) #math.js Common log2 tests
Message:
TypeError: math.log2 is not a function
Stacktrace:
TypeError: math.log2 is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:9727)
30) #math.js Common log10 tests
Message:
TypeError: math.log10 is not a function
Stacktrace:
TypeError: math.log10 is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:10308)
31) #math.js Common log1p tests
Message:
TypeError: math.log1p is not a function
Stacktrace:
TypeError: math.log1p is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:10824)
32) #math.js Testing unit converters
Message:
TypeError: math.feetToInches is not a function
Stacktrace:
TypeError: math.feetToInches is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:11188)
33) #math.js Testing trigonometric functions
Message:
TypeError: math.sin is not a function
Stacktrace:
TypeError: math.sin is not a function
at jasmine.Spec.<anonymous> (/Users/toubou91/git/math.js/spec/math-spec.js:9:12715)
Finished in 0.024 seconds
33 tests, 33 assertions, 33 fai
나는 두 디렉토리에 같은 이름 (하는 index.js)를 사용하고 있기 때문에 될 수 있다고 의심 (삼각 단위) , 그래도 나는 그것을 작동하게 만들 수 없다.
아이디어가 있으십니까?
와우, 감사합니다. @MikaS! 더 나은 디자인 선택으로 무엇을 제안 하시겠습니까? 내 테스트를 더 깨끗하게 유지하기 때문에 첫 번째 옵션으로 갈 것입니다. – thodorisbais
@ 처음에는 생각했습니다. mathjs 객체에 하위 객체가 너무 길어집니다. 너무 많은 함수가있는 지점에 도달하면 중요하지 않은 함수를 하위 객체에 넣을 수 있습니다. – MikaS
어떨까요? module.exports = Object.assign ( require ('./ unit'), require ('./ trigonometric') ); – thodorisbais