Skip to content

Commit

Permalink
Convert to TypeScript, see #1465
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Oct 15, 2024
1 parent f3b10f9 commit a397dc0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 4 additions & 2 deletions js/grunt/copySupplementalPhetioFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import * as _ from 'lodash';
import IntentionalAny from '../../../phet-core/js/types/IntentionalAny.js';
import webpackBuild from './webpackBuild.ts';
import buildStandalone from './buildStandalone.ts';
import formatPhetioAPI from '../phet-io/formatPhetioAPI';
import reportTscResults from './reportTscResults';

const assert = require( 'assert' );
const archiver = require( 'archiver' );
Expand All @@ -21,11 +23,11 @@ const copyDirectory = require( '../grunt/copyDirectory' );
const execute = require( '../../../perennial-alias/js/common/execute' );
const grunt = require( 'grunt' );
const generatePhetioMacroAPI = require( '../phet-io/generatePhetioMacroAPI' );
const formatPhetioAPI = require( '../phet-io/formatPhetioAPI' );

const minify = require( '../grunt/minify' );
const marked = require( 'marked' );
const tsc = require( './tsc' );
import reportTscResults from './reportTscResults';

const getPhetLibs = require( './getPhetLibs' );
const path = require( 'path' );
const webpack = require( 'webpack' );
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/generate-phet-io-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import getOption from '../../../../perennial-alias/js/grunt/tasks/util/getOption';
import getRepo from '../../../../perennial-alias/js/grunt/tasks/util/getRepo';
import formatPhetioAPI from '../../phet-io/formatPhetioAPI';

/**
* Output the PhET-iO API as JSON to phet-io-sim-specific/api.
Expand All @@ -16,7 +17,6 @@ import getRepo from '../../../../perennial-alias/js/grunt/tasks/util/getRepo';
*/
const repo = getRepo();

const formatPhetioAPI = require( '../../phet-io/formatPhetioAPI' );
const getSimList = require( '../../common/getSimList' );
const generatePhetioMacroAPI = require( '../../phet-io/generatePhetioMacroAPI' );
const fs = require( 'fs' );
Expand Down
14 changes: 6 additions & 8 deletions js/phet-io/formatPhetioAPI.js → js/phet-io/formatPhetioAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,32 @@
* @author Sam Reid (PhET Interactive Simulations)
*/


const assert = require( 'assert' );
const fixEOL = require( '../grunt/fixEOL' );

import IntentionalAny from '../../../phet-core/js/types/IntentionalAny.ts';

/**
* Creates a new object, recursively, by sorting the keys at each level.
* @param {Object} unordered - jsonifiable object to be sorted by key name. Sorting is recursive.
* @param unordered - jsonifiable object to be sorted by key name. Sorting is recursive.
*/
const copyWithSortedKeys = unordered => {
const copyWithSortedKeys = ( unordered: IntentionalAny ): Record<string, IntentionalAny> => {
if ( Array.isArray( unordered ) ) {
return unordered.map( copyWithSortedKeys );
}
else if ( typeof unordered !== 'object' || unordered === null ) {
return unordered;
}

const ordered = {};
const ordered: Record<string, IntentionalAny> = {};
Object.keys( unordered ).sort().forEach( key => {
const value = unordered[ key ];
ordered[ key ] = copyWithSortedKeys( value );
} );
return ordered;
};

/**
* @param {Object} api
*/
module.exports = api => {
export default ( api: IntentionalAny ): string => {
assert( api, 'api expected' );
const objectString = JSON.stringify( copyWithSortedKeys( api ), null, 2 );
return fixEOL( objectString );
Expand Down

0 comments on commit a397dc0

Please sign in to comment.