Skip to content

Commit 28bbc7e

Browse files
committed
Added API function aliases
1 parent fe40590 commit 28bbc7e

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

generate-pw/src/generate-pw.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,22 @@ function validateOptions(options, defaultOptions, docURL, exampleCall) {
319319
}
320320

321321
// EXPORT API functions
322+
const funcAliases = {
323+
generatePassword: [
324+
'generate', 'generatepassword', 'generatepw', 'generatePw', 'generatePW',
325+
'Generate', 'Generatepassword', 'GeneratePassword', 'Generatepw', 'GeneratePw', 'GeneratePW'
326+
],
327+
generatePasswords: [
328+
'generatepasswords', 'generatepws', 'generatePws', 'generatePWs', 'generatePWS',
329+
'Generatepasswords', 'GeneratePasswords', 'Generatepws', 'GeneratePws', 'GeneratePWs', 'GeneratePWS'
330+
],
331+
strictify: [ 'Strictify' ],
332+
validateStrength: [ 'validate', 'Validate', 'validatestrength', 'Validatestrength', 'ValidateStrength' ]
333+
};
322334
const apiFunctions = { generatePassword, generatePasswords, strictify, validateStrength };
323335
try { module.exports = { ...apiFunctions }; } catch (err) {} // for Node.js
324336
try { window.pw = { ...apiFunctions }; } catch (err) {} // for Greasemonkey
337+
for (const func in funcAliases) { // init/export aliases
338+
try { funcAliases[func].forEach(alias => module.exports[alias] = module.exports[func]); } catch (err) {} // for Node.js
339+
try { funcAliases[func].forEach(alias => window.pw[alias] = window.pw[func]); } catch (err) {} // for Greasemonkey
340+
}

geolocate/src/geolocate.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ function validateOptions(options, defaultOptions, docURL, exampleCall) {
119119
}
120120

121121
// EXPORT API functions
122-
const apiFunctions = { geolocate, locate: geolocate };
123-
try { module.exports = { ...apiFunctions }; } catch (err) {} // for Node.js
124-
try { window.geo = { ...apiFunctions }; } catch (err) {} // for Greasemonkey
122+
const funcAliases = { geolocate: ['Geolocate', 'geoLocate', 'GeoLocate', 'locate', 'Locate'] };
123+
try { module.exports = { geolocate }; } catch (err) {} // for Node.js
124+
try { window.geo = { geolocate }; } catch (err) {} // for Greasemonkey
125+
for (const func in funcAliases) { // init/export aliases
126+
try { funcAliases[func].forEach(alias => module.exports[alias] = module.exports[func]); } catch (err) {} // for Node.js
127+
try { funcAliases[func].forEach(alias => window.geo[alias] = window.geo[func]); } catch (err) {} // for Greasemonkey
128+
}

0 commit comments

Comments
 (0)