
Security News
US Government Forces Anthropic to Pull Claude Fable Days After Launch
Anthropic says the directive cited national security concerns over a narrow jailbreak, but offered no specific technical details.
device-heading
Advanced tools
TypeScript library to get and track device heading.
[!NOTE] Requires HTTPS or localhost to access motion sensors.
On iOS Safari,
requestIOSPermission()must be called inside a user gesture handler (e.g., a button click).Heading accuracy depends on the device's magnetometer and surrounding environment.
🔗 Live Demo: https://ryohidaka.github.io/device-heading/
[!TIP] Access from a smartphone to see real-time compass heading updates as you move your device.
npm i device-heading
import { DeviceHeading } from "device-heading";
const compass = new DeviceHeading();
if (compass.isSupported()) {
console.log("DeviceOrientationEvent API is supported on this device.");
} else {
console.error("DeviceOrientationEvent API is not supported on this device.");
}
import { DeviceHeading } from "device-heading";
const compass = new DeviceHeading();
const heading = await compass.once();
console.log("Current heading:", heading);
import { DeviceHeading } from "device-heading";
// Round to 1 decimal place (e.g., 180.5)
const compass = new DeviceHeading({ precision: 1 });
const heading = await compass.once();
console.log("Current heading::", heading);
import { DeviceHeading } from "device-heading";
const compass = new DeviceHeading();
compass.start((heading) => {
console.log("Heading:", heading);
});
// Stop watching when done
setTimeout(() => {
compass.stop();
console.log("Stopped observing.");
}, 5000);
import { DeviceHeading } from "device-heading";
const compass = new DeviceHeading();
if (!(await compass.hasIOSPermission())) {
// show permission request UI
}
On iOS Safari, the user must explicitly grant permission to access motion data. Call this inside a user gesture handler (e.g., a button click).
import { DeviceHeading } from "device-heading";
const compass = new DeviceHeading();
button.addEventListener("click", async () => {
const granted = await compass.requestIOSPermission();
if (granted) {
console.log("Permission granted");
} else {
console.log("Permission denied");
}
});
new DeviceHeading(options?)Creates a new compass instance.
| Option | Type | Default | Description |
|---|---|---|---|
precision | number | undefined | Decimal places to round heading values to. If omitted, no rounding is applied. |
isSupported(): booleanReturns true if the current environment supports DeviceOrientationEvent.
once(): Promise<number>Returns the current heading once (in degrees, 0–360°).
start(callback: (heading: number) => void): voidStarts watching for heading updates. Calls callback with the latest heading on each change.
stop(): voidStops watching for heading updates.
hasIOSPermission(): Promise<boolean>Returns true if the DeviceOrientationEvent permission is granted on iOS 13+.
On non-iOS devices, always returns true.
requestIOSPermission(): Promise<boolean>Requests motion permission on iOS 13+. Must be called inside a user gesture handler (e.g., a button click).
On non-iOS devices, returns true immediately.
Please see CONTRIBUTING.md for contribution guidelines.
MIT
FAQs
TypeScript library to get and track device heading
We found that device-heading demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Anthropic says the directive cited national security concerns over a narrow jailbreak, but offered no specific technical details.

Security News
A network of 152 Chrome live wallpaper extensions hid ad tracking and made extension-driven traffic look like Google search clicks.

Company News
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.