Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/igorskyflyer/npm-regkeys
๐ An npm package for fetching Windows registry keys. ๐
https://github.com/igorskyflyer/npm-regkeys
back-end biome igordvlpr igorskyflyer javascirpt module node nodejs npm package registry regkeys typescript vitest windows
Last synced: 4 months ago
JSON representation
๐ An npm package for fetching Windows registry keys. ๐
- Host: GitHub
- URL: https://github.com/igorskyflyer/npm-regkeys
- Owner: igorskyflyer
- License: mit
- Created: 2020-08-19T18:51:02.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-07-04T22:19:56.000Z (8 months ago)
- Last Synced: 2024-08-18T13:17:35.834Z (6 months ago)
- Topics: back-end, biome, igordvlpr, igorskyflyer, javascirpt, module, node, nodejs, npm, package, registry, regkeys, typescript, vitest, windows
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@igor.dvlpr/regkeys
- Size: 275 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
Awesome Lists containing this project
README
# RegKeys
RegKeys,
an NPM package for querying Windows registry keys.
_Uses the **reg.exe** system executable._
If you are looking for a cool implementation of this module, click here.
๐ Support further development
I work hard for every project, including this one and your support means a lot to me!
Consider buying me a coffee. โ
Thank you for supporting my efforts! ๐๐
![]()
@igorskyflyer
_Uses the **reg.exe** system executable._
If you are looking for a cool implementation of this module, click here.
## ๐ต๐ผ Usage
Install it by executing:
```shell
npm i "@igor.dvlpr/regkeys"
```
## ๐คน๐ผ API
```ts
constructor(key): RegKeys
```> Creates the RegKeys object.
> Do **not** forget to set the **_key_** parameter.- **key**: `string`, the key you later want to manipulate with, i.e. read keys, check for children keys, etc.,
> **key** can either be an expanded or a non-expanded key, i.e.:
| Non-expanded | Expanded |
| :----------: | :------------------------: |
| HKCR | HKEY_CLASSES_ROOT |
| HKCU | HKEY_CURRENT_USER |
| HKLM | HKEY_LOCAL_MACHINE |
| HKU | HKEY_USERS |
| HKCC | HKEY_CURRENT_CONFIGURATION |returns the **RegKeys** object.
##### Example
```ts
import { RegKeys } from '@igor.dvlpr/regkeys'// for your convenience, you can use forward slashes,
// since internally Windows only supports back slashes,
// which need to be escaped and look bad ๐ซ๐// so...
``````ts
// ๐
const registry: RegKeys = new RegKeys('HKLM\\Software')// is the same as
// ๐ฅณ๐
const registry: RegKeys = new RegKeys('HKLM/Software')
```
```ts
get(forceRefresh: boolean = false): string[]
```> Gets the keys for the given root key.
- **forceRefresh**: _boolean_, indicates whether the registry should be queried again since the result of this method is cached internally, for performance,
returns a **string[]**.
##### Example
```ts
import { RegKeys } from '@igor.dvlpr/regkeys'const registry: RegKeys = new RegKeys('HKCR')
const keys: string[] = registry.get()// do something with the keys,
// it's your fate, unlock it ๐
keys.forEach((key: string) => {
console.log(key)
})
```
```ts
hasKey(searchFor: string, caseSensitive: boolean = false): boolean
```> Checks whether the given key is a direct child of the currently selected key.
- **searchFor**: _string_, the key to search for,
- **caseSensitive**: _boolean_, indicates whether the search should be case-sensitive or not. Defaults to **false**,returns a **boolean**.
> **NOTE**: it will auto-fetch the keys if the internal cache is empty = you didn't call **get()** before calling this method.
##### Example
```ts
import { RegKeys } from '@igor.dvlpr/regkeys'const registry: RegKeys = new RegKeys('HKLM/Software')
// let's see if we have any
// Microsoft software on our Windows PC
// ๐๐๐๐๐๐
console.log(registry.hasKey('Microsoft'))
```
```ts
hasKeys(searchFor: string[], caseSensitive: boolean = false): boolean
```> Checks whether the given keys are a direct child of the currently selected key.
- **list**: _string[]_, the keys to search for,
- **caseSensitive**: _boolean_, indicates whether the search should be case-sensitive or not. Defaults to **false**,returns a **boolean[]**.
> **NOTE**: it will auto-fetch the keys if the internal cache is empty = you didn't call **get()** before calling this method.
##### Example
```ts
import { RegKeys } from '@igor.dvlpr/regkeys'const registry: RegKeys = new RegKeys('HKLM/Software')
console.log(registry.hasKeys(['Microsoft', 'Macromedia', 'Google', 'Adobe']))
```
```ts
has(value: string|string[], caseSensitive: boolean = false): boolean|boolean[]
```> A generic method that checks whether the given key(s) is/are a direct child of the currently selected key. See both hasKey() and hasKeys(). You can use this method for own convenience, it will pick the suited method depending on the type of the **value** parameter,
- **value**: _string|string[]_, the key(s) to search for,
- **caseSensitive**: _boolean_, indicates whether the search should be case-sensitive or not. Defaults to **false**,returns a **boolean|boolean[]**.
> **NOTE**: it will auto-fetch the keys if the internal cache is empty = you didn't call **get()** before calling this method.
##### Example
```ts
import { RegKeys } from '@igor.dvlpr/regkeys'const registry: RegKeys = new RegKeys('HKLM/Software')
console.log(registry.has('Microsoft'))
console.log(registry.has(['Microsoft', 'Macromedia', 'Google', 'Adobe']))
```
```ts
searchFor(value: string, predicate: SearchPredicate): boolean
```> Provides a way to do keys-checking using a custom predicate function,
- **value**: _string_, the key name to find,
- **predicate**: _SearchPredicate_, the callback that will do the actual querying, see the code example below,returns a **boolean**, i.e. true upon finding the first match or false if no match is found or any of the both required parameters aren't set.
> **NOTE**: it will auto-fetch the keys if the internal cache is empty = you didn't call **get()** before calling this method.
##### Example
```ts
import { RegKeys } from '@igor.dvlpr/regkeys'const registry: RegKeys = new RegKeys('HKLM/Software')
// useful for custom search algorithms/behavior,
// like demonstrated here, case-insensitive partial search
console.log(
registry.searchFor('micro', (key: string, searchFor: string, i: number) => {
return key.toLowerCase().indexOf(searchFor.toLowerCase()) > -1
})
)
```
```ts
clear(): void
```> Clears the cached result, if any,
returns a **void**.
##### Example
```ts
import { RegKeys } from '@igor.dvlpr/regkeys'const registry: RegKeys = new RegKeys('HKLM/Software')
// fetch keys and cache them
let keys = registry.get()// ๐ฎ do something with the registry โญ
// clear the cached result
registry.clear()// refetch (new) keys
keys = registry.get()console.log(keys)
```---
## ๐ชช License
Licensed under the MIT license which is available here, [MIT license](https://github.com/igorskyflyer/npm-regkeys/blob/main/LICENSE).
---
## ๐งฌ Related
[@igor.dvlpr/is-rootdir](https://www.npmjs.com/package/@igor.dvlpr/is-rootdir)
> _๐ผ Provides a way to check if the given path is the root drive/directory. โ_
[@igor.dvlpr/mp3size](https://www.npmjs.com/package/@igor.dvlpr/mp3size)
> _๐งฎ Calculates an estimated file size of Mp3 files. ๐ถ_
[@igor.dvlpr/aria](https://www.npmjs.com/package/@igor.dvlpr/aria)
> _๐งฌ Meet Aria, an efficient Adblock filter list compiler, with many features that make your maintenance of Adblock filter lists a breeze! ๐ก_
[@igor.dvlpr/keppo](https://www.npmjs.com/package/@igor.dvlpr/keppo)
> _๐ก Parse, manage, compare and output SemVer-compatible version numbers. ๐ก_
[@igor.dvlpr/simple-exec](https://www.npmjs.com/package/@igor.dvlpr/simple-exec)
> _๐บ Command. Execution. Made. Simple. โถ_
>
> Provided by **Igor Dimitrijeviฤ** ([*@igorskyflyer*](https://github.com/igorskyflyer/)).
>