index.js 826 B

12345678910111213141516171819202122232425262728293031323334
  1. const SayLinux = require('./platform/linux.js')
  2. const SayMacos = require('./platform/darwin.js')
  3. const SayWin32 = require('./platform/win32.js')
  4. const MACOS = 'darwin'
  5. const LINUX = 'linux'
  6. const WIN32 = 'win32'
  7. class Say {
  8. constructor (platform) {
  9. if (!platform) {
  10. platform = process.platform
  11. }
  12. if (platform === MACOS) {
  13. return new SayMacos()
  14. } else if (platform === LINUX) {
  15. return new SayLinux()
  16. } else if (platform === WIN32) {
  17. return new SayWin32()
  18. }
  19. throw new Error(`new Say(): unsupported platorm! ${platform}`)
  20. }
  21. }
  22. module.exports = new Say() // Create a singleton automatically for backwards compatability
  23. module.exports.Say = Say // Allow users to `say = new Say.Say(platform)`
  24. module.exports.platforms = {
  25. WIN32: WIN32,
  26. MACOS: MACOS,
  27. LINUX: LINUX
  28. }