Format with prettier and add .prettierrc

This commit is contained in:
Joel Arvidsson 2018-02-25 16:14:17 +01:00
parent 172368f2fd
commit a751670b92
3 changed files with 101 additions and 50 deletions

5
.prettierrc Normal file
View File

@ -0,0 +1,5 @@
{
"printWidth": 80,
"singleQuote": true,
"trailingComma": "es5",
}

View File

@ -18,38 +18,43 @@ export default class KeychainExample extends Component {
};
save() {
Keychain
.setSecurePassword('myService', this.state.username, this.state.password)
Keychain.setSecurePassword(
'myService',
this.state.username,
this.state.password
)
.then(() => {
this.setState({ status: 'Credentials saved!' });
})
.catch((err) => {
.catch(err => {
this.setState({ status: 'Could not save credentials, ' + err });
});
}
load() {
Keychain
.getSecurePassword('myService')
.then((credentials) => {
Keychain.getSecurePassword('myService')
.then(credentials => {
if (credentials) {
this.setState({ ...credentials, status: 'Credentials loaded!' });
} else {
this.setState({ status: 'No credentials stored.' });
}
})
.catch((err) => {
.catch(err => {
this.setState({ status: 'Could not load credentials. ' + err });
});
}
reset() {
Keychain
.resetGenericPassword()
Keychain.resetGenericPassword()
.then(() => {
this.setState({ status: 'Credentials Reset!', username: '', password: '' });
this.setState({
status: 'Credentials Reset!',
username: '',
password: '',
});
})
.catch((err) => {
.catch(err => {
this.setState({ status: 'Could not reset credentials, ' + err });
});
}
@ -58,9 +63,7 @@ export default class KeychainExample extends Component {
return (
<KeyboardAvoidingView behavior="padding" style={styles.container}>
<View style={styles.content}>
<Text style={styles.title}>
Keychain Example
</Text>
<Text style={styles.title}>Keychain Example</Text>
<View style={styles.field}>
<Text style={styles.label}>Username</Text>
<TextInput
@ -68,8 +71,9 @@ export default class KeychainExample extends Component {
autoFocus={true}
autoCapitalize="none"
value={this.state.username}
onChange={(event) => this.setState({ username: event.nativeEvent.text })}
/>
onChange={event =>
this.setState({ username: event.nativeEvent.text })}
/>
</View>
<View style={styles.field}>
<Text style={styles.label}>Password</Text>
@ -78,22 +82,34 @@ export default class KeychainExample extends Component {
password={true}
autoCapitalize="none"
value={this.state.password}
onChange={(event) => this.setState({ password: event.nativeEvent.text })}
/>
onChange={event =>
this.setState({ password: event.nativeEvent.text })}
/>
</View>
{!!this.state.status && (<Text style={styles.status}>{this.state.status}</Text>)}
{!!this.state.status && (
<Text style={styles.status}>{this.state.status}</Text>
)}
<View style={styles.buttons}>
<TouchableHighlight onPress={() => this.save()} style={styles.button}>
<TouchableHighlight
onPress={() => this.save()}
style={styles.button}
>
<View style={styles.save}>
<Text style={styles.buttonText}>Save</Text>
</View>
</TouchableHighlight>
<TouchableHighlight onPress={() => this.load()} style={styles.button}>
<TouchableHighlight
onPress={() => this.load()}
style={styles.button}
>
<View style={styles.load}>
<Text style={styles.buttonText}>Load</Text>
</View>
</TouchableHighlight>
<TouchableHighlight onPress={() => this.reset()} style={styles.button}>
<TouchableHighlight
onPress={() => this.reset()}
style={styles.button}
>
<View style={styles.reset}>
<Text style={styles.buttonText}>Reset</Text>
</View>
@ -110,7 +126,7 @@ const styles = StyleSheet.create({
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#F5FCFF'
backgroundColor: '#F5FCFF',
},
content: {
width: 250,
@ -165,5 +181,5 @@ const styles = StyleSheet.create({
fontSize: 14,
paddingHorizontal: 16,
paddingVertical: 8,
}
},
});

View File

@ -8,12 +8,12 @@ type SecAccessible =
| 'AccessibleWhenPasscodeSetThisDeviceOnly'
| 'AccessibleWhenUnlockedThisDeviceOnly'
| 'AccessibleAfterFirstUnlockThisDeviceOnly'
| 'AccessibleAlwaysThisDeviceOnly'
| 'AccessibleAlwaysThisDeviceOnly';
type Options = {
accessible?: SecAccessible;
accessGroup?: string;
service?: string;
accessible?: SecAccessible,
accessGroup?: string,
service?: string,
};
type SecAccessControl =
@ -22,16 +22,14 @@ type SecAccessControl =
| 'TouchIDCurrentSet'
| 'DevicePasscode'
| 'TouchIDAnyOrDevicePasscode'
| 'TouchIDCurrentSetOrDevicePasscode'
| 'TouchIDCurrentSetOrDevicePasscode';
type LAPolicy =
| 'Authentication'
| 'AuthenticationWithBiometrics'
type LAPolicy = 'Authentication' | 'AuthenticationWithBiometrics';
type SecureOptions = {
customPrompt?: string;
authenticationType?: LAPolicy;
accessControl?: SecAccessControl;
customPrompt?: string,
authenticationType?: LAPolicy,
accessControl?: SecAccessControl,
};
/**
@ -40,9 +38,7 @@ type SecureOptions = {
* @param {object} options LAPolicy option, iOS only
* @return {Promise} Resolves to `true` when successful
*/
export function canImplyAuthentication(
options?: SecureOptions
): Promise {
export function canImplyAuthentication(options?: SecureOptions): Promise {
return RNKeychainManager.canCheckAuthentication(options);
}
@ -60,7 +56,12 @@ export function setSecurePassword(
password: string,
options?: SecureOptions
): Promise {
return RNKeychainManager.setSecurePasswordForService(service, username, password, options);
return RNKeychainManager.setSecurePasswordForService(
service,
username,
password,
options
);
}
/**
@ -89,7 +90,12 @@ export function setInternetCredentials(
password: string,
options?: Options
): Promise {
return RNKeychainManager.setInternetCredentialsForServer(server, username, password, options);
return RNKeychainManager.setInternetCredentialsForServer(
server,
username,
password,
options
);
}
/**
@ -120,9 +126,13 @@ export function resetInternetCredentials(
function getOptionsArgument(serviceOrOptions?: string | KeychainOptions) {
if (Platform.OS !== 'ios') {
return typeof serviceOrOptions === 'object' ? serviceOrOptions.service : serviceOrOptions;
return typeof serviceOrOptions === 'object'
? serviceOrOptions.service
: serviceOrOptions;
}
return typeof serviceOrOptions === 'string' ? { service: serviceOrOptions } : serviceOrOptions;
return typeof serviceOrOptions === 'string'
? { service: serviceOrOptions }
: serviceOrOptions;
}
/**
@ -137,7 +147,11 @@ export function setGenericPassword(
password: string,
serviceOrOptions?: string | KeychainOptions
): Promise {
return RNKeychainManager.setGenericPasswordForOptions(getOptionsArgument(serviceOrOptions), username, password);
return RNKeychainManager.setGenericPasswordForOptions(
getOptionsArgument(serviceOrOptions),
username,
password
);
}
/**
@ -148,7 +162,9 @@ export function setGenericPassword(
export function getGenericPassword(
serviceOrOptions?: string | KeychainOptions
): Promise {
return RNKeychainManager.getGenericPasswordForOptions(getOptionsArgument(serviceOrOptions));
return RNKeychainManager.getGenericPasswordForOptions(
getOptionsArgument(serviceOrOptions)
);
}
/**
@ -159,7 +175,9 @@ export function getGenericPassword(
export function resetGenericPassword(
serviceOrOptions?: string | KeychainOptions
): Promise {
return RNKeychainManager.resetGenericPasswordForOptions(getOptionsArgument(serviceOrOptions));
return RNKeychainManager.resetGenericPasswordForOptions(
getOptionsArgument(serviceOrOptions)
);
}
/**
@ -167,9 +185,13 @@ export function resetGenericPassword(
* @return {Promise} Resolves to `{ server, username, password }` if approved and
* `false` if denied and throws an error if not supported on platform or there's no shared credentials
*/
export function requestSharedWebCredentials() : Promise {
export function requestSharedWebCredentials(): Promise {
if (Platform.OS !== 'ios') {
return Promise.reject(new Error(`requestSharedWebCredentials() is not supported on ${Platform.OS} yet`));
return Promise.reject(
new Error(
`requestSharedWebCredentials() is not supported on ${Platform.OS} yet`
)
);
}
return RNKeychainManager.requestSharedWebCredentials();
}
@ -185,9 +207,17 @@ export function setSharedWebCredentials(
server: string,
username: string,
password: string
) : Promise {
): Promise {
if (Platform.OS !== 'ios') {
return Promise.reject(new Error(`setSharedWebCredentials() is not supported on ${Platform.OS} yet`));
return Promise.reject(
new Error(
`setSharedWebCredentials() is not supported on ${Platform.OS} yet`
)
);
}
return RNKeychainManager.setSharedWebCredentialsForServer(server, username, password);
return RNKeychainManager.setSharedWebCredentialsForServer(
server,
username,
password
);
}