Action

Drafts 5 JavaScript API list

Last update over 6 years ago

Creates a new sheet listing the Object method and property names of the Drafts 5 JS API

Steps

  • script

    (function () {
    
    	const main = () => {
    
    		const 
    			g = this,
    			ks = keySort(
    					Object.keys(g).filter(k => k !== '$')
    				);
    
    		
    		// NEW DRAFTS 5 SHEET
    		editor.new();
    	
    		// POPULATED WITH LISTING OF OBJECTS PROPERTIES AND METHODS
    		// IN THE DRAFTS 5 JAVASCRIPT INTERFACE
    		editor.setText(
    			ks.map(k => {
    				const 
    					o = g[k],
    					c = o.constructor,
    					t = typeof c,
    					blnC = t !== 'object',
    					noise = ['constructor','prototype'],
    					
    					nest = Object.getOwnPropertyNames(
    						blnC ? (
    							o
    						) : o.constructor.prototype
    					).filter(x => !noise.includes(x)),
    					
    					rest = blnC ? Object.getOwnPropertyNames(
    						o.prototype
    					).filter(x => !noise.includes(x)) : [],
    
    					fs = nest.concat(rest);
    					
    				return k + '\n' + (fs.length > 0 ? (
    					keySort(fs).map(s => '    ' + s).join('\n')
    				) : ''); 
    			}).join('\n')
    		 );
    	};
    	
    
    	// NEW SHEET LISTING OBJECTS PROPERTIES AND METHODS
    	// OF THE DRAFTS 5 JS API
    
    	const keySort = xs => {
    		const ys = xs.slice(0);
    		return (
    			ys.sort((a, b) => {
    				const 
    					la = a.toLowerCase(),
    					lb = b.toLowerCase();
    				return la < lb ? -1 : la > lb ? 1 : 0;
    			}),
    			ys
    		);
    	};
    
    	const showJSON = x => JSON.stringify(x, null, 2);
    
    	// -------------------------------
    	return main();
    })()

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.