keyboard-layout
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -1,50 +0,66 @@ | ||
(function() { | ||
var Emitter, KeyboardLayoutObserver, emitter, getCurrentKeyboardLanguage, getCurrentKeyboardLayout, getInstalledKeyboardLanguages, observeCurrentKeyboardLayout, observer, onDidChangeCurrentKeyboardLayout; | ||
'use strict' | ||
Emitter = require('event-kit').Emitter; | ||
const Emitter = require('event-kit').Emitter | ||
const KeyboardLayoutManager = require('../build/Release/keyboard-layout-manager.node') | ||
KeyboardLayoutObserver = require('../build/Release/keyboard-layout-observer.node').KeyboardLayoutObserver; | ||
const emitter = new Emitter() | ||
emitter = new Emitter; | ||
let currentKeymap = null | ||
let currentKeyboardLayout = null | ||
let currentKeyboardLanguage = null | ||
observer = new KeyboardLayoutObserver(function() { | ||
return emitter.emit('did-change-current-keyboard-layout', getCurrentKeyboardLayout()); | ||
}); | ||
const manager = new KeyboardLayoutManager(() => { | ||
currentKeymap = null | ||
currentKeyboardLayout = null | ||
currentKeyboardLanguage = null | ||
emitter.emit('did-change-current-keyboard-layout', getCurrentKeyboardLayout()) | ||
}) | ||
getCurrentKeyboardLayout = function() { | ||
return observer.getCurrentKeyboardLayout(); | ||
}; | ||
function getCurrentKeymap () { | ||
if (!currentKeymap) { | ||
currentKeymap = manager.getCurrentKeymap() | ||
} | ||
return currentKeymap | ||
} | ||
getCurrentKeyboardLanguage = function() { | ||
return observer.getCurrentKeyboardLanguage(); | ||
}; | ||
function getCurrentKeyboardLayout () { | ||
if (!currentKeyboardLayout) { | ||
currentKeyboardLayout = manager.getCurrentKeyboardLayout() | ||
} | ||
return currentKeyboardLayout | ||
} | ||
getInstalledKeyboardLanguages = function() { | ||
var language, languages, _i, _len, _ref; | ||
languages = {}; | ||
_ref = observer.getInstalledKeyboardLanguages() || []; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
language = _ref[_i]; | ||
languages[language] = true; | ||
} | ||
return Object.keys(languages); | ||
}; | ||
function getCurrentKeyboardLanguage () { | ||
if (!currentKeyboardLanguage) { | ||
currentKeyboardLanguage = manager.getCurrentKeyboardLanguage() | ||
} | ||
return currentKeyboardLanguage | ||
} | ||
onDidChangeCurrentKeyboardLayout = function(callback) { | ||
return emitter.on('did-change-current-keyboard-layout', callback); | ||
}; | ||
function getInstalledKeyboardLanguages () { | ||
var languages = {} | ||
observeCurrentKeyboardLayout = function(callback) { | ||
callback(getCurrentKeyboardLayout()); | ||
return onDidChangeCurrentKeyboardLayout(callback); | ||
}; | ||
for (var language of (manager.getInstalledKeyboardLanguages() || [])) { | ||
languages[language] = true | ||
} | ||
module.exports = { | ||
getCurrentKeyboardLayout: getCurrentKeyboardLayout, | ||
getCurrentKeyboardLanguage: getCurrentKeyboardLanguage, | ||
getInstalledKeyboardLanguages: getInstalledKeyboardLanguages, | ||
onDidChangeCurrentKeyboardLayout: onDidChangeCurrentKeyboardLayout, | ||
observeCurrentKeyboardLayout: observeCurrentKeyboardLayout | ||
}; | ||
return Object.keys(languages) | ||
} | ||
}).call(this); | ||
function onDidChangeCurrentKeyboardLayout (callback) { | ||
return emitter.on('did-change-current-keyboard-layout', callback) | ||
} | ||
function observeCurrentKeyboardLayout (callback) { | ||
callback(getCurrentKeyboardLayout()) | ||
return onDidChangeCurrentKeyboardLayout(callback) | ||
} | ||
module.exports = { | ||
getCurrentKeymap: getCurrentKeymap, | ||
getCurrentKeyboardLayout: getCurrentKeyboardLayout, | ||
getCurrentKeyboardLanguage: getCurrentKeyboardLanguage, | ||
getInstalledKeyboardLanguages: getInstalledKeyboardLanguages, | ||
onDidChangeCurrentKeyboardLayout: onDidChangeCurrentKeyboardLayout, | ||
observeCurrentKeyboardLayout: observeCurrentKeyboardLayout | ||
} |
{ | ||
"name": "keyboard-layout", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Read and observe the current keyboard layout on OS X.", | ||
"main": "./lib/keyboard-layout", | ||
"scripts": { | ||
"prepublish": "grunt prepublish", | ||
"test": "grunt test" | ||
"test": "jasmine-focused --captureExceptions --forceexit spec" | ||
}, | ||
@@ -28,13 +27,4 @@ "repository": { | ||
"devDependencies": { | ||
"coffee-script": "^1.7.0", | ||
"jasmine-focused": "^1.0.4", | ||
"grunt-contrib-coffee": "^0.9.0", | ||
"grunt-cli": "^0.1.8", | ||
"grunt": "^0.4.1", | ||
"grunt-shell": "^0.2.2", | ||
"grunt-coffeelint": "^0.0.6", | ||
"rimraf": "^2.2.2", | ||
"coffee-cache": "^0.2.0", | ||
"temp": "^0.6.0" | ||
"jasmine-focused": "^1.0.4" | ||
} | ||
} |
@@ -9,5 +9,5 @@ # keyboard-layout [![Build Status](https://travis-ci.org/atom/keyboard-layout.svg?branch=master)](https://travis-ci.org/atom/keyboard-layout) [![Build status](https://ci.appveyor.com/api/projects/status/303xcfrs0yj448au/branch/master?svg=true)](https://ci.appveyor.com/project/kevinsawicki/keyboard-layout/branch/master) | ||
```coffee | ||
{getCurrentKeyboardLayout} = require 'keyboard-layout' | ||
getCurrentKeyboardLayout() # => "com.apple.keylayout.Dvorak" | ||
```js | ||
const KeyboardLayout = require('keyboard-layout') | ||
KeyboardLayout.getCurrentKeyboardLayout() // => "com.apple.keylayout.Dvorak" | ||
``` | ||
@@ -19,8 +19,27 @@ | ||
current layout value and then again next time it changes, whereas | ||
`onDidChangeCurrentKeyboardLayout` only invokes the callback on the next change. | ||
`onDidChangeCurrentKeyboardLayout` only invokes the callback on the next | ||
change. | ||
```coffee | ||
{observeCurrentKeyboardLayout} = require 'keyboard-layout' | ||
subscription = observeCurrentKeyboardLayout (layout) -> console.log layout | ||
subscription.dispose() # to unsubscribe later | ||
```js | ||
const KeyboardLayout = require('keyboard-layout') | ||
subscription = KeyboardLayout.observeCurrentKeyboardLayout((layout) => console.log(layout)) | ||
subscription.dispose() // to unsubscribe later | ||
``` | ||
To return characters for various modifier states based on a DOM 3 | ||
`KeyboardEvent.code` value and the current system keyboard layout, use | ||
`getCurrentKeymap()`: | ||
```js | ||
const KeyboardLayout = require('keyboard-layout') | ||
KeyboardLayout.getCurrentKeymap()['KeyS'] | ||
/* | ||
On a US layout, this returns: | ||
{ | ||
unmodified: 's', | ||
withShift: 'S', | ||
withAltGr: 'ß', | ||
withShiftAltGr: 'Í' | ||
} | ||
*/ | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55690
1
11
53
44
1
2