import { osType } from "@alx-plugins/marginnote" ; import { scanObject } from "./scan" ; export const getWordCount = ( src ) => { return ( src . match ( /\b/g ) || "" ) . length / 2 + ( src . match ( chs ) || "" ) . length ; } ; const prefix = "marginnote3app://note/" ; const chs = RegExp ( /[\u4e00-\u9fa5]/g ) ; export const mnUrl = ( id ) => prefix + id ; export { alert , copy , debug , showHUD } ; const showHUD = ( message , duration = 2 ) => { Application . sharedInstance ( ) . showHUD ( message , self . window , duration ) ; } ; const alert = ( message ) => { Application . sharedInstance ( ) . alert ( message ) ; } ; /**
 * Copy to Clipboard
 */ const copy = ( content ) => { let pasteBoard = UIPasteboard . generalPasteboard ( ) ; pasteBoard . string = content ; } ; const debug = ( obj ) => { const replacer = ( k , value ) => { if ( value === undefined ) { return "UNDEFINED" ; } else if ( typeof value === "function" ) { return value . toString ( ) ; } else return value ; } ; try { return JSON . stringify ( scanObject ( obj ) , replacer , 2 ) ; } catch ( error ) { if ( error instanceof Error ) showHUD ( error . toString ( ) ) ; else showHUD ( JSON . stringify ( error ) ) ; return null ; } } ; /**
 * Get Objective-C class declaration
 */ export const getObjCClassDeclar = ( name , type ) => `${ name } : ${ type }` ; export const isMac = ( ) => Application . sharedInstance ( ) . osType === osType . macOS ;