├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── dist ├── index.d.ts ├── index.js ├── index.js.map ├── uuid.d.ts ├── uuid.js ├── uuid.js.map ├── uuid.service.d.ts ├── uuid.service.js └── uuid.service.js.map ├── package.json ├── src ├── index.ts ├── uuid.service.ts └── uuid.ts ├── tsconfig.json └── tslint.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Node generated files 2 | node_modules 3 | npm-debug.log 4 | 5 | # OS generated files 6 | Thumbs.db 7 | .DS_Store 8 | 9 | .history 10 | 11 | # VS Code 12 | .vscode 13 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Node generated files 2 | node_modules 3 | npm-debug.log 4 | 5 | # OS generated files 6 | Thumbs.db 7 | .DS_Store 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Wulf Solter 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # THIS PROJECT IS NOT MAINTAINED # 2 | # USE AT YOUR OWN RISK # 3 | 4 | # angular2-uuid 5 | Angular 2 UUID generator. 6 | Uses crypto-secure PRNG window.crypto.getRandomValues() if available, otherwise fallback to Math.random(); 7 | 8 | ## Install 9 | `npm install angular2-uuid --save` 10 | 11 | ## Use 12 | Include in Angular2 / Ionic2 project with 13 | ``` 14 | import { UuidService } from 'angular2-uuid'; 15 | ... 16 | constructor(private uuid: UuidService) { ... } 17 | ... 18 | const uuid = this.uuid.generate(); 19 | ``` 20 | -------------------------------------------------------------------------------- /dist/index.d.ts: -------------------------------------------------------------------------------- 1 | export { UuidService } from './uuid.service'; 2 | export { UUID } from './uuid'; 3 | -------------------------------------------------------------------------------- /dist/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var uuid_service_1 = require("./uuid.service"); 3 | exports.UuidService = uuid_service_1.UuidService; 4 | var uuid_1 = require("./uuid"); 5 | exports.UUID = uuid_1.UUID; 6 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /dist/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,+CAA6C;AAApC,qCAAA,WAAW,CAAA;AACpB,+BAA8B;AAArB,sBAAA,IAAI,CAAA"} -------------------------------------------------------------------------------- /dist/uuid.d.ts: -------------------------------------------------------------------------------- 1 | export declare class UUID { 2 | constructor(); 3 | static UUID(): string; 4 | private static pad4(num); 5 | private static random4(); 6 | } 7 | -------------------------------------------------------------------------------- /dist/uuid.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var UUID = (function () { 3 | function UUID() { 4 | // no-op 5 | } 6 | UUID.UUID = function () { 7 | if (typeof (window) !== "undefined" && typeof (window.crypto) !== "undefined" && typeof (window.crypto.getRandomValues) !== "undefined") { 8 | // If we have a cryptographically secure PRNG, use that 9 | // http://stackoverflow.com/questions/6906916/collisions-when-generating-uuids-in-javascript 10 | var buf = new Uint16Array(8); 11 | window.crypto.getRandomValues(buf); 12 | return (this.pad4(buf[0]) + this.pad4(buf[1]) + "-" + this.pad4(buf[2]) + "-" + this.pad4(buf[3]) + "-" + this.pad4(buf[4]) + "-" + this.pad4(buf[5]) + this.pad4(buf[6]) + this.pad4(buf[7])); 13 | } 14 | else { 15 | // Otherwise, just use Math.random 16 | // https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript 17 | // https://stackoverflow.com/questions/11605068/why-does-jshint-argue-against-bitwise-operators-how-should-i-express-this-code 18 | return this.random4() + this.random4() + "-" + this.random4() + "-" + this.random4() + "-" + 19 | this.random4() + "-" + this.random4() + this.random4() + this.random4(); 20 | } 21 | }; 22 | UUID.pad4 = function (num) { 23 | var ret = num.toString(16); 24 | while (ret.length < 4) { 25 | ret = "0" + ret; 26 | } 27 | return ret; 28 | }; 29 | UUID.random4 = function () { 30 | return Math.floor((1 + Math.random()) * 0x10000) 31 | .toString(16) 32 | .substring(1); 33 | }; 34 | return UUID; 35 | }()); 36 | exports.UUID = UUID; 37 | //# sourceMappingURL=uuid.js.map -------------------------------------------------------------------------------- /dist/uuid.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"uuid.js","sourceRoot":"","sources":["../src/uuid.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb;IAEI;QACI,QAAQ;IACZ,CAAC;IAEa,SAAI,GAAlB;QACI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC;YACtI,uDAAuD;YACvD,4FAA4F;YAC5F,IAAI,GAAG,GAAgB,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC;YAC1C,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC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f,CAAC;IAEc,YAAO,GAAtB;QACI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC;aAC3C,QAAQ,CAAC,EAAE,CAAC;aACZ,SAAS,CAAC,CAAC,CAAC,CAAC;IACtB,CAAC;IAEL,WAAC;AAAD,CAAC,AApCD,IAoCC;AApCY,oBAAI"} -------------------------------------------------------------------------------- /dist/uuid.service.d.ts: -------------------------------------------------------------------------------- 1 | export declare class UuidService { 2 | generate(): string; 3 | } 4 | -------------------------------------------------------------------------------- /dist/uuid.service.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 6 | return c > 3 && r && Object.defineProperty(target, key, r), r; 7 | }; 8 | var uuid_1 = require("./uuid"); 9 | var core_1 = require("@angular/core"); 10 | var UuidService = (function () { 11 | function UuidService() { 12 | } 13 | UuidService.prototype.generate = function () { 14 | return uuid_1.UUID.UUID(); 15 | }; 16 | return UuidService; 17 | }()); 18 | UuidService = __decorate([ 19 | core_1.Injectable() 20 | ], UuidService); 21 | exports.UuidService = UuidService; 22 | //# sourceMappingURL=uuid.service.js.map -------------------------------------------------------------------------------- /dist/uuid.service.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"uuid.service.js","sourceRoot":"","sources":["../src/uuid.service.ts"],"names":[],"mappings":";;;;;;;AAAA,+BAA8B;AAE9B,sCAA2C;AAG3C,IAAa,WAAW;IAAxB;IAKA,CAAC;IAHQ,8BAAQ,GAAf;QACE,MAAM,CAAC,WAAI,CAAC,IAAI,EAAE,CAAC;IACrB,CAAC;IACH,kBAAC;AAAD,CAAC,AALD,IAKC;AALY,WAAW;IADvB,iBAAU,EAAE;GACA,WAAW,CAKvB;AALY,kCAAW"} -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular2-uuid", 3 | "version": "1.1.1", 4 | "description": "Angular 2 / TypeScript crypto-secure UUID generator", 5 | "main": "dist/index.js", 6 | "typings": "dist/index.d.ts", 7 | "scripts": { 8 | "prepublish": "tsc", 9 | "test": "echo \"Error: no test specified\" && exit 1" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/wulfsolter/angular2-uuid.git" 14 | }, 15 | "keywords": [ 16 | "angular", 17 | "angular2", 18 | "ionic", 19 | "uuid", 20 | "guid", 21 | "TypeScript", 22 | "crypto", 23 | "secure" 24 | ], 25 | "author": "Wulf Solter (http://wulf.co.nz)", 26 | "license": "MIT", 27 | "bugs": { 28 | "url": "https://github.com/wulfsolter/angular2-uuid/issues" 29 | }, 30 | "homepage": "https://github.com/wulfsolter/angular2-uuid#readme", 31 | "devDependencies": { 32 | "@angular/common": "2.4.10", 33 | "@angular/compiler": "^2.4.10", 34 | "@angular/compiler-cli": "^2.4.10", 35 | "@angular/core": "^2.4.10", 36 | "rxjs": "^5.2.0", 37 | "tslint": "^4.5.1", 38 | "typescript": "2.2.1", 39 | "zone.js": "0.7.6" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export { UuidService } from './uuid.service'; 2 | export { UUID } from './uuid'; 3 | -------------------------------------------------------------------------------- /src/uuid.service.ts: -------------------------------------------------------------------------------- 1 | import { UUID } from './uuid'; 2 | 3 | import { Injectable } from '@angular/core'; 4 | 5 | @Injectable() 6 | export class UuidService { 7 | 8 | public generate(): string { 9 | return UUID.UUID(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/uuid.ts: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | export class UUID { 4 | 5 | constructor() { 6 | // no-op 7 | } 8 | 9 | public static UUID(): string { 10 | if (typeof (window) !== "undefined" && typeof (window.crypto) !== "undefined" && typeof (window.crypto.getRandomValues) !== "undefined") { 11 | // If we have a cryptographically secure PRNG, use that 12 | // http://stackoverflow.com/questions/6906916/collisions-when-generating-uuids-in-javascript 13 | let buf: Uint16Array = new Uint16Array(8); 14 | window.crypto.getRandomValues(buf); 15 | return (this.pad4(buf[0]) + this.pad4(buf[1]) + "-" + this.pad4(buf[2]) + "-" + this.pad4(buf[3]) + "-" + this.pad4(buf[4]) + "-" + this.pad4(buf[5]) + this.pad4(buf[6]) + this.pad4(buf[7])); 16 | } else { 17 | // Otherwise, just use Math.random 18 | // https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript 19 | // https://stackoverflow.com/questions/11605068/why-does-jshint-argue-against-bitwise-operators-how-should-i-express-this-code 20 | return this.random4() + this.random4() + "-" + this.random4() + "-" + this.random4() + "-" + 21 | this.random4() + "-" + this.random4() + this.random4() + this.random4(); 22 | } 23 | } 24 | 25 | private static pad4(num: number): string { 26 | let ret: string = num.toString(16); 27 | while (ret.length < 4) { 28 | ret = "0" + ret; 29 | } 30 | return ret; 31 | } 32 | 33 | private static random4(): string { 34 | return Math.floor((1 + Math.random()) * 0x10000) 35 | .toString(16) 36 | .substring(1); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "declaration": true, 5 | "emitDecoratorMetadata": true, 6 | "experimentalDecorators": true, 7 | "lib": ["dom", "es6"], 8 | "module": "commonjs", 9 | "moduleResolution": "node", 10 | "noEmitOnError": true, 11 | "noImplicitAny": false, 12 | "outDir": "./dist", 13 | "rootDir": "./src", 14 | "sourceMap": true, 15 | "target": "es5", 16 | "inlineSources": false 17 | }, 18 | 19 | "files": [ 20 | "./src/index.ts" 21 | ], 22 | 23 | "angularCompilerOptions": { 24 | "genDir": "compiled", 25 | "debug": true, 26 | "skipMetadataEmit" : false, 27 | "strictMetadataEmit": true 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "align": [ 4 | true, 5 | "parameters", 6 | "arguments", 7 | "statements" 8 | ], 9 | "ban": false, 10 | "class-name": true, 11 | "comment-format": [ 12 | true, 13 | "check-space" 14 | ], 15 | "curly": false, 16 | "eofline": true, 17 | "forin": false, 18 | "indent": [ 19 | true, 20 | "spaces" 21 | ], 22 | "interface-name": false, 23 | "jsdoc-format": true, 24 | "label-position": true, 25 | "label-undefined": true, 26 | "max-line-length": [ 27 | true, 28 | 180 29 | ], 30 | "member-access": true, 31 | "member-ordering": [false], 32 | "no-any": false, 33 | "no-arg": true, 34 | "no-bitwise": true, 35 | "no-conditional-assignment": true, 36 | "no-consecutive-blank-lines": true, 37 | "no-console": [false], 38 | "no-construct": false, 39 | "no-constructor-vars": true, 40 | "no-debugger": true, 41 | "no-duplicate-key": true, 42 | "no-duplicate-variable": true, 43 | "no-empty": true, 44 | "no-eval": true, 45 | "no-inferrable-types": false, 46 | "no-internal-module": true, 47 | "no-require-imports": false, 48 | "no-shadowed-variable": true, 49 | "no-string-literal": false, 50 | "no-switch-case-fall-through": true, 51 | "no-trailing-whitespace": true, 52 | "no-unreachable": true, 53 | "no-unused-expression": true, 54 | "no-unused-variable": false, 55 | "no-use-before-declare": true, 56 | "no-var-keyword": true, 57 | "no-var-requires": true, 58 | "object-literal-sort-keys": false, 59 | "one-line": [ 60 | true, 61 | "check-open-brace", 62 | "check-whitespace" 63 | ], 64 | "quotemark": [ 65 | true, 66 | "single", 67 | "avoid-escape" 68 | ], 69 | "radix": false, 70 | "semicolon": true, 71 | "switch-default": false, 72 | "trailing-comma": [ 73 | true, 74 | { 75 | "multiline": "always", 76 | "singleline": "never" 77 | } 78 | ], 79 | "triple-equals": [true], 80 | "typedef": [ 81 | true, 82 | "call-signature", 83 | "parameter", 84 | "property-declaration", 85 | "variable-declaration", 86 | "member-variable-declaration" 87 | ], 88 | "typedef-whitespace": [ 89 | true, 90 | { 91 | "call-signature": "nospace", 92 | "index-signature": "nospace", 93 | "parameter": "nospace", 94 | "property-declaration": "nospace", 95 | "variable-declaration": "nospace" 96 | } 97 | ], 98 | "use-strict": [ 99 | true, 100 | "check-module", 101 | "check-function" 102 | ], 103 | "variable-name": [ 104 | true, 105 | "check-format", 106 | "allow-leading-underscore", 107 | "ban-keywords" 108 | ], 109 | "whitespace": [ 110 | true, 111 | "check-branch", 112 | "check-decl", 113 | "check-operator", 114 | "check-separator", 115 | "check-type" 116 | ] 117 | } 118 | } 119 | --------------------------------------------------------------------------------