js-isci
Draft-1 benchmark result:
1-keyword_isci_1 x 1,524,326 ops/sec ±0.80% (96 runs sampled)
1-keyword_isci_2 x 1,522,268 ops/sec ±0.78% (94 runs sampled)
1-keyword_isci_3 x 1,535,622 ops/sec ±0.68% (94 runs sampled)
Run node draft-1/benchmark.js
for concrete proof.
ISCI (Identification SCheme Information) is a scheme that stores information related to an identification label. ISCI can standardize an identification label on the system or application you have. ISCI is very flexible. ISCI uses the JSON format, this format allows an identification label to generated on any system at any time. ISCI can be stored in Databases, JSON Files or other storage areas that support the JSON storage format. ISCI can be used across platforms depending on the availability of libraries on each platform.
- Class name for HTML element in production mode. Ex:
<button class="r_k92"></button>
- API_KEY in API
- Opaque Access Token in OAuth
- Primary Key in Database
- Salt character in Hash function
- User ID, Document ID, Invoice Number, District ID, etc
- or in lieu of other identification labels that require personal customization
You can save it anywhere in a place that supports to save a JSON or JSON string like MongoDB, SQL Server, Solr, Redis, JSON File, etc.
Using ISCI Draft-1.
Whats is Draft in ISCI? The Draft is a standardized version of the ISCI format
accountId.isci.json
(You can use any name) :
{
"name": "isciAccountId",
"pattern": "<districtId>_[uniqueCharacter]-[randomCharacter]",
"keywords": {
"uniqueCharacter": {
"type": "incrCharset",
"charset": "abcdefgh",
"index": 0,
"increaser": 1,
"length": 3
},
"randomCharacter": {
"type": "randCharset",
"charset": "abcdefghijklmnopq012345",
"minLength": 5,
"maxLength": 12
}
}
}
in
pattern
section,districtId
is the parameter that will be input when an ID is created.uniqueCharacter
andrandomCharacter
are keywords that will be generated automatically by the ISCI library based on the options specified in thekeywords
section. See Official ISCI Documentation for further information.
You can store this JSON object in database or file to generate an ID anytime, anywhere with any language system depends on the availability of ISCI libraries from each language.
https://cdn.jsdelivr.net/npm/js-isci@latest/{draft-version}/dist/{js-version}/{library-mode}.min.js
-
draft-version
: (lowercase) See List ISCI Drafts -
js-version
:js
: ES2015 versiones
: ES2016 versionES2015 support in most browser, while ES2016 support only in most modern browser
-
library-mode
:mutable
immutable
light-mutable
light-immutable
What is the difference between mutable and immutable version? See Mutable Version
The light version is 50% smaller than the non-light version. In light version not include support to
currentDate
andcurrentUnixTimestamp
keywords
Draft-1, ES2016, Mutable : https://cdn.jsdelivr.net/npm/js-isci@latest/draft-1/dist/es/mutable.min.js
Draft-1, ES2015, Light Immutable : https://cdn.jsdelivr.net/npm/js-isci@latest/draft-1/dist/js/light-immutable.min.js
# Use npm or yarn
npm install js-isci
<script src="path/to/js-isci" />
<script>
isci.next(isciObject);
</script>
require('js-isci/{draft-version}/{library-mode}')
Property
draft-version
andlibrary-mode
is the same as the property in the CDN
In the node version there is no
js-version
property as in the CDN
// Default import is: Draft-1, Mutable
const { next } = require('js-isci');
// Draft-1, Immutable
const { next } = require('js-isci/draft-1/immutable');
// Draft-1, Light Mutable
const { next } = require('js-isci/draft-1/light-mutable');
Just select one of the examples above
Expand code
const { next } = require('js-isci');
const sampleIsci = {
pattern:
'<index>-[keyword_1]-[keyword_2]-[keyword_3]-[keyword_4]-[keyword_5]_[keyword_6]',
keywords: {
keyword_1: {
type: 'randCharset',
length: 5,
charset: 'abcdefg'
},
keyword_2: {
type: 'incrNumber',
index: 0,
increaser: 1,
startNumber: 0
},
keyword_3: {
type: 'incrCharset',
index: 0,
increaser: 1,
length: 6,
charset: 'hijkl'
},
keyword_4: {
type: 'incrCharsets',
index: 0,
increaser: 1,
charsets: ['mnopq', 'rstuv', 'wxyz', '01234', '56789']
}
}
};
let i = 0;
while (i++ < 6) {
console.log(
next(sampleIsci, {
index: i
})
);
}
Output:
1-efbff-1-hhhhhh_mrw05
2-egdcf-2-hhhhhi_mrw06
3-gcbdd-3-hhhhhj_mrw07
4-aafde-4-hhhhhk_mrw08
5-ebgac-5-hhhhhl_mrw09
6-babbc-6-hhhhih_mrw15
You can use the result above as an ID for your data like
user_id
,document_id
and etc.
Params:
-
isci
:object
- Your ISCI. See ISCI Formats for more information -
params
:object
- The ISCI parameter
Get next ID from an ISCI.
Return:
object.result
:string
- The next IDobject.updatedIsci
:object
- Updatedisci
object.
Same as .next
method in mutable version, but this function does not change the original isci
object and returning an object
contain next ID and updated ISCI.
When is this function is used?
The answer is if you don't want to change the original ISCI object
In Javascript, all object instances are connected. When you change an instance, other intances will also change.
Example:
const original = { key1: 'hello' }; const instance1 = original; const instance2 = original; // Change value in instance2 instance2.key1 = 'world'; // Now value of original, instance1, instance2 is: // { key1: 'world' }