@segment/protocol

Testing component used to fake different protocols from the browser

protocol

Testing component used to fake protocols from the browser. Overrides window.location.protocolproperties with fake ones using Object.defineProperty, so it won't work on IE8. Probably a good thing to only use in testing.

Installation

$ npm install @segment/protocol

API

#protocol()

Returns the current protocol that the document is using

protocol(); // 'http:'

#protocol(protocol)

When supplied with an argument, sets a custom protocol for the document.

protocol('chrome-extension:');
protocol(); // 'chrome-extension:'

#http()

Sets the protocol to be http

protocol();  // 'file:'
protocol.http();  // 'http:'

#https()

Sets the protocol to be https:

protocol();  // 'file:'
protocol.https();  // 'https:'

#reset()

Resets the protocol to be whatever it was at page load.

protocol('x:');
protocol.reset();
protocol(); // 'http:'

HomePage

https://github.com/segmentio/protocol#readme

Repository

https://github.com/segmentio/protocol


上一篇:@segment/send-json
下一篇:@segment/localstorage-retry

相关推荐

官方社区

扫码加入 JavaScript 社区