-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from Maaaartin/fix/wrong-date-parsing
Fix/wrong date parsing
- Loading branch information
Showing
13 changed files
with
88 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,39 @@ | ||
import { findMatches } from '../../util'; | ||
import { PropertyMap } from '../../util'; | ||
import { findMatches, ListPropertiesMap } from '../../util'; | ||
import TransportParseAllCommand from '../abstract/transportParseAll'; | ||
|
||
export default class ListPropertiesCommand extends TransportParseAllCommand<PropertyMap> { | ||
protected Cmd = 'shell:getprop'; | ||
const valueParser = ( | ||
type: string | undefined, | ||
value: string | ||
): string | boolean | number => { | ||
switch (type) { | ||
case 'bool': | ||
case 'int': | ||
try { | ||
return JSON.parse(value); | ||
} catch { | ||
return value; | ||
} | ||
default: | ||
return value; | ||
} | ||
}; | ||
|
||
export default class ListPropertiesCommand extends TransportParseAllCommand<ListPropertiesMap> { | ||
protected Cmd = 'shell:getprop -T && getprop'; | ||
|
||
protected parse(value: string): PropertyMap { | ||
return findMatches(value, /^\[([\s\S]*?)\]: \[([\s\S]*?)\]?$/gm, 'map'); | ||
protected parse(value: string): ListPropertiesMap { | ||
const matches = findMatches( | ||
value, | ||
/^\[([\s\S]*?)\]: \[([\s\S]*?)\]?$/gm | ||
) as [string, string][]; | ||
const typeMap = new Map(matches.slice(0, matches.length / 2)); | ||
return new Map( | ||
matches | ||
.slice(matches.length / 2) | ||
.map(([key, value]) => [ | ||
key, | ||
valueParser(typeMap.get(key), value) | ||
]) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.