Skip to content

Commit

Permalink
Merge pull request #1 from sajera/improvement_for_source_of_helper
Browse files Browse the repository at this point in the history
Improvement for source of helper
  • Loading branch information
sajera committed Jun 24, 2017
2 parents 7093912 + 17b25e8 commit 8ec158f
Show file tree
Hide file tree
Showing 41 changed files with 2,839 additions and 236 deletions.
38 changes: 38 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true


[*]
# Change these settings to your own preference
indent_style = space
indent_size = 4

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[*.html]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true

[*.styl,*.scss,*.css,*.less]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,bower.json,.eslintrc}]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
18 changes: 18 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"env": {
"browser": true,
"node": true
},
"rules": {
"complexity": [2, 16],
"max-nested-callbacks": [2, 3],
"max-params": [2, 4],
"max-statements": [2, 30],
"no-extra-parens": [0],
"no-magic-numbers": [0],
"no-restricted-syntax": [2, "ContinueStatement", "DebuggerStatement", "LabeledStatement", "WithStatement"],
"operator-linebreak": [2, "before"],
"spaced-comment": [0],
"strict": [0]
}
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/*
bower_components/*
*.log
old/*
14 changes: 14 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
node_modules/*
bower_components/*
old/*
lib/*
tables/*
test/*
*.log
*.md
bower.json
gulpfile.js
.eslintrc.json
.gitignore
.npmignore
.editorconfig
59 changes: 29 additions & 30 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
{
"name": "s-uid",
"main": "uid.min.js",
"version": "1.3.0",
"private": false,
"description": "Generate id from base string",
"ignore": [
"node_modules",
"bower_components",
"package.json",
"bower.json",
"gulpfile.js",
"lib",
"test.*"
],
"keywords": [
"s-uid",
"uid"
],
"homepage": "https://github.com/sajera/s-uid",
"authors": [
"Sajera: Serhii P <allsajera@gmail.com>"
],
"repository": {
"type": "git",
"url": "git+https://github.com/sajera/s-uid.git"
},
"license": "MIT",
"dependencies": {},
"devDependencies": {}
}
"name": "s-uid",
"main": "s-uid.min.js",
"private": false,
"description": "Generate id from base string",
"ignore": [
"node_modules",
"bower_components",
"package.json",
"bower.json",
"gulpfile.js",
"lib",
"test.*"
],
"keywords": [
"s-uid",
"uid"
],
"homepage": "https://github.com/sajera/s-uid",
"authors": [
"Sajera: Serhii P <allsajera@gmail.com>"
],
"repository": {
"type": "git",
"url": "git+https://github.com/sajera/s-uid.git"
},
"license": "MIT",
"dependencies": {},
"devDependencies": {}
}
146 changes: 146 additions & 0 deletions doc/API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

## uid

generate random id based on template string.
Default template string is 'xxxxxxxx-xxxx-1xxx-1xxx-xxxxxxxxxxxx'.

> Template rules very simple:
>
> **base** - it's a string for creating id. Rewrite only special characters
>
> **N** - Rewrite to random Number
>
> **H** - Rewrite to random hex numder
>
> **S** - Rewrite to random english symbol
>
> **X** - Rewrite to any from "N","H","S"
**Parameters**

- `base` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** :[default: 'XXXXXXXX-XXXX-1XXX-1XXX-XXXXXXXXXXXX']

**Examples**

```javascript
uid();
uid('XXX-4NNN-dummy-SSS');
```

Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**

## uid.\_time

Humanized time string.
This method is very sensitive to the correctness of the input arguments

**Parameters**

- `separator` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Separator character for output
- `date` **[Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)** instance of Date constructor

**Examples**

```javascript
uid._time('-', new Date() );
```

Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**

## uid.\_date

Humanized date string.
This method is very sensitive to the correctness of the input arguments

**Parameters**

- `separator` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Separator character for output
- `date` **[Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)** instance of Date constructor

**Examples**

```javascript
uid._date('-', new Date() );
```

Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**

## uid.time

Humanized date+time string. Safe method.

**Parameters**

- `date` **[Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)?** :[default: new Date()] - instance of Date constructor
- `separator1` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** :[default: ' - '] - Separator character for output date
- `separator2` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** :[default: ' \s '] - Separator character for output bitwin date and time
- `separator3` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** :[default: ' : '] - Separator character for output time
- `time`

**Examples**

```javascript
uid.time();
uid.time( new Date() );
uid.time( new Date(), '-', ':', '-');
```

Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**

## uid.th

hash based on time in 36 numerical system by default

**Parameters**

- `date` **[Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)?** :[default: new Date()] - instance of Date constructor
- `Number` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** [bit]&#x3A;[default: 36] - expect number 2-36

**Examples**

```javascript
uid.th();
uid.th(null, 4);
uid.th(new Date(), 10);
```

Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** hash string

## uid.guid

generate uuid (xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx)
based on time, reserved characters and random symbols

**Parameters**

- `M` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** [default: random english symbol ( uid('S') )]
- `N` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** [default: random number ( uid('N') )]
- `time` **[Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)?** [default: new Date()] - date of guid generation

**Examples**

```javascript
uid.guid();
uid.guid('M', 0, new Date() );
```

Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**

## exports

defination on platforms (both variants on platform like Electron)

bower i --save s-uid

npm i --save s-uid

**Examples**

```javascript
window.uid || window['s-uid'] // in browser
```

```javascript
var uid = require('s-uid') // in Node.js
```
Loading

0 comments on commit 8ec158f

Please sign in to comment.