UNPKG

@codesnippets/codesnippets

Version:
56 lines (41 loc) 1.56 kB
# CodeSnippets Open source and free to use code snippets fueled by you! :sparkling_heart: ## Contributing If you would like to help with this crowd-sourced project, check out our [CONTRIBUTING.md file](https://github.com/trimorphdev/codesnippets/blob/master/CONTRIBUTING.md). There you'll find how you can contribute to the project and what to contribute. Thanks! # API ``` npm install @codesnippets/codesnippets ``` ## Getting Languages You can get a language with the `getLanguage` function provided by CodeSnippets. This will return a language from the `snippets.jsonc` file as an object. ```js const codesnippets = require('codesnippets'); const js = codesnippets.getLanguage('javascript'); console.log(js); ``` Alternatively, you can get a list of all languages: ```js const codesnippets = require('codesnippets'); const languages = codesnippets.getLanguages(); console.log(languages); ``` Or a list of only names of supported languages: ```js const codesnippets = require('codesnippets'); const names = codesnippets.getLanguageNames(); console.log(names); ``` ## Getting Snippets Once you get a Language, you can use the `getSnippet` function. ```js const codesnippets = require('codesnippets'); const js = codesnippets.getLanguage('javascript'); const log = js.getSnippet('log'); // To get the file's contents, use the .get() function: console.log(log.getSync()); ``` You can also get a list of snippet names: ```js const snippets = js.getSnippets(); console.log(snippets); ```