Skip to content

Commit

Permalink
Merge pull request #5 from jeanlescure/v2
Browse files Browse the repository at this point in the history
full refactor using neutrino
  • Loading branch information
jeanlescure committed Mar 4, 2020
2 parents a6c0179 + 23652cf commit 3afd18d
Show file tree
Hide file tree
Showing 18 changed files with 7,241 additions and 489 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const neutrino = require('neutrino');

module.exports = neutrino().eslintrc();
75 changes: 0 additions & 75 deletions .eslintrc.json

This file was deleted.

101 changes: 49 additions & 52 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,40 +1,13 @@

# Created by https://www.gitignore.io/api/node,macos,windows

### macOS ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
Expand All @@ -47,11 +20,12 @@ lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
Expand All @@ -60,22 +34,31 @@ bower_components
# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

Expand All @@ -87,27 +70,41 @@ typings/

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
# Serverless directories
.serverless/

# Folder config file
Desktop.ini
# FuseBox cache
.fusebox/

# Recycle Bin used on file shares
$RECYCLE.BIN/
# DynamoDB Local files
.dynamodb/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# TernJS port file
.tern-port

# Windows shortcuts
*.lnk
# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# End of https://www.gitignore.io/api/node,macos,windows
# Neutrino build directory
build
32 changes: 32 additions & 0 deletions .neutrinorc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const airbnbBase = require('@neutrinojs/airbnb-base');
const library = require('@neutrinojs/library');
const jest = require('@neutrinojs/jest');

const libName = require('./package.json').name;

module.exports = {
use: [
airbnbBase({
eslint: {
baseConfig: {
rules: {
'jest/no-try-expect': 'off',
},
},
},
}),
library({
name: libName,
babel: {
plugins: [
'@babel/plugin-proposal-class-properties',
],
},
}),
jest(),
(neutrino) => {
neutrino.config.output
.filename(`${libName}.min.js`);
},
],
};
34 changes: 25 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# Short Unique ID Generator
## With ES6 imports, Node.js, and browser support

This is a straight up manual transpilation to ES6 of the [short-uid](https://github.com/serendipious/nodejs-short-uid) npm package by [Ankit Kuwadekar](https://github.com/serendipious/).
This started as a straight up manual transpilation to ES6 of the [short-uid](https://github.com/serendipious/nodejs-short-uid) npm package by [Ankit Kuwadekar](https://github.com/serendipious/).

## Why?
![image depicting over 5000 weekly npm downloads](/assets/weekly-downloads.png)

The above linked repository has gone stale, no updates in the past 3 years (as of updating this README).
Since my package is now reporting between 4k and 5k+ npm weekly downloads, I've gone ahead and refactored the package using [Neutrino JS](https://neutrinojs.org/).

If used in a ES6 environment it fails to follow good `import` standards.
## V2.x

Even so, the functionality is still useful. So here we are.
Version 2.0 was mainly a refactor of the original branch, so functionality and naming conventions have been kept the same.

Even so, there are still **breaking changes**, mainly the removal of the `lib` build output, as well as changes on how to instantiate the library on the browser.

## Instantiation (Server-side)

Expand Down Expand Up @@ -49,10 +51,23 @@ Browser:

<!-- Instantiate -->
<script>
var uid = new ShortUniqueId();
var ShortUniqueId = window['short-unique-id'].default;
var uid = new ShortUniqueId({debug: true});
</script>
```

## Options

There are three options available on instantiation:

```javascript
const options = {
dictionary: ['Z', 'a', 'p', 'h', 'o', 'd' ...], // User-defined dictionary
skipShuffle: false, // If true, sequentialUUID will iterate over the dictionary in the given order
debug: false, // If true the instance will console.log useful info
};
```

## Usage

Once instantiated you can use one of two functions:
Expand Down Expand Up @@ -82,15 +97,16 @@ This will update the `short-unique-id.js` file under `./lib`, which will then be
Find lint using [airbnb](https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb-base) for [eslint](https://github.com/eslint/eslint):

```
npm run lint
yarn lint
```

## Build

In order to publish the latest changes you must build the distribution files:

```
npm run build
yarn build
yarn dist:update
```

This will update the `short-unique-id.js` file under `./lib`, which will then be minified as the `short-unique-id.min.js` file under the `./dist` directory.
This will generate the `short-unique-id.min.js` file under the `./dist` directory.
Binary file added assets/weekly-downloads.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion dist/short-unique-id.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3afd18d

Please sign in to comment.