Skip to content

Commit bd0e0bf

Browse files
style(prettier): added prettier and made eslint stricter
1 parent bbc1552 commit bd0e0bf

File tree

6 files changed

+214
-42
lines changed

6 files changed

+214
-42
lines changed

Diff for: .eslintrc

+60-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,65 @@
11
{
2-
"extends": "standard",
2+
"extends": [
3+
"standard",
4+
"prettier-standard"
5+
],
6+
"plugins": [
7+
"ramda"
8+
],
9+
"parser": "babel-eslint",
310
"rules": {
11+
"prefer-template": "error",
12+
"prettier/prettier": [
13+
"error",
14+
{
15+
"printWidth": 120
16+
}
17+
],
418
"no-var": "error",
5-
"prefer-const": "error"
19+
"prefer-const": "error",
20+
"import/no-unresolved": "error",
21+
"import/named": "error",
22+
"import/namespace": "error",
23+
"import/default": "error",
24+
"import/export": "error",
25+
"import/no-named-as-default": "warn",
26+
"import/no-named-as-default-member": "off",
27+
"import/no-duplicates": "warn",
28+
"import/order": "error",
29+
"ramda/always-simplification": "error",
30+
"ramda/any-pass-simplification": "error",
31+
"ramda/both-simplification": "error",
32+
"ramda/complement-simplification": "error",
33+
"ramda/compose-pipe-style": "off",
34+
"ramda/compose-simplification": "error",
35+
"ramda/cond-simplification": "error",
36+
"ramda/either-simplification": "error",
37+
"ramda/eq-by-simplification": "error",
38+
"ramda/filter-simplification": "error",
39+
"ramda/if-else-simplification": "error",
40+
"ramda/map-simplification": "error",
41+
"ramda/merge-simplification": "error",
42+
"ramda/no-redundant-and": "error",
43+
"ramda/no-redundant-not": "error",
44+
"ramda/no-redundant-or": "error",
45+
"ramda/pipe-simplification": "error",
46+
"ramda/prefer-both-either": "error",
47+
"ramda/prefer-complement": "error",
48+
"ramda/prefer-ramda-boolean": "error",
49+
"ramda/prop-satisfies-simplification": "error",
50+
"ramda/reduce-simplification": "error",
51+
"ramda/reject-simplification": "error",
52+
"ramda/set-simplification": "error",
53+
"ramda/unless-simplification": "error",
54+
"ramda/when-simplification": "error"
55+
},
56+
"settings": {
57+
"import/resolver": {
58+
"node": {
59+
"extensions": [
60+
".js"
61+
]
62+
}
63+
}
664
}
765
}

Diff for: .prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"printWidth": 120
5+
}

Diff for: dist/audioparam-getvalueattime.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+7
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,21 @@
3434
"devDependencies": {
3535
"@babel/core": "^7.6.0",
3636
"@babel/preset-env": "^7.6.0",
37+
"babel-eslint": "^10.0.3",
3738
"cz-conventional-changelog": "^3.0.2",
3839
"eslint": "^6.4.0",
40+
"eslint-config-prettier": "^6.3.0",
41+
"eslint-config-prettier-standard": "^3.0.1",
3942
"eslint-config-standard": "^14.1.0",
4043
"eslint-plugin-import": "^2.18.2",
4144
"eslint-plugin-node": "^10.0.0",
45+
"eslint-plugin-prettier": "^3.1.1",
4246
"eslint-plugin-promise": "^4.2.1",
47+
"eslint-plugin-ramda": "^2.5.1",
4348
"eslint-plugin-standard": "^4.0.1",
4449
"pre-commit": "^1.2.2",
50+
"prettier": "^1.18.2",
51+
"prettier-config-standard": "^1.0.1",
4552
"rimraf": "^3.0.0",
4653
"rollup": "^1.21.4",
4754
"rollup-plugin-babel": "^4.3.3",

Diff for: src/helpers.js

+131-36
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,52 @@
11
/* global BaseAudioContext, AudioContext, webkitAudioContext, AudioParam */
22

3-
import { isEmpty, prop, compose, complement, clamp, isNil, reject, append, equals, lt, __, gte, either, filter, both, reduce, max, pluck, unless, find, propEq, min, gt, last, has, all, props, add, length, head, without, sortBy, any } from 'ramda'
4-
import { getLinearRampToValueAtTime, getExponentialRampToValueAtTime, getTargetValueAtTime, getValueCurveAtTime } from 'pseudo-audio-param/lib/expr.js'
3+
import {
4+
isEmpty,
5+
prop,
6+
compose,
7+
complement,
8+
clamp,
9+
isNil,
10+
reject,
11+
append,
12+
equals,
13+
lt,
14+
__,
15+
gte,
16+
either,
17+
filter,
18+
both,
19+
reduce,
20+
max,
21+
pluck,
22+
unless,
23+
find,
24+
propEq,
25+
min,
26+
gt,
27+
last,
28+
has,
29+
all,
30+
props,
31+
length,
32+
head,
33+
without,
34+
sortBy,
35+
any,
36+
sum
37+
} from 'ramda'
38+
import {
39+
getLinearRampToValueAtTime,
40+
getExponentialRampToValueAtTime,
41+
getTargetValueAtTime,
42+
getValueCurveAtTime
43+
} from 'pseudo-audio-param/lib/expr.js'
544

6-
const AudioContextClass = isNil(window.BaseAudioContext) ? (isNil(window.AudioContext) ? webkitAudioContext : AudioContext) : BaseAudioContext
45+
const AudioContextClass = isNil(window.BaseAudioContext)
46+
? isNil(window.AudioContext)
47+
? webkitAudioContext
48+
: AudioContext
49+
: BaseAudioContext
750

851
const maxAll = reduce(max, -Infinity)
952
const minAll = reduce(min, Infinity)
@@ -46,16 +89,39 @@ const evaluateSchedulement = (scheduledChanges, initialValue, initialTime, endTi
4689
const endTimeOfLastChange = isNil(lastChangeBeforeTime) ? initialTime : lastChangeBeforeTime.targetTime
4790
switch (firstChangeAfterTime.method) {
4891
case 'linearRampToValueAtTime':
49-
value = getLinearRampToValueAtTime(endTime, value, getTargetValueOfChange(firstChangeAfterTime), endTimeOfLastChange, firstChangeAfterTime.targetTime)
92+
value = getLinearRampToValueAtTime(
93+
endTime,
94+
value,
95+
getTargetValueOfChange(firstChangeAfterTime),
96+
endTimeOfLastChange,
97+
firstChangeAfterTime.targetTime
98+
)
5099
break
51100
case 'exponentialRampToValueAtTime':
52-
value = getExponentialRampToValueAtTime(endTime, value, getTargetValueOfChange(firstChangeAfterTime), endTimeOfLastChange, firstChangeAfterTime.targetTime)
101+
value = getExponentialRampToValueAtTime(
102+
endTime,
103+
value,
104+
getTargetValueOfChange(firstChangeAfterTime),
105+
endTimeOfLastChange,
106+
firstChangeAfterTime.targetTime
107+
)
53108
break
54109
case 'setTargetAtTime':
55-
value = getTargetValueAtTime(endTime, value, firstChangeAfterTime.params[0], firstChangeAfterTime.params[1], firstChangeAfterTime.params[2])
110+
value = getTargetValueAtTime(
111+
endTime,
112+
value,
113+
firstChangeAfterTime.params[0],
114+
firstChangeAfterTime.params[1],
115+
firstChangeAfterTime.params[2]
116+
)
56117
break
57118
case 'setValueCurveAtTime':
58-
value = getValueCurveAtTime(endTime, firstChangeAfterTime.params[0], firstChangeAfterTime.params[1], firstChangeAfterTime.params[2])
119+
value = getValueCurveAtTime(
120+
endTime,
121+
firstChangeAfterTime.params[0],
122+
firstChangeAfterTime.params[1],
123+
firstChangeAfterTime.params[2]
124+
)
59125
break
60126
}
61127
}
@@ -66,13 +132,12 @@ const evaluateSchedulement = (scheduledChanges, initialValue, initialTime, endTi
66132
const scheduleChange = (audioParam, method, params, targetTime) => {
67133
const now = audioParam._ctx.currentTime
68134

69-
const outdatedSchedulements = filter(compose(
70-
both(
71-
gte(__, audioParam._valueWasLastSetAt),
72-
lt(__, now)
73-
),
74-
prop('targetTime')
75-
))(audioParam._scheduledChanges)
135+
const outdatedSchedulements = filter(
136+
compose(
137+
both(gte(__, audioParam._valueWasLastSetAt), lt(__, now)),
138+
prop('targetTime')
139+
)
140+
)(audioParam._scheduledChanges)
76141

77142
if (!isEmpty(outdatedSchedulements)) {
78143
audioParam._valueWasLastSetAt = compose(
@@ -91,17 +156,22 @@ const scheduleChange = (audioParam, method, params, targetTime) => {
91156
targetTime: clamp(now, Infinity, targetTime)
92157
})
93158
),
94-
reject(compose(
95-
either(
96-
(method === 'cancelScheduledValues' ? gte(__, targetTime) : equals(__, targetTime)),
97-
lt(__, now)
98-
),
99-
prop('targetTime')
100-
))
159+
reject(
160+
compose(
161+
either(method === 'cancelScheduledValues' ? gte(__, targetTime) : equals(__, targetTime), lt(__, now)),
162+
prop('targetTime')
163+
)
164+
)
101165
)(audioParam._scheduledChanges)
102166

103167
if (method === 'cancelAndHoldAtTime') {
104-
const events = filter(compose(gte(__, targetTime), prop('targetTime')), audioParam._scheduledChanges)
168+
const events = filter(
169+
compose(
170+
gte(__, targetTime),
171+
prop('targetTime')
172+
),
173+
audioParam._scheduledChanges
174+
)
105175

106176
if (!isEmpty(events)) {
107177
let event
@@ -118,18 +188,37 @@ const scheduleChange = (audioParam, method, params, targetTime) => {
118188
event.targetTime = targetTime
119189
switch (event.method) {
120190
case 'linearRampToValueAtTime':
121-
event.params = [getLinearRampToValueAtTime(targetTime, audioParam._value, event.params[0], audioParam._valueWasLastSetAt, event.params[1]), targetTime]
191+
event.params = [
192+
getLinearRampToValueAtTime(
193+
targetTime,
194+
audioParam._value,
195+
event.params[0],
196+
audioParam._valueWasLastSetAt,
197+
event.params[1]
198+
),
199+
targetTime
200+
]
122201
break
123202
case 'exponentialRampToValueAtTime':
124-
event.params = [getExponentialRampToValueAtTime(targetTime, audioParam._value, event.params[0], audioParam._valueWasLastSetAt, event.params[1]), targetTime]
203+
event.params = [
204+
getExponentialRampToValueAtTime(
205+
targetTime,
206+
audioParam._value,
207+
event.params[0],
208+
audioParam._valueWasLastSetAt,
209+
event.params[1]
210+
),
211+
targetTime
212+
]
125213
break
126-
case 'setValueCurveAtTime': {
127-
// const [values, startTime, duration] = event.params
128-
const [values, startTime] = event.params
129-
const newDuration = targetTime - startTime
130-
const newValues = values // TODO
131-
event.params = [newValues, startTime, newDuration]
132-
}
214+
case 'setValueCurveAtTime':
215+
{
216+
// const [values, startTime, duration] = event.params
217+
const [values, startTime] = event.params
218+
const newDuration = targetTime - startTime
219+
const newValues = values // TODO
220+
event.params = [newValues, startTime, newDuration]
221+
}
133222
break
134223
}
135224
}
@@ -149,7 +238,13 @@ const hasScheduledChanges = compose(
149238
)
150239

151240
const hasScheduledChangesAtTime = (audioParam, time) => {
152-
return any(compose(gt(__, time), prop('targetTime')), audioParam._scheduledChanges)
241+
return any(
242+
compose(
243+
gte(__, time),
244+
prop('targetTime')
245+
),
246+
audioParam._scheduledChanges
247+
)
153248
}
154249

155250
const getValueAtTime = (audioParam, time) => {
@@ -169,7 +264,7 @@ const getValueAtTime = (audioParam, time) => {
169264
const bindContextToParams = (creatorName, params) => {
170265
const originalFn = AudioContextClass.prototype[creatorName]
171266
if (!isNil(originalFn)) {
172-
AudioContextClass.prototype[creatorName] = function (...args) {
267+
AudioContextClass.prototype[creatorName] = function(...args) {
173268
const ctx = this
174269
const node = originalFn.apply(ctx, args)
175270
params.forEach(param => {
@@ -190,11 +285,11 @@ const bindContextToParams = (creatorName, params) => {
190285
const bindSchedulerToParamMethod = (methodName, timeArgIndexes = []) => {
191286
const originalFn = AudioParam.prototype[methodName]
192287
if (!isNil(originalFn)) {
193-
AudioParam.prototype[methodName] = function (...args) {
288+
AudioParam.prototype[methodName] = function(...args) {
194289
const audioParam = this
195290
let targetTime = Infinity
196291
if (!isEmpty(timeArgIndexes) && all(has(__, args), timeArgIndexes)) {
197-
targetTime = reduce(add, 0, props(timeArgIndexes, args))
292+
targetTime = sum(props(timeArgIndexes, args))
198293
}
199294
scheduleChange(audioParam, methodName, args, targetTime)
200295
originalFn.apply(audioParam, args)
@@ -208,7 +303,7 @@ const bindSchedulerToParamMethod = (methodName, timeArgIndexes = []) => {
208303
const hijackParamValueSetter = () => {
209304
const descriptor = Object.getOwnPropertyDescriptor(AudioParam.prototype, 'value')
210305
const originalSetter = descriptor.set
211-
descriptor.set = function (newValue) {
306+
descriptor.set = function(newValue) {
212307
const audioParam = this
213308
// value change gets ignored in Firefox and Safari, if there are changes scheduled
214309
if (!hasScheduledChanges(audioParam)) {

Diff for: src/index.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ if (!isNil(window.AudioParam) && isNil(AudioParam.prototype.getValueAtTime)) {
1818
bindContextToParams('createDynamicsCompressor', ['threshold', 'knee', 'ratio', 'attack', 'release'])
1919
bindContextToParams('createGain', ['gain'])
2020
bindContextToParams('createOscillator', ['frequency', 'detune'])
21-
bindContextToParams('createPanner', ['orientationX', 'orientationY', 'orientationZ', 'positionX', 'positionY', 'positionZ'])
21+
bindContextToParams('createPanner', [
22+
'orientationX',
23+
'orientationY',
24+
'orientationZ',
25+
'positionX',
26+
'positionY',
27+
'positionZ'
28+
])
2229
bindContextToParams('createStereoPanner', ['pan'])
2330

2431
// hijack param methods and mark which argument has the time
@@ -35,12 +42,12 @@ if (!isNil(window.AudioParam) && isNil(AudioParam.prototype.getValueAtTime)) {
3542

3643
hijackParamValueSetter()
3744

38-
AudioParam.prototype.getValueAtTime = function (time) {
45+
AudioParam.prototype.getValueAtTime = function(time) {
3946
const audioParam = this
4047
return getValueAtTime(audioParam, time)
4148
}
4249

43-
AudioParam.prototype.hasScheduledChangesAtTime = function (time) {
50+
AudioParam.prototype.hasScheduledChangesAtTime = function(time) {
4451
const audioParam = this
4552
return hasScheduledChangesAtTime(audioParam, time)
4653
}

0 commit comments

Comments
 (0)