@codesnippets/codesnippets

Open source code snippets and examples.

Usage no npm install needed!

<script type="module">
  import codesnippetsCodesnippets from 'https://cdn.skypack.dev/@codesnippets/codesnippets';
</script>

README

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. 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.

const codesnippets = require('codesnippets');

const js = codesnippets.getLanguage('javascript');
console.log(js);

Alternatively, you can get a list of all languages:

const codesnippets = require('codesnippets');

const languages = codesnippets.getLanguages();
console.log(languages);

Or a list of only names of supported languages:

const codesnippets = require('codesnippets');

const names = codesnippets.getLanguageNames();
console.log(names);

Getting Snippets

Once you get a Language, you can use the getSnippet function.

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:

const snippets = js.getSnippets();
console.log(snippets);