8000 chore: Remove safe-json-parse (#8790) · videojs/video.js@3380d33 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 3380d33

Browse files
authored
chore: Remove safe-json-parse (#8790)
## Description Removes an old unmaintained dependency that isn't needed any more. ## Specific Changes proposed Replace safe-json-parse with `JSON.parse` ## Requirements Checklist - [x] Feature implemented / Bug fixed - [ ] If necessary, more likely in a feature request than a bug fix - [x] Change has been verified in an actual browser (Chrome, Firefox, IE) - [ ] Unit Tests updated or fixed - [ ] Docs/guides updated - [ ] Example created ([starter template on JSBin](https://codepen.io/gkatsev/pen/GwZegv?editors=1000#0)) - [x] Has no DOM changes which impact accessiblilty or trigger warnings (e.g. Chrome issues tab) - [x] Has no changes to JSDoc which cause `npm run docs:api` to error - [ ] Reviewed by Two Core Contributors
1 parent 57c27f8 commit 3380d33

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494
"m3u8-parser": "^7.1.0",
9595
"mpd-parser": "^1.2.2",
9696
"mux.js": "^7.0.1",
97-
"safe-json-parse": "4.0.0",
9897
"videojs-contrib-quality-levels": "4.1.0",
9998
"videojs-font": "4.2.0",
10099
"videojs-vtt.js": "0.15.5"

src/js/player.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { bufferedPercent } from './utils/buffer.js';
2222
import * as stylesheet from './utils/stylesheet.js';
2323
import FullscreenApi from './fullscreen-api.js';
2424
import MediaError from './media-error.js';
25-
import safeParseTuple from 'safe-json-parse/tuple';
2625
import {merge} from './utils/obj';
2726
import {silencePromise, isPromise} from './utils/promise';
2827
import textTrackConverter from './tracks/text-track-list-converter.js';
@@ -5231,13 +5230,12 @@ class Player extends Component {
52315230
// Check if data-setup attr exists.
52325231
if (dataSetup !== null) {
52335232
// Parse options JSON
5234-
// If empty string, make it a parsable json object.
5235-
const [err, data] = safeParseTuple(dataSetup || '{}');
5236-
5237-
if (err) {
5238-
log.error(err);
5233+
try {
5234+
// If empty string, make it a parsable json object.
5235+
Object.assign(tagOptions, JSON.parse(dataSetup || '{}'));
5236+
} catch (e) {
5237+
log.error('data-setup', e);
52395238
}
5240-
Object.assign(tagOptions, data);
52415239
}
52425240

52435241
Object.assign(baseOptions, tagOptions);

test/unit/setup.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* eslint-env qunit */
22
import TestHelpers from './test-helpers.js';
3+
import sinon from 'sinon';
4+
import window from 'global/window';
35

46
QUnit.module('Setup');
57

@@ -19,3 +21,20 @@ QUnit.test('should set options from data-setup even if autoSetup is not called b
1921
assert.ok(player.options_.playsinline === true);
2022
player.dispose();
2123
});
24+
25+
QUnit.test('should log an error if data-setup has invalid JSON', function(assert) {
26+
const logError = sinon.spy(window.console, 'error');
27+
28+
const el = TestHelpers.makeTag();
29+
30+
el.setAttribute(
31+
'data-setup',
32+
"{'controls': true}"
33+
);
34+
35+
const player = TestHelpers.makePlayer({}, el);
36+
37+
assert.ok(logError.calledWith('VIDEOJS:', 'ERROR:', 'data-setup'));
38+
player.dispose();
39+
window.console.error.restore();
40+
});

test/unit/tracks/text-track-settings.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import TextTrackSettings from '../../../src/js/tracks/text-track-settings.js';
33
import TestHelpers from '../test-helpers.js';
44
import * as Events from '../../../src/js/utils/events.js';
5-
import safeParseTuple from 'safe-json-parse/tuple';
65
import sinon from 'sinon';
76
import window from 'global/window';
87
import Component from '../../../src/js/component.js';
@@ -120,7 +119,7 @@ QUnit.test('should update settings', function(assert) {
120119
Events.trigger(player.$('.vjs-done-button'), 'click');
121120

122121
assert.deepEqual(
123-
safeParseTuple(window.localStorage.getItem('vjs-text-track-settings'))[1],
122+
JSON.parse(window.localStorage.getItem('vjs-text-track-settings')),
124123
newSettings,
125124
'values are saved'
126125
);

0 commit comments

Comments
 (0)
0