The OSINT investigator's workbench. One case, one folder, every tool. Local-first: your media and your investigations never leave your machine.
JavaScript
import { describe, it, expect } from 'vitest';
import { bidiIsolate, bidiSafe, FSI, hasRtl, LRI, PDI } from './bidi.js';
const ARABIC = 'قصف على المدينة';
describe('hasRtl', () => {
it('detects Arabic and Hebrew, not Latin', () => {
expect(hasRtl(ARABIC)).toBe(true);
expect(hasRtl('עיר עתיקה')).toBe(true);
expect(hasRtl('Strike on the city, 48.8584, 2.2945')).toBe(false);
expect(hasRtl('')).toBe(false);
expect(hasRtl(null)).toBe(false);
});
});
describe('bidiSafe — isolates LTR runs inside RTL text', () => {
it('leaves LTR-only text completely untouched', () => {
const text = 'Kyiv - 8GXG+Q8\n50.450100, 30.523400\n@GeoConfirmed\nhttps://x.com/a/1';
expect(bidiSafe(text)).toBe(text);
});
it('wraps a coordinate pair so the comma cannot flip', () => {
const out = bidiSafe(`${ARABIC}\n50.450100, 30.523400`);
expect(out).toContain(`${LRI}50.450100, 30.523400${PDI}`);
});
it('wraps URLs, mentions and plus codes', () => {
const out = bidiSafe(`${ARABIC} @GeoConfirmed 8GXG+Q8 https://t.me/chan/42`);
expect(out).toContain(`${LRI}@GeoConfirmed${PDI}`);
expect(out).toContain(`${LRI}8GXG+Q8${PDI}`);
expect(out).toContain(`${LRI}https://t.me/chan/42${PDI}`);
});
it('keeps the RTL prose itself unwrapped', () => {
const out = bidiSafe(`${ARABIC}\nhttps://x.com/a/1`);
expect(out.startsWith(ARABIC)).toBe(true);
});
it('is idempotent — re-applying never double-wraps', () => {
const once = bidiSafe(`${ARABIC} 50.450100, 30.523400`);
expect(bidiSafe(once)).toBe(once);
});
it('handles empty/nullish input', () => {
expect(bidiSafe('')).toBe('');
expect(bidiSafe(null)).toBe('');
});
});
describe('bidiIsolate — a drawn label reads in its own direction', () => {
it('isolates a label holding RTL, so its number and ellipsis stay on its side', () => {
expect(bidiIsolate('مسجد 12')).toBe(`${FSI}مسجد 12${PDI}`);
expect(bidiIsolate('שלום…')).toBe(`${FSI}שלום…${PDI}`);
});
it('leaves every other label exactly as it was', () => {
expect(bidiIsolate('Quay 4')).toBe('Quay 4');
expect(bidiIsolate('Москва')).toBe('Москва');
expect(bidiIsolate(null)).toBe('');
});
});