Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

lamualfa/js-isci

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm-version github-license

travis-build-status codecov-coverage david-dependency-status

jsdelivr-downloads npm-downloads

Generate up to 1,5 MILLION++ unique strings (10 character each) in 1 SECOND !!! Thunder IconThunder IconThunder Icon

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 Library for Javascript

What is ISCI?

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.

See Official ISCI Repository

ISCI Can Be Used For:

  • 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

Where can i storage ISCI ?

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.

Simple ISCI example:

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 and randomCharacter are keywords that will be generated automatically by the ISCI library based on the options specified in the keywords 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.

Instalation

CDN

Format:

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 version
    • es : ES2016 version

      ES2015 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 and currentUnixTimestamp keywords

Example:

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

Modules

# Use npm or yarn
npm install js-isci

Usage

Browser

<script src="path/to/js-isci" />

<script>
  isci.next(isciObject);
</script>

Node

Format:

require('js-isci/{draft-version}/{library-mode}')

Property draft-version and library-mode is the same as the property in the CDN

In the node version there is no js-version property as in the CDN

Example:

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

Example js-isci Usage

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.

Methods

Mutable version:

.next(isci, params) string

Params:

  • isci : object - Your ISCI. See ISCI Formats for more information

  • params : object - The ISCI parameter

Get next ID from an ISCI.

Immutable version:

.next(isci, params) object

Return:

  • object.result : string - The next ID
  • object.updatedIsci : object - Updated isci 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' }

See examples.js file for more example or visit Official ISCI Documentation