id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
39,100 |
bluemathsoft/bm-common
|
lib/ops.js
|
empty
|
function empty(arg0, datatype) {
var A;
if (Array.isArray(arg0)) {
A = new ndarray_1.NDArray({ shape: arg0, datatype: datatype });
}
else {
A = new ndarray_1.NDArray({ shape: [arg0], datatype: datatype });
}
return A;
}
|
javascript
|
function empty(arg0, datatype) {
var A;
if (Array.isArray(arg0)) {
A = new ndarray_1.NDArray({ shape: arg0, datatype: datatype });
}
else {
A = new ndarray_1.NDArray({ shape: [arg0], datatype: datatype });
}
return A;
}
|
[
"function",
"empty",
"(",
"arg0",
",",
"datatype",
")",
"{",
"var",
"A",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"arg0",
")",
")",
"{",
"A",
"=",
"new",
"ndarray_1",
".",
"NDArray",
"(",
"{",
"shape",
":",
"arg0",
",",
"datatype",
":",
"datatype",
"}",
")",
";",
"}",
"else",
"{",
"A",
"=",
"new",
"ndarray_1",
".",
"NDArray",
"(",
"{",
"shape",
":",
"[",
"arg0",
"]",
",",
"datatype",
":",
"datatype",
"}",
")",
";",
"}",
"return",
"A",
";",
"}"
] |
Creates empty NDArray of given shape or of given length if argument is
a number
|
[
"Creates",
"empty",
"NDArray",
"of",
"given",
"shape",
"or",
"of",
"given",
"length",
"if",
"argument",
"is",
"a",
"number"
] |
0915b3aa3b9aab25925984b24ebdc98168ea6e07
|
https://github.com/bluemathsoft/bm-common/blob/0915b3aa3b9aab25925984b24ebdc98168ea6e07/lib/ops.js#L151-L160
|
39,101 |
bluemathsoft/bm-common
|
lib/ops.js
|
cross
|
function cross(A, B) {
if (A.shape.length !== 1 || B.shape.length !== 1) {
throw new Error('A or B is not 1D');
}
if (A.length < 3 || B.length < 3) {
throw new Error('A or B is less than 3 in length');
}
var a1 = A.getN(0);
var a2 = A.getN(1);
var a3 = A.getN(2);
var b1 = B.getN(0);
var b2 = B.getN(1);
var b3 = B.getN(2);
return new ndarray_1.NDArray([
a2 * b3 - a3 * b2,
a3 * b1 - a1 * b3,
a1 * b2 - a2 * b1
]);
}
|
javascript
|
function cross(A, B) {
if (A.shape.length !== 1 || B.shape.length !== 1) {
throw new Error('A or B is not 1D');
}
if (A.length < 3 || B.length < 3) {
throw new Error('A or B is less than 3 in length');
}
var a1 = A.getN(0);
var a2 = A.getN(1);
var a3 = A.getN(2);
var b1 = B.getN(0);
var b2 = B.getN(1);
var b3 = B.getN(2);
return new ndarray_1.NDArray([
a2 * b3 - a3 * b2,
a3 * b1 - a1 * b3,
a1 * b2 - a2 * b1
]);
}
|
[
"function",
"cross",
"(",
"A",
",",
"B",
")",
"{",
"if",
"(",
"A",
".",
"shape",
".",
"length",
"!==",
"1",
"||",
"B",
".",
"shape",
".",
"length",
"!==",
"1",
")",
"{",
"throw",
"new",
"Error",
"(",
"'A or B is not 1D'",
")",
";",
"}",
"if",
"(",
"A",
".",
"length",
"<",
"3",
"||",
"B",
".",
"length",
"<",
"3",
")",
"{",
"throw",
"new",
"Error",
"(",
"'A or B is less than 3 in length'",
")",
";",
"}",
"var",
"a1",
"=",
"A",
".",
"getN",
"(",
"0",
")",
";",
"var",
"a2",
"=",
"A",
".",
"getN",
"(",
"1",
")",
";",
"var",
"a3",
"=",
"A",
".",
"getN",
"(",
"2",
")",
";",
"var",
"b1",
"=",
"B",
".",
"getN",
"(",
"0",
")",
";",
"var",
"b2",
"=",
"B",
".",
"getN",
"(",
"1",
")",
";",
"var",
"b3",
"=",
"B",
".",
"getN",
"(",
"2",
")",
";",
"return",
"new",
"ndarray_1",
".",
"NDArray",
"(",
"[",
"a2",
"*",
"b3",
"-",
"a3",
"*",
"b2",
",",
"a3",
"*",
"b1",
"-",
"a1",
"*",
"b3",
",",
"a1",
"*",
"b2",
"-",
"a2",
"*",
"b1",
"]",
")",
";",
"}"
] |
Computes cross product of A and B
Only defined for A and B to 1D vectors of length at least 3
Only first 3 elements of A and B are used
|
[
"Computes",
"cross",
"product",
"of",
"A",
"and",
"B",
"Only",
"defined",
"for",
"A",
"and",
"B",
"to",
"1D",
"vectors",
"of",
"length",
"at",
"least",
"3",
"Only",
"first",
"3",
"elements",
"of",
"A",
"and",
"B",
"are",
"used"
] |
0915b3aa3b9aab25925984b24ebdc98168ea6e07
|
https://github.com/bluemathsoft/bm-common/blob/0915b3aa3b9aab25925984b24ebdc98168ea6e07/lib/ops.js#L195-L213
|
39,102 |
bluemathsoft/bm-common
|
lib/ops.js
|
length
|
function length(A) {
if (A.shape.length !== 1) {
throw new Error('A is not a 1D array');
}
return Math.sqrt(dot(A, A));
}
|
javascript
|
function length(A) {
if (A.shape.length !== 1) {
throw new Error('A is not a 1D array');
}
return Math.sqrt(dot(A, A));
}
|
[
"function",
"length",
"(",
"A",
")",
"{",
"if",
"(",
"A",
".",
"shape",
".",
"length",
"!==",
"1",
")",
"{",
"throw",
"new",
"Error",
"(",
"'A is not a 1D array'",
")",
";",
"}",
"return",
"Math",
".",
"sqrt",
"(",
"dot",
"(",
"A",
",",
"A",
")",
")",
";",
"}"
] |
Computes length or magnitude of A, where A is a 1D vector
|
[
"Computes",
"length",
"or",
"magnitude",
"of",
"A",
"where",
"A",
"is",
"a",
"1D",
"vector"
] |
0915b3aa3b9aab25925984b24ebdc98168ea6e07
|
https://github.com/bluemathsoft/bm-common/blob/0915b3aa3b9aab25925984b24ebdc98168ea6e07/lib/ops.js#L218-L223
|
39,103 |
bluemathsoft/bm-common
|
lib/ops.js
|
dir
|
function dir(A) {
if (A.shape.length !== 1) {
throw new Error('A is not a 1D array');
}
return div(A, length(A));
}
|
javascript
|
function dir(A) {
if (A.shape.length !== 1) {
throw new Error('A is not a 1D array');
}
return div(A, length(A));
}
|
[
"function",
"dir",
"(",
"A",
")",
"{",
"if",
"(",
"A",
".",
"shape",
".",
"length",
"!==",
"1",
")",
"{",
"throw",
"new",
"Error",
"(",
"'A is not a 1D array'",
")",
";",
"}",
"return",
"div",
"(",
"A",
",",
"length",
"(",
"A",
")",
")",
";",
"}"
] |
Computes direction vector of A, where A is a 1D vector
|
[
"Computes",
"direction",
"vector",
"of",
"A",
"where",
"A",
"is",
"a",
"1D",
"vector"
] |
0915b3aa3b9aab25925984b24ebdc98168ea6e07
|
https://github.com/bluemathsoft/bm-common/blob/0915b3aa3b9aab25925984b24ebdc98168ea6e07/lib/ops.js#L228-L233
|
39,104 |
enmasseio/babble
|
lib/block/IIf.js
|
IIf
|
function IIf (condition, trueBlock, falseBlock) {
if (!(this instanceof IIf)) {
throw new SyntaxError('Constructor must be called with the new operator');
}
if (typeof condition === 'function') {
this.condition = condition;
}
else if (condition instanceof RegExp) {
this.condition = function (message, context) {
return condition.test(message);
}
}
else {
this.condition = function (message, context) {
return message == condition;
}
}
if (trueBlock && !trueBlock.isBlock) {
throw new TypeError('Parameter trueBlock must be a Block');
}
if (falseBlock && !falseBlock.isBlock) {
throw new TypeError('Parameter falseBlock must be a Block');
}
this.trueBlock = trueBlock || null;
this.falseBlock = falseBlock || null;
}
|
javascript
|
function IIf (condition, trueBlock, falseBlock) {
if (!(this instanceof IIf)) {
throw new SyntaxError('Constructor must be called with the new operator');
}
if (typeof condition === 'function') {
this.condition = condition;
}
else if (condition instanceof RegExp) {
this.condition = function (message, context) {
return condition.test(message);
}
}
else {
this.condition = function (message, context) {
return message == condition;
}
}
if (trueBlock && !trueBlock.isBlock) {
throw new TypeError('Parameter trueBlock must be a Block');
}
if (falseBlock && !falseBlock.isBlock) {
throw new TypeError('Parameter falseBlock must be a Block');
}
this.trueBlock = trueBlock || null;
this.falseBlock = falseBlock || null;
}
|
[
"function",
"IIf",
"(",
"condition",
",",
"trueBlock",
",",
"falseBlock",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"IIf",
")",
")",
"{",
"throw",
"new",
"SyntaxError",
"(",
"'Constructor must be called with the new operator'",
")",
";",
"}",
"if",
"(",
"typeof",
"condition",
"===",
"'function'",
")",
"{",
"this",
".",
"condition",
"=",
"condition",
";",
"}",
"else",
"if",
"(",
"condition",
"instanceof",
"RegExp",
")",
"{",
"this",
".",
"condition",
"=",
"function",
"(",
"message",
",",
"context",
")",
"{",
"return",
"condition",
".",
"test",
"(",
"message",
")",
";",
"}",
"}",
"else",
"{",
"this",
".",
"condition",
"=",
"function",
"(",
"message",
",",
"context",
")",
"{",
"return",
"message",
"==",
"condition",
";",
"}",
"}",
"if",
"(",
"trueBlock",
"&&",
"!",
"trueBlock",
".",
"isBlock",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'Parameter trueBlock must be a Block'",
")",
";",
"}",
"if",
"(",
"falseBlock",
"&&",
"!",
"falseBlock",
".",
"isBlock",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'Parameter falseBlock must be a Block'",
")",
";",
"}",
"this",
".",
"trueBlock",
"=",
"trueBlock",
"||",
"null",
";",
"this",
".",
"falseBlock",
"=",
"falseBlock",
"||",
"null",
";",
"}"
] |
extend Block with function then
IIf
Create an iif block, which checks a condition and continues either with
the trueBlock or the falseBlock. The input message is passed to the next
block in the flow.
Can be used as follows:
- When `condition` evaluates true:
- when `trueBlock` is provided, the flow continues with `trueBlock`
- else, when there is a block connected to the IIf block, the flow continues
with that block.
- When `condition` evaluates false:
- when `falseBlock` is provided, the flow continues with `falseBlock`
Syntax:
new IIf(condition, trueBlock)
new IIf(condition, trueBlock [, falseBlock])
new IIf(condition).then(...)
@param {Function | RegExp | *} condition A condition returning true or false
In case of a function,
the function is invoked as
`condition(message, context)` and
must return a boolean. In case of
a RegExp, condition will be tested
to return true. In other cases,
non-strict equality is tested on
the input.
@param {Block} [trueBlock]
@param {Block} [falseBlock]
@constructor
@extends {Block}
|
[
"extend",
"Block",
"with",
"function",
"then",
"IIf",
"Create",
"an",
"iif",
"block",
"which",
"checks",
"a",
"condition",
"and",
"continues",
"either",
"with",
"the",
"trueBlock",
"or",
"the",
"falseBlock",
".",
"The",
"input",
"message",
"is",
"passed",
"to",
"the",
"next",
"block",
"in",
"the",
"flow",
"."
] |
6b7e84d7fb0df2d1129f0646b37a9d89d3da2539
|
https://github.com/enmasseio/babble/blob/6b7e84d7fb0df2d1129f0646b37a9d89d3da2539/lib/block/IIf.js#L43-L72
|
39,105 |
co3moz/gluon
|
gluon.js
|
function () {
return Token.destroy({
where: {
code: req.get('token')
}
}).then(function (data) {
return data;
}).catch(function (err) {
res.database(err)
});
}
|
javascript
|
function () {
return Token.destroy({
where: {
code: req.get('token')
}
}).then(function (data) {
return data;
}).catch(function (err) {
res.database(err)
});
}
|
[
"function",
"(",
")",
"{",
"return",
"Token",
".",
"destroy",
"(",
"{",
"where",
":",
"{",
"code",
":",
"req",
".",
"get",
"(",
"'token'",
")",
"}",
"}",
")",
".",
"then",
"(",
"function",
"(",
"data",
")",
"{",
"return",
"data",
";",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"res",
".",
"database",
"(",
"err",
")",
"}",
")",
";",
"}"
] |
Removes token from owner
@returns {Promise.<TResult>}
|
[
"Removes",
"token",
"from",
"owner"
] |
b6ca29330ce518b7f909755cad70a42f6add3fed
|
https://github.com/co3moz/gluon/blob/b6ca29330ce518b7f909755cad70a42f6add3fed/gluon.js#L174-L184
|
|
39,106 |
co3moz/gluon
|
gluon.js
|
function (roles) {
roles.map(function (role) {
return Role.findOrCreate({
where: {
code: role,
ownerId: req[options.auth.model].id
},
defaults: {
code: role,
ownerId: req[options.auth.model].id
}
}).spread(function (role, created) {
return role
}).catch(function (err) {
res.database(err)
});
});
return Promise.all(roles);
}
|
javascript
|
function (roles) {
roles.map(function (role) {
return Role.findOrCreate({
where: {
code: role,
ownerId: req[options.auth.model].id
},
defaults: {
code: role,
ownerId: req[options.auth.model].id
}
}).spread(function (role, created) {
return role
}).catch(function (err) {
res.database(err)
});
});
return Promise.all(roles);
}
|
[
"function",
"(",
"roles",
")",
"{",
"roles",
".",
"map",
"(",
"function",
"(",
"role",
")",
"{",
"return",
"Role",
".",
"findOrCreate",
"(",
"{",
"where",
":",
"{",
"code",
":",
"role",
",",
"ownerId",
":",
"req",
"[",
"options",
".",
"auth",
".",
"model",
"]",
".",
"id",
"}",
",",
"defaults",
":",
"{",
"code",
":",
"role",
",",
"ownerId",
":",
"req",
"[",
"options",
".",
"auth",
".",
"model",
"]",
".",
"id",
"}",
"}",
")",
".",
"spread",
"(",
"function",
"(",
"role",
",",
"created",
")",
"{",
"return",
"role",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"res",
".",
"database",
"(",
"err",
")",
"}",
")",
";",
"}",
")",
";",
"return",
"Promise",
".",
"all",
"(",
"roles",
")",
";",
"}"
] |
Adds a roles to owner
@param {Array<String>} roles Which roles
@returns {Promise.<Instance>}
|
[
"Adds",
"a",
"roles",
"to",
"owner"
] |
b6ca29330ce518b7f909755cad70a42f6add3fed
|
https://github.com/co3moz/gluon/blob/b6ca29330ce518b7f909755cad70a42f6add3fed/gluon.js#L218-L238
|
|
39,107 |
co3moz/gluon
|
gluon.js
|
function (role) {
return Role.destroy({
where: {
code: role,
ownerId: req[options.auth.model].id
},
limit: 1
}).catch(function (err) {
res.database(err)
});
}
|
javascript
|
function (role) {
return Role.destroy({
where: {
code: role,
ownerId: req[options.auth.model].id
},
limit: 1
}).catch(function (err) {
res.database(err)
});
}
|
[
"function",
"(",
"role",
")",
"{",
"return",
"Role",
".",
"destroy",
"(",
"{",
"where",
":",
"{",
"code",
":",
"role",
",",
"ownerId",
":",
"req",
"[",
"options",
".",
"auth",
".",
"model",
"]",
".",
"id",
"}",
",",
"limit",
":",
"1",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"res",
".",
"database",
"(",
"err",
")",
"}",
")",
";",
"}"
] |
Removes a role from owner
@param {String} role Which role
@returns {Promise.<Number>}
|
[
"Removes",
"a",
"role",
"from",
"owner"
] |
b6ca29330ce518b7f909755cad70a42f6add3fed
|
https://github.com/co3moz/gluon/blob/b6ca29330ce518b7f909755cad70a42f6add3fed/gluon.js#L247-L257
|
|
39,108 |
co3moz/gluon
|
gluon.js
|
function (role) {
return Role.count({
where: {
code: role,
ownerId: req[options.auth.model].id
},
limit: 1
}).then(function (data) {
return data == 1
}).catch(function (err) {
res.database(err)
});
}
|
javascript
|
function (role) {
return Role.count({
where: {
code: role,
ownerId: req[options.auth.model].id
},
limit: 1
}).then(function (data) {
return data == 1
}).catch(function (err) {
res.database(err)
});
}
|
[
"function",
"(",
"role",
")",
"{",
"return",
"Role",
".",
"count",
"(",
"{",
"where",
":",
"{",
"code",
":",
"role",
",",
"ownerId",
":",
"req",
"[",
"options",
".",
"auth",
".",
"model",
"]",
".",
"id",
"}",
",",
"limit",
":",
"1",
"}",
")",
".",
"then",
"(",
"function",
"(",
"data",
")",
"{",
"return",
"data",
"==",
"1",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"res",
".",
"database",
"(",
"err",
")",
"}",
")",
";",
"}"
] |
Checks for role
@param {String} role Which role
@returns {Promise.<Boolean>}
|
[
"Checks",
"for",
"role"
] |
b6ca29330ce518b7f909755cad70a42f6add3fed
|
https://github.com/co3moz/gluon/blob/b6ca29330ce518b7f909755cad70a42f6add3fed/gluon.js#L285-L297
|
|
39,109 |
co3moz/gluon
|
gluon.js
|
function (roles) {
return Role.count({
where: {
code: {
$in: roles
},
ownerId: req[options.auth.model].id
}
}).then(function (data) {
return data == roles.length
}).catch(function (err) {
res.database(err)
});
}
|
javascript
|
function (roles) {
return Role.count({
where: {
code: {
$in: roles
},
ownerId: req[options.auth.model].id
}
}).then(function (data) {
return data == roles.length
}).catch(function (err) {
res.database(err)
});
}
|
[
"function",
"(",
"roles",
")",
"{",
"return",
"Role",
".",
"count",
"(",
"{",
"where",
":",
"{",
"code",
":",
"{",
"$in",
":",
"roles",
"}",
",",
"ownerId",
":",
"req",
"[",
"options",
".",
"auth",
".",
"model",
"]",
".",
"id",
"}",
"}",
")",
".",
"then",
"(",
"function",
"(",
"data",
")",
"{",
"return",
"data",
"==",
"roles",
".",
"length",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"res",
".",
"database",
"(",
"err",
")",
"}",
")",
";",
"}"
] |
Checks for roles
@param {Array<String>} roles Which roles
@returns {Promise.<Boolean>}
|
[
"Checks",
"for",
"roles"
] |
b6ca29330ce518b7f909755cad70a42f6add3fed
|
https://github.com/co3moz/gluon/blob/b6ca29330ce518b7f909755cad70a42f6add3fed/gluon.js#L305-L318
|
|
39,110 |
reklatsmasters/btparse
|
lib/avltree.js
|
create
|
function create(key, value) {
if (!Buffer.isBuffer(key)) {
throw new TypeError('expected buffer')
}
return {
key,
value,
left: null,
right: null,
height: 0
}
}
|
javascript
|
function create(key, value) {
if (!Buffer.isBuffer(key)) {
throw new TypeError('expected buffer')
}
return {
key,
value,
left: null,
right: null,
height: 0
}
}
|
[
"function",
"create",
"(",
"key",
",",
"value",
")",
"{",
"if",
"(",
"!",
"Buffer",
".",
"isBuffer",
"(",
"key",
")",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'expected buffer'",
")",
"}",
"return",
"{",
"key",
",",
"value",
",",
"left",
":",
"null",
",",
"right",
":",
"null",
",",
"height",
":",
"0",
"}",
"}"
] |
create new AVL tree node
@returns {{key: null, value: null, height: number, left: null, right: null}}
|
[
"create",
"new",
"AVL",
"tree",
"node"
] |
caacdfd3cd24fb2e68d67f0dab64dd5ba8947ad9
|
https://github.com/reklatsmasters/btparse/blob/caacdfd3cd24fb2e68d67f0dab64dd5ba8947ad9/lib/avltree.js#L15-L27
|
39,111 |
reklatsmasters/btparse
|
lib/avltree.js
|
compare
|
function compare(tree_key, key) {
let buf
if (Buffer.isBuffer(key)) {
buf = key
} else if (typeof key == 'string') {
buf = Buffer.from(key)
} else {
throw new TypeError('Argument `key` must be a Buffer or a string')
}
return Buffer.compare(tree_key, buf)
}
|
javascript
|
function compare(tree_key, key) {
let buf
if (Buffer.isBuffer(key)) {
buf = key
} else if (typeof key == 'string') {
buf = Buffer.from(key)
} else {
throw new TypeError('Argument `key` must be a Buffer or a string')
}
return Buffer.compare(tree_key, buf)
}
|
[
"function",
"compare",
"(",
"tree_key",
",",
"key",
")",
"{",
"let",
"buf",
"if",
"(",
"Buffer",
".",
"isBuffer",
"(",
"key",
")",
")",
"{",
"buf",
"=",
"key",
"}",
"else",
"if",
"(",
"typeof",
"key",
"==",
"'string'",
")",
"{",
"buf",
"=",
"Buffer",
".",
"from",
"(",
"key",
")",
"}",
"else",
"{",
"throw",
"new",
"TypeError",
"(",
"'Argument `key` must be a Buffer or a string'",
")",
"}",
"return",
"Buffer",
".",
"compare",
"(",
"tree_key",
",",
"buf",
")",
"}"
] |
compare 2 keys
@param tree_key {Buffer}
@param key {string|Buffer}
@returns {number}
|
[
"compare",
"2",
"keys"
] |
caacdfd3cd24fb2e68d67f0dab64dd5ba8947ad9
|
https://github.com/reklatsmasters/btparse/blob/caacdfd3cd24fb2e68d67f0dab64dd5ba8947ad9/lib/avltree.js#L35-L47
|
39,112 |
reklatsmasters/btparse
|
lib/avltree.js
|
lookup
|
function lookup(tree, key) {
if (!tree) {
return null
}
switch (compare(tree.key, key)) {
case 0:
return tree
case 1:
return lookup(tree.right, key)
case -1:
return lookup(tree.left, key)
default:
break
}
}
|
javascript
|
function lookup(tree, key) {
if (!tree) {
return null
}
switch (compare(tree.key, key)) {
case 0:
return tree
case 1:
return lookup(tree.right, key)
case -1:
return lookup(tree.left, key)
default:
break
}
}
|
[
"function",
"lookup",
"(",
"tree",
",",
"key",
")",
"{",
"if",
"(",
"!",
"tree",
")",
"{",
"return",
"null",
"}",
"switch",
"(",
"compare",
"(",
"tree",
".",
"key",
",",
"key",
")",
")",
"{",
"case",
"0",
":",
"return",
"tree",
"case",
"1",
":",
"return",
"lookup",
"(",
"tree",
".",
"right",
",",
"key",
")",
"case",
"-",
"1",
":",
"return",
"lookup",
"(",
"tree",
".",
"left",
",",
"key",
")",
"default",
":",
"break",
"}",
"}"
] |
search `key` in AVL tree
@param tree {Object}
@param key {Buffer|String}
@returns {Buffer|Object|null}
|
[
"search",
"key",
"in",
"AVL",
"tree"
] |
caacdfd3cd24fb2e68d67f0dab64dd5ba8947ad9
|
https://github.com/reklatsmasters/btparse/blob/caacdfd3cd24fb2e68d67f0dab64dd5ba8947ad9/lib/avltree.js#L55-L70
|
39,113 |
logikum/md-site-engine
|
source/models/metadata.js
|
function( definitions, path ) {
//region Search engine properties
/**
* Gets the title of the document.
* @type {string}
* @readonly
*/
this.title = '';
/**
* Gets the keywords of the document.
* @type {string}
* @readonly
*/
this.keywords = '';
/**
* Gets the description of the document.
* @type {string}
* @readonly
*/
this.description = '';
//endregion
//region Menu properties
/**
* Gets the text of the menu item.
* @type {string}
* @readonly
*/
this.text = '';
/**
* Gets the order of the menu item.
* @type {string}
* @readonly
*/
this.order = 0;
/**
* Indicates whether the menu item is displayed.
* @type {Boolean}
* @readonly
*/
this.hidden = false;
/**
* Indicates whether the menu item is a leaf with hidden children,
* i.e. a truncated menu node.
* @type {Boolean}
* @readonly
*/
this.umbel = false;
//endregion
//region Page properties
/**
* Gets the identifier of the content, it defaults to the path.
* @type {string}
* @readonly
*/
this.id = '';
/**
* Gets the path of the content.
* @type {string}
* @readonly
*/
this.path = path;
/**
* Gets the name of a custom document for the content.
* @type {string}
* @readonly
*/
this.document = '';
/**
* Gets the name of a custom layout for the content.
* @type {string}
* @readonly
*/
this.layout = '';
/**
* Gets the token collection for the segments found on the content.
* @type {object}
* @readonly
*/
this.segments = { };
/**
* Indicates whether the content is enabled for search.
* @type {Boolean}
* @readonly
*/
this.searchable = true;
//endregion
// Set the defined properties of the content.
Object.assign( this, getMainProperties( definitions ) );
Object.assign( this.segments, getSegmentProperties( definitions ) );
// Set default identity.
if (!this.id)
this.id = path;
// Immutable object.
freeze( this );
}
|
javascript
|
function( definitions, path ) {
//region Search engine properties
/**
* Gets the title of the document.
* @type {string}
* @readonly
*/
this.title = '';
/**
* Gets the keywords of the document.
* @type {string}
* @readonly
*/
this.keywords = '';
/**
* Gets the description of the document.
* @type {string}
* @readonly
*/
this.description = '';
//endregion
//region Menu properties
/**
* Gets the text of the menu item.
* @type {string}
* @readonly
*/
this.text = '';
/**
* Gets the order of the menu item.
* @type {string}
* @readonly
*/
this.order = 0;
/**
* Indicates whether the menu item is displayed.
* @type {Boolean}
* @readonly
*/
this.hidden = false;
/**
* Indicates whether the menu item is a leaf with hidden children,
* i.e. a truncated menu node.
* @type {Boolean}
* @readonly
*/
this.umbel = false;
//endregion
//region Page properties
/**
* Gets the identifier of the content, it defaults to the path.
* @type {string}
* @readonly
*/
this.id = '';
/**
* Gets the path of the content.
* @type {string}
* @readonly
*/
this.path = path;
/**
* Gets the name of a custom document for the content.
* @type {string}
* @readonly
*/
this.document = '';
/**
* Gets the name of a custom layout for the content.
* @type {string}
* @readonly
*/
this.layout = '';
/**
* Gets the token collection for the segments found on the content.
* @type {object}
* @readonly
*/
this.segments = { };
/**
* Indicates whether the content is enabled for search.
* @type {Boolean}
* @readonly
*/
this.searchable = true;
//endregion
// Set the defined properties of the content.
Object.assign( this, getMainProperties( definitions ) );
Object.assign( this.segments, getSegmentProperties( definitions ) );
// Set default identity.
if (!this.id)
this.id = path;
// Immutable object.
freeze( this );
}
|
[
"function",
"(",
"definitions",
",",
"path",
")",
"{",
"//region Search engine properties",
"/**\n * Gets the title of the document.\n * @type {string}\n * @readonly\n */",
"this",
".",
"title",
"=",
"''",
";",
"/**\n * Gets the keywords of the document.\n * @type {string}\n * @readonly\n */",
"this",
".",
"keywords",
"=",
"''",
";",
"/**\n * Gets the description of the document.\n * @type {string}\n * @readonly\n */",
"this",
".",
"description",
"=",
"''",
";",
"//endregion",
"//region Menu properties",
"/**\n * Gets the text of the menu item.\n * @type {string}\n * @readonly\n */",
"this",
".",
"text",
"=",
"''",
";",
"/**\n * Gets the order of the menu item.\n * @type {string}\n * @readonly\n */",
"this",
".",
"order",
"=",
"0",
";",
"/**\n * Indicates whether the menu item is displayed.\n * @type {Boolean}\n * @readonly\n */",
"this",
".",
"hidden",
"=",
"false",
";",
"/**\n * Indicates whether the menu item is a leaf with hidden children,\n * i.e. a truncated menu node.\n * @type {Boolean}\n * @readonly\n */",
"this",
".",
"umbel",
"=",
"false",
";",
"//endregion",
"//region Page properties",
"/**\n * Gets the identifier of the content, it defaults to the path.\n * @type {string}\n * @readonly\n */",
"this",
".",
"id",
"=",
"''",
";",
"/**\n * Gets the path of the content.\n * @type {string}\n * @readonly\n */",
"this",
".",
"path",
"=",
"path",
";",
"/**\n * Gets the name of a custom document for the content.\n * @type {string}\n * @readonly\n */",
"this",
".",
"document",
"=",
"''",
";",
"/**\n * Gets the name of a custom layout for the content.\n * @type {string}\n * @readonly\n */",
"this",
".",
"layout",
"=",
"''",
";",
"/**\n * Gets the token collection for the segments found on the content.\n * @type {object}\n * @readonly\n */",
"this",
".",
"segments",
"=",
"{",
"}",
";",
"/**\n * Indicates whether the content is enabled for search.\n * @type {Boolean}\n * @readonly\n */",
"this",
".",
"searchable",
"=",
"true",
";",
"//endregion",
"// Set the defined properties of the content.",
"Object",
".",
"assign",
"(",
"this",
",",
"getMainProperties",
"(",
"definitions",
")",
")",
";",
"Object",
".",
"assign",
"(",
"this",
".",
"segments",
",",
"getSegmentProperties",
"(",
"definitions",
")",
")",
";",
"// Set default identity.",
"if",
"(",
"!",
"this",
".",
"id",
")",
"this",
".",
"id",
"=",
"path",
";",
"// Immutable object.",
"freeze",
"(",
"this",
")",
";",
"}"
] |
Represents the metadata of a content.
@param {object} definitions - A collection of properties.
@param {string} path - The path of the current content.
@constructor
|
[
"Represents",
"the",
"metadata",
"of",
"a",
"content",
"."
] |
1abb0d9d6ea2c84690b9ffdde6b7ff7d49288784
|
https://github.com/logikum/md-site-engine/blob/1abb0d9d6ea2c84690b9ffdde6b7ff7d49288784/source/models/metadata.js#L35-L151
|
|
39,114 |
wangtao0101/parse-import-es6
|
src/parseImport.js
|
findLeadingComments
|
function findLeadingComments(comments, index, beginIndex, first) {
const leadComments = [];
if (first && ignoreComment.test(comments[index].raw)) {
return leadComments;
}
let backIndex = index - 1;
while (backIndex >= beginIndex &&
(comments[backIndex].loc.end.line + 1 === comments[backIndex + 1].loc.start.line
|| comments[backIndex].loc.end.line === comments[backIndex + 1].loc.start.line)) {
if (first && ignoreComment.test(comments[backIndex].raw)) {
break;
}
backIndex -= 1;
}
for (let ind = backIndex + 1; ind <= index; ind += 1) {
leadComments.push(comments[ind]);
}
return leadComments;
}
|
javascript
|
function findLeadingComments(comments, index, beginIndex, first) {
const leadComments = [];
if (first && ignoreComment.test(comments[index].raw)) {
return leadComments;
}
let backIndex = index - 1;
while (backIndex >= beginIndex &&
(comments[backIndex].loc.end.line + 1 === comments[backIndex + 1].loc.start.line
|| comments[backIndex].loc.end.line === comments[backIndex + 1].loc.start.line)) {
if (first && ignoreComment.test(comments[backIndex].raw)) {
break;
}
backIndex -= 1;
}
for (let ind = backIndex + 1; ind <= index; ind += 1) {
leadComments.push(comments[ind]);
}
return leadComments;
}
|
[
"function",
"findLeadingComments",
"(",
"comments",
",",
"index",
",",
"beginIndex",
",",
"first",
")",
"{",
"const",
"leadComments",
"=",
"[",
"]",
";",
"if",
"(",
"first",
"&&",
"ignoreComment",
".",
"test",
"(",
"comments",
"[",
"index",
"]",
".",
"raw",
")",
")",
"{",
"return",
"leadComments",
";",
"}",
"let",
"backIndex",
"=",
"index",
"-",
"1",
";",
"while",
"(",
"backIndex",
">=",
"beginIndex",
"&&",
"(",
"comments",
"[",
"backIndex",
"]",
".",
"loc",
".",
"end",
".",
"line",
"+",
"1",
"===",
"comments",
"[",
"backIndex",
"+",
"1",
"]",
".",
"loc",
".",
"start",
".",
"line",
"||",
"comments",
"[",
"backIndex",
"]",
".",
"loc",
".",
"end",
".",
"line",
"===",
"comments",
"[",
"backIndex",
"+",
"1",
"]",
".",
"loc",
".",
"start",
".",
"line",
")",
")",
"{",
"if",
"(",
"first",
"&&",
"ignoreComment",
".",
"test",
"(",
"comments",
"[",
"backIndex",
"]",
".",
"raw",
")",
")",
"{",
"break",
";",
"}",
"backIndex",
"-=",
"1",
";",
"}",
"for",
"(",
"let",
"ind",
"=",
"backIndex",
"+",
"1",
";",
"ind",
"<=",
"index",
";",
"ind",
"+=",
"1",
")",
"{",
"leadComments",
".",
"push",
"(",
"comments",
"[",
"ind",
"]",
")",
";",
"}",
"return",
"leadComments",
";",
"}"
] |
return leading comment list
@param {*list<comment>} comments
@param {*} the last match leading comment of one import
@param {*} beginIndex the potential begin of the comment index of the import
@param {*} first whether first import
|
[
"return",
"leading",
"comment",
"list"
] |
c0ada33342b07e58cba83c27b6f1d92e522f35ac
|
https://github.com/wangtao0101/parse-import-es6/blob/c0ada33342b07e58cba83c27b6f1d92e522f35ac/src/parseImport.js#L78-L96
|
39,115 |
ssmolkin1/my-little-schemer
|
src/prim/ops.js
|
loadTo
|
function loadTo(S) {
/**
* Takes a non-empty list as its argument and return the first member of the argument.
* @param {list} l
* @returns {*}
* @example
* // returns 1
* car([1, 2]);
*/
S.car = (l) => {
if (S.isAtom(l) || S.isNull(l)) {
throw new TypeError('The Law of Car: You can only take the car of a non-empty list.');
}
let result = l[0];
// Clone there result if it is a list or an object to keep the function pure
if (S.isList(result)) {
result = result.slice();
}
if (S.isObject(result)) {
result = Object.assign({}, result);
}
return result;
};
/**
* Takes a non-empty list as its argument and returns a new list contaiting the same members
* as the argument, except for the car.
* @param {list} l
* @return {list}
* @example
* // returns [2]
* cdr([1, 2]);
*/
S.cdr = (l) => {
if (S.isAtom(l) || S.isNull(l)) {
throw new TypeError('The Law of Cdr: You can only take the cdr of a non-empty list.');
}
return l.slice(1);
};
/**
* Takes two arguments, the second of which must be a list, and returns a new list comtaining
* the first argument and the elements of the second argument.
* @param {*} exp
* @param {list} l
* @returns {list}
* @example
* // returns ['cat', 'dog']
* cons('cat', ['dog']);
*/
S.cons = (exp, l) => {
if (S.isAtom(l)) {
throw new TypeError('The Law of Cons: The second argument must be a list.');
}
const n = l.slice(0);
n.unshift(exp);
return n;
};
/**
* Takes any expression as its argument and returns the expression unevaluated. Should only
* be used inside S-Expressions and jS-Expressions.
* @param {*} exp
* @returns {*}
* @example
* // returns ['cat', 'dog']
* evaluate(`(cons cat (dog))`);
*
* // returns ['cons', 'cat', ['dog']]
* evaluate(`(quote (cons cat (dog)))`);
*/
S.quote = exp => exp;
/**
* Adds 1 to a number.
* @param {number} n
* @returns {number}
* @example
* // returns 2
* add1(1);
*/
S.add1 = (n) => {
if (!S.isNumber(n)) {
throw new TypeError('Arithmetic operations can only be done on numbers.');
}
return n + 1;
};
/**
* Subtracts 1 from a number.
* @param {number} n
* @returns {number}
* @example
* // returns 1
* sub1(2);
*/
S.sub1 = (n) => {
if (!S.isNumber(n)) {
throw new TypeError('Arithmetic operations can only be done on numbers.');
}
return n - 1;
};
/**
* The applicative order Y-combinator.
* @param {function} le
*/
S.Y = le => (f => f(f))(f => le(x => (f(f))(x)));
}
|
javascript
|
function loadTo(S) {
/**
* Takes a non-empty list as its argument and return the first member of the argument.
* @param {list} l
* @returns {*}
* @example
* // returns 1
* car([1, 2]);
*/
S.car = (l) => {
if (S.isAtom(l) || S.isNull(l)) {
throw new TypeError('The Law of Car: You can only take the car of a non-empty list.');
}
let result = l[0];
// Clone there result if it is a list or an object to keep the function pure
if (S.isList(result)) {
result = result.slice();
}
if (S.isObject(result)) {
result = Object.assign({}, result);
}
return result;
};
/**
* Takes a non-empty list as its argument and returns a new list contaiting the same members
* as the argument, except for the car.
* @param {list} l
* @return {list}
* @example
* // returns [2]
* cdr([1, 2]);
*/
S.cdr = (l) => {
if (S.isAtom(l) || S.isNull(l)) {
throw new TypeError('The Law of Cdr: You can only take the cdr of a non-empty list.');
}
return l.slice(1);
};
/**
* Takes two arguments, the second of which must be a list, and returns a new list comtaining
* the first argument and the elements of the second argument.
* @param {*} exp
* @param {list} l
* @returns {list}
* @example
* // returns ['cat', 'dog']
* cons('cat', ['dog']);
*/
S.cons = (exp, l) => {
if (S.isAtom(l)) {
throw new TypeError('The Law of Cons: The second argument must be a list.');
}
const n = l.slice(0);
n.unshift(exp);
return n;
};
/**
* Takes any expression as its argument and returns the expression unevaluated. Should only
* be used inside S-Expressions and jS-Expressions.
* @param {*} exp
* @returns {*}
* @example
* // returns ['cat', 'dog']
* evaluate(`(cons cat (dog))`);
*
* // returns ['cons', 'cat', ['dog']]
* evaluate(`(quote (cons cat (dog)))`);
*/
S.quote = exp => exp;
/**
* Adds 1 to a number.
* @param {number} n
* @returns {number}
* @example
* // returns 2
* add1(1);
*/
S.add1 = (n) => {
if (!S.isNumber(n)) {
throw new TypeError('Arithmetic operations can only be done on numbers.');
}
return n + 1;
};
/**
* Subtracts 1 from a number.
* @param {number} n
* @returns {number}
* @example
* // returns 1
* sub1(2);
*/
S.sub1 = (n) => {
if (!S.isNumber(n)) {
throw new TypeError('Arithmetic operations can only be done on numbers.');
}
return n - 1;
};
/**
* The applicative order Y-combinator.
* @param {function} le
*/
S.Y = le => (f => f(f))(f => le(x => (f(f))(x)));
}
|
[
"function",
"loadTo",
"(",
"S",
")",
"{",
"/**\n * Takes a non-empty list as its argument and return the first member of the argument.\n * @param {list} l\n * @returns {*}\n * @example\n * // returns 1\n * car([1, 2]);\n */",
"S",
".",
"car",
"=",
"(",
"l",
")",
"=>",
"{",
"if",
"(",
"S",
".",
"isAtom",
"(",
"l",
")",
"||",
"S",
".",
"isNull",
"(",
"l",
")",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'The Law of Car: You can only take the car of a non-empty list.'",
")",
";",
"}",
"let",
"result",
"=",
"l",
"[",
"0",
"]",
";",
"// Clone there result if it is a list or an object to keep the function pure",
"if",
"(",
"S",
".",
"isList",
"(",
"result",
")",
")",
"{",
"result",
"=",
"result",
".",
"slice",
"(",
")",
";",
"}",
"if",
"(",
"S",
".",
"isObject",
"(",
"result",
")",
")",
"{",
"result",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"result",
")",
";",
"}",
"return",
"result",
";",
"}",
";",
"/**\n * Takes a non-empty list as its argument and returns a new list contaiting the same members\n * as the argument, except for the car.\n * @param {list} l\n * @return {list}\n * @example\n * // returns [2]\n * cdr([1, 2]);\n */",
"S",
".",
"cdr",
"=",
"(",
"l",
")",
"=>",
"{",
"if",
"(",
"S",
".",
"isAtom",
"(",
"l",
")",
"||",
"S",
".",
"isNull",
"(",
"l",
")",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'The Law of Cdr: You can only take the cdr of a non-empty list.'",
")",
";",
"}",
"return",
"l",
".",
"slice",
"(",
"1",
")",
";",
"}",
";",
"/**\n * Takes two arguments, the second of which must be a list, and returns a new list comtaining\n * the first argument and the elements of the second argument.\n * @param {*} exp\n * @param {list} l\n * @returns {list}\n * @example\n * // returns ['cat', 'dog']\n * cons('cat', ['dog']);\n */",
"S",
".",
"cons",
"=",
"(",
"exp",
",",
"l",
")",
"=>",
"{",
"if",
"(",
"S",
".",
"isAtom",
"(",
"l",
")",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'The Law of Cons: The second argument must be a list.'",
")",
";",
"}",
"const",
"n",
"=",
"l",
".",
"slice",
"(",
"0",
")",
";",
"n",
".",
"unshift",
"(",
"exp",
")",
";",
"return",
"n",
";",
"}",
";",
"/**\n * Takes any expression as its argument and returns the expression unevaluated. Should only\n * be used inside S-Expressions and jS-Expressions.\n * @param {*} exp\n * @returns {*}\n * @example\n * // returns ['cat', 'dog']\n * evaluate(`(cons cat (dog))`);\n *\n * // returns ['cons', 'cat', ['dog']]\n * evaluate(`(quote (cons cat (dog)))`);\n */",
"S",
".",
"quote",
"=",
"exp",
"=>",
"exp",
";",
"/**\n * Adds 1 to a number.\n * @param {number} n\n * @returns {number}\n * @example\n * // returns 2\n * add1(1);\n */",
"S",
".",
"add1",
"=",
"(",
"n",
")",
"=>",
"{",
"if",
"(",
"!",
"S",
".",
"isNumber",
"(",
"n",
")",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'Arithmetic operations can only be done on numbers.'",
")",
";",
"}",
"return",
"n",
"+",
"1",
";",
"}",
";",
"/**\n * Subtracts 1 from a number.\n * @param {number} n\n * @returns {number}\n * @example\n * // returns 1\n * sub1(2);\n */",
"S",
".",
"sub1",
"=",
"(",
"n",
")",
"=>",
"{",
"if",
"(",
"!",
"S",
".",
"isNumber",
"(",
"n",
")",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'Arithmetic operations can only be done on numbers.'",
")",
";",
"}",
"return",
"n",
"-",
"1",
";",
"}",
";",
"/**\n * The applicative order Y-combinator.\n * @param {function} le\n */",
"S",
".",
"Y",
"=",
"le",
"=>",
"(",
"f",
"=>",
"f",
"(",
"f",
")",
")",
"(",
"f",
"=>",
"le",
"(",
"x",
"=>",
"(",
"f",
"(",
"f",
")",
")",
"(",
"x",
")",
")",
")",
";",
"}"
] |
Inserts methods into namespace
@param {object} S The namepsace into which the methods are inserted.
@returns {void}
|
[
"Inserts",
"methods",
"into",
"namespace"
] |
618b9e94ffd0cc7f45a458bdf9eaa14aa90956b3
|
https://github.com/ssmolkin1/my-little-schemer/blob/618b9e94ffd0cc7f45a458bdf9eaa14aa90956b3/src/prim/ops.js#L6-L124
|
39,116 |
codekirei/columnize-array
|
lib/columns.js
|
Columns
|
function Columns(props) {
// require and bind methods
//----------------------------------------------------------
[ 'bindState'
, 'solve'
].forEach(method =>
this.constructor.prototype[method] = require(`./methods/${method}`)
)
// bind props (immutable) and state (mutable)
//----------------------------------------------------------
this.props = props
this.bindState(1)
// find solution state
//----------------------------------------------------------
this.solve()
}
|
javascript
|
function Columns(props) {
// require and bind methods
//----------------------------------------------------------
[ 'bindState'
, 'solve'
].forEach(method =>
this.constructor.prototype[method] = require(`./methods/${method}`)
)
// bind props (immutable) and state (mutable)
//----------------------------------------------------------
this.props = props
this.bindState(1)
// find solution state
//----------------------------------------------------------
this.solve()
}
|
[
"function",
"Columns",
"(",
"props",
")",
"{",
"// require and bind methods",
"//----------------------------------------------------------",
"[",
"'bindState'",
",",
"'solve'",
"]",
".",
"forEach",
"(",
"method",
"=>",
"this",
".",
"constructor",
".",
"prototype",
"[",
"method",
"]",
"=",
"require",
"(",
"`",
"${",
"method",
"}",
"`",
")",
")",
"// bind props (immutable) and state (mutable)",
"//----------------------------------------------------------",
"this",
".",
"props",
"=",
"props",
"this",
".",
"bindState",
"(",
"1",
")",
"// find solution state",
"//----------------------------------------------------------",
"this",
".",
"solve",
"(",
")",
"}"
] |
Constructor with columnization logic.
@param {Object} props - immutable properties that dictate columnization
@returns {Object} instance of self
|
[
"Constructor",
"with",
"columnization",
"logic",
"."
] |
ba100d1d9cf707fa249a58fa177d6b26ec131278
|
https://github.com/codekirei/columnize-array/blob/ba100d1d9cf707fa249a58fa177d6b26ec131278/lib/columns.js#L9-L27
|
39,117 |
juttle/juttle-viz
|
src/lib/utils/string-utils.js
|
function(str, maxLength, where) {
if (!_.isString(str)) {
return str;
}
var strLength = str.length;
if (strLength <= maxLength) {
return str;
}
// limit the length of the series name by dropping characters and inserting an ELLIPSIS where specified
switch(where) {
case 'start':
str = ELLIPSIS + str.substr(strLength - maxLength - 1);
break;
case 'end':
str = str.substr(0, Math.floor(maxLength) - 1) + ELLIPSIS;
break;
default:
str = str.substr(0, Math.floor(maxLength/2) - 1) + ELLIPSIS + str.substr(-1 * (Math.floor(maxLength/2) + 1));
}
return str;
}
|
javascript
|
function(str, maxLength, where) {
if (!_.isString(str)) {
return str;
}
var strLength = str.length;
if (strLength <= maxLength) {
return str;
}
// limit the length of the series name by dropping characters and inserting an ELLIPSIS where specified
switch(where) {
case 'start':
str = ELLIPSIS + str.substr(strLength - maxLength - 1);
break;
case 'end':
str = str.substr(0, Math.floor(maxLength) - 1) + ELLIPSIS;
break;
default:
str = str.substr(0, Math.floor(maxLength/2) - 1) + ELLIPSIS + str.substr(-1 * (Math.floor(maxLength/2) + 1));
}
return str;
}
|
[
"function",
"(",
"str",
",",
"maxLength",
",",
"where",
")",
"{",
"if",
"(",
"!",
"_",
".",
"isString",
"(",
"str",
")",
")",
"{",
"return",
"str",
";",
"}",
"var",
"strLength",
"=",
"str",
".",
"length",
";",
"if",
"(",
"strLength",
"<=",
"maxLength",
")",
"{",
"return",
"str",
";",
"}",
"// limit the length of the series name by dropping characters and inserting an ELLIPSIS where specified",
"switch",
"(",
"where",
")",
"{",
"case",
"'start'",
":",
"str",
"=",
"ELLIPSIS",
"+",
"str",
".",
"substr",
"(",
"strLength",
"-",
"maxLength",
"-",
"1",
")",
";",
"break",
";",
"case",
"'end'",
":",
"str",
"=",
"str",
".",
"substr",
"(",
"0",
",",
"Math",
".",
"floor",
"(",
"maxLength",
")",
"-",
"1",
")",
"+",
"ELLIPSIS",
";",
"break",
";",
"default",
":",
"str",
"=",
"str",
".",
"substr",
"(",
"0",
",",
"Math",
".",
"floor",
"(",
"maxLength",
"/",
"2",
")",
"-",
"1",
")",
"+",
"ELLIPSIS",
"+",
"str",
".",
"substr",
"(",
"-",
"1",
"*",
"(",
"Math",
".",
"floor",
"(",
"maxLength",
"/",
"2",
")",
"+",
"1",
")",
")",
";",
"}",
"return",
"str",
";",
"}"
] |
Truncate string to a maxLength
@param {[type]} str [description]
@param {[type]} maxLength [description]
@param {[type]} where where to truncate and put the ellipsis (start, middle, or end). defaults to middle.
@return {[type]} [description]
|
[
"Truncate",
"string",
"to",
"a",
"maxLength"
] |
834d13a66256d9c9177f46968b0ef05b8143e762
|
https://github.com/juttle/juttle-viz/blob/834d13a66256d9c9177f46968b0ef05b8143e762/src/lib/utils/string-utils.js#L12-L36
|
|
39,118 |
logikum/md-site-engine
|
source/readers/process-contents.js
|
processContents
|
function processContents(
contentDir, contentRoot,
submenuFile, contentStock, menuStock,
references, language, renderer
) {
var typeName = 'Content';
// Read directory items.
var items = fs.readdirSync( path.join( process.cwd(), contentDir ) );
items.forEach( function ( item ) {
// Get full path of item.
var itemPath = path.join( contentDir, item );
// Get item info.
var stats = fs.statSync( path.join( process.cwd(), itemPath ) );
if (stats.isDirectory()) {
// Determine content path.
var directoryPath = contentRoot + '/' + item;
// Create menu item.
var directoryNode = MenuBuilder.buildSubMenu(
menuStock, path.join( itemPath, submenuFile ), directoryPath
);
// Read subdirectory.
processContents(
itemPath,
directoryPath,
submenuFile,
contentStock,
directoryNode ? directoryNode.children : menuStock,
references,
language,
renderer
);
}
else if (stats.isFile()) {
var ext = path.extname( item );
var basename = path.basename( item, ext );
var isMarkdown = true;
switch (ext) {
case '.html':
isMarkdown = false;
case '.md':
// Read the content file.
var content = getContent( itemPath, isMarkdown ? "markdown" : 'html' );
// Set content path.
content.path = contentRoot + '/' + basename;
// Read content definition.
var definition = getDefinition( content );
// Contains menu info?
if (definition.order || definition.text)
// Create menu item.
MenuBuilder.createMenuItem( menuStock, definition, content.path, false );
// Generate HTML from markdown text.
if (isMarkdown)
content.html = marked(
content.html + '\n' + references.get( language ),
{ renderer: renderer }
);
// Omit menu separator.
if (definition.text !== '---')
// Store content.
contentStock.add( content, definition );
logger.fileProcessed( typeName, itemPath );
break;
default:
if (item !== submenuFile)
logger.fileSkipped( typeName, itemPath );
break;
}
}
} );
}
|
javascript
|
function processContents(
contentDir, contentRoot,
submenuFile, contentStock, menuStock,
references, language, renderer
) {
var typeName = 'Content';
// Read directory items.
var items = fs.readdirSync( path.join( process.cwd(), contentDir ) );
items.forEach( function ( item ) {
// Get full path of item.
var itemPath = path.join( contentDir, item );
// Get item info.
var stats = fs.statSync( path.join( process.cwd(), itemPath ) );
if (stats.isDirectory()) {
// Determine content path.
var directoryPath = contentRoot + '/' + item;
// Create menu item.
var directoryNode = MenuBuilder.buildSubMenu(
menuStock, path.join( itemPath, submenuFile ), directoryPath
);
// Read subdirectory.
processContents(
itemPath,
directoryPath,
submenuFile,
contentStock,
directoryNode ? directoryNode.children : menuStock,
references,
language,
renderer
);
}
else if (stats.isFile()) {
var ext = path.extname( item );
var basename = path.basename( item, ext );
var isMarkdown = true;
switch (ext) {
case '.html':
isMarkdown = false;
case '.md':
// Read the content file.
var content = getContent( itemPath, isMarkdown ? "markdown" : 'html' );
// Set content path.
content.path = contentRoot + '/' + basename;
// Read content definition.
var definition = getDefinition( content );
// Contains menu info?
if (definition.order || definition.text)
// Create menu item.
MenuBuilder.createMenuItem( menuStock, definition, content.path, false );
// Generate HTML from markdown text.
if (isMarkdown)
content.html = marked(
content.html + '\n' + references.get( language ),
{ renderer: renderer }
);
// Omit menu separator.
if (definition.text !== '---')
// Store content.
contentStock.add( content, definition );
logger.fileProcessed( typeName, itemPath );
break;
default:
if (item !== submenuFile)
logger.fileSkipped( typeName, itemPath );
break;
}
}
} );
}
|
[
"function",
"processContents",
"(",
"contentDir",
",",
"contentRoot",
",",
"submenuFile",
",",
"contentStock",
",",
"menuStock",
",",
"references",
",",
"language",
",",
"renderer",
")",
"{",
"var",
"typeName",
"=",
"'Content'",
";",
"// Read directory items.",
"var",
"items",
"=",
"fs",
".",
"readdirSync",
"(",
"path",
".",
"join",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"contentDir",
")",
")",
";",
"items",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"// Get full path of item.",
"var",
"itemPath",
"=",
"path",
".",
"join",
"(",
"contentDir",
",",
"item",
")",
";",
"// Get item info.",
"var",
"stats",
"=",
"fs",
".",
"statSync",
"(",
"path",
".",
"join",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"itemPath",
")",
")",
";",
"if",
"(",
"stats",
".",
"isDirectory",
"(",
")",
")",
"{",
"// Determine content path.",
"var",
"directoryPath",
"=",
"contentRoot",
"+",
"'/'",
"+",
"item",
";",
"// Create menu item.",
"var",
"directoryNode",
"=",
"MenuBuilder",
".",
"buildSubMenu",
"(",
"menuStock",
",",
"path",
".",
"join",
"(",
"itemPath",
",",
"submenuFile",
")",
",",
"directoryPath",
")",
";",
"// Read subdirectory.",
"processContents",
"(",
"itemPath",
",",
"directoryPath",
",",
"submenuFile",
",",
"contentStock",
",",
"directoryNode",
"?",
"directoryNode",
".",
"children",
":",
"menuStock",
",",
"references",
",",
"language",
",",
"renderer",
")",
";",
"}",
"else",
"if",
"(",
"stats",
".",
"isFile",
"(",
")",
")",
"{",
"var",
"ext",
"=",
"path",
".",
"extname",
"(",
"item",
")",
";",
"var",
"basename",
"=",
"path",
".",
"basename",
"(",
"item",
",",
"ext",
")",
";",
"var",
"isMarkdown",
"=",
"true",
";",
"switch",
"(",
"ext",
")",
"{",
"case",
"'.html'",
":",
"isMarkdown",
"=",
"false",
";",
"case",
"'.md'",
":",
"// Read the content file.",
"var",
"content",
"=",
"getContent",
"(",
"itemPath",
",",
"isMarkdown",
"?",
"\"markdown\"",
":",
"'html'",
")",
";",
"// Set content path.",
"content",
".",
"path",
"=",
"contentRoot",
"+",
"'/'",
"+",
"basename",
";",
"// Read content definition.",
"var",
"definition",
"=",
"getDefinition",
"(",
"content",
")",
";",
"// Contains menu info?",
"if",
"(",
"definition",
".",
"order",
"||",
"definition",
".",
"text",
")",
"// Create menu item.",
"MenuBuilder",
".",
"createMenuItem",
"(",
"menuStock",
",",
"definition",
",",
"content",
".",
"path",
",",
"false",
")",
";",
"// Generate HTML from markdown text.",
"if",
"(",
"isMarkdown",
")",
"content",
".",
"html",
"=",
"marked",
"(",
"content",
".",
"html",
"+",
"'\\n'",
"+",
"references",
".",
"get",
"(",
"language",
")",
",",
"{",
"renderer",
":",
"renderer",
"}",
")",
";",
"// Omit menu separator.",
"if",
"(",
"definition",
".",
"text",
"!==",
"'---'",
")",
"// Store content.",
"contentStock",
".",
"add",
"(",
"content",
",",
"definition",
")",
";",
"logger",
".",
"fileProcessed",
"(",
"typeName",
",",
"itemPath",
")",
";",
"break",
";",
"default",
":",
"if",
"(",
"item",
"!==",
"submenuFile",
")",
"logger",
".",
"fileSkipped",
"(",
"typeName",
",",
"itemPath",
")",
";",
"break",
";",
"}",
"}",
"}",
")",
";",
"}"
] |
Processes the items of a content sub-directory.
@param {string} contentDir - The path of the content sub-directory.
@param {string} contentRoot - The base URL of the content sub-directory.
@param {string} submenuFile - The path of the menu level file (__submenu.txt).
@param {ContentStock} contentStock - The content storage of the language.
@param {MenuStock} menuStock - The current menu node (a menu level storage).
@param {ReferenceDrawer} references - The reference storage.
@param {string} language - The language of the content sub-directory.
@param {marked.Renderer} renderer - The custom markdown renderer.
|
[
"Processes",
"the",
"items",
"of",
"a",
"content",
"sub",
"-",
"directory",
"."
] |
1abb0d9d6ea2c84690b9ffdde6b7ff7d49288784
|
https://github.com/logikum/md-site-engine/blob/1abb0d9d6ea2c84690b9ffdde6b7ff7d49288784/source/readers/process-contents.js#L22-L106
|
39,119 |
oramics/synth-kit
|
lib/instruments/tonewheel.js
|
toState
|
function toState (preset) {
if (preset) {
const norm = (preset.replace(/[^012345678]/g, "") + "000000000").slice(0, 9)
const gains = norm.split("").map((n) => Math.abs(+n / 8))
return {
bank: { gains }
}
}
}
|
javascript
|
function toState (preset) {
if (preset) {
const norm = (preset.replace(/[^012345678]/g, "") + "000000000").slice(0, 9)
const gains = norm.split("").map((n) => Math.abs(+n / 8))
return {
bank: { gains }
}
}
}
|
[
"function",
"toState",
"(",
"preset",
")",
"{",
"if",
"(",
"preset",
")",
"{",
"const",
"norm",
"=",
"(",
"preset",
".",
"replace",
"(",
"/",
"[^012345678]",
"/",
"g",
",",
"\"\"",
")",
"+",
"\"000000000\"",
")",
".",
"slice",
"(",
"0",
",",
"9",
")",
"const",
"gains",
"=",
"norm",
".",
"split",
"(",
"\"\"",
")",
".",
"map",
"(",
"(",
"n",
")",
"=>",
"Math",
".",
"abs",
"(",
"+",
"n",
"/",
"8",
")",
")",
"return",
"{",
"bank",
":",
"{",
"gains",
"}",
"}",
"}",
"}"
] |
Given a preset, return a state fragment
|
[
"Given",
"a",
"preset",
"return",
"a",
"state",
"fragment"
] |
38de28d945241507e2bb195eb551aaff7c1c55d5
|
https://github.com/oramics/synth-kit/blob/38de28d945241507e2bb195eb551aaff7c1c55d5/lib/instruments/tonewheel.js#L45-L53
|
39,120 |
express-bem/express-bem
|
lib/engines.js
|
function (name, extension, engine) {
// add to storage
this[name] = engine.render || engine;
enginesByExtension[extension] = engine;
return this;
}
|
javascript
|
function (name, extension, engine) {
// add to storage
this[name] = engine.render || engine;
enginesByExtension[extension] = engine;
return this;
}
|
[
"function",
"(",
"name",
",",
"extension",
",",
"engine",
")",
"{",
"// add to storage",
"this",
"[",
"name",
"]",
"=",
"engine",
".",
"render",
"||",
"engine",
";",
"enginesByExtension",
"[",
"extension",
"]",
"=",
"engine",
";",
"return",
"this",
";",
"}"
] |
add bem engine
@param {String} [name]
@param {String} [extension]
@param {Function|Object} engine
@returns {Engines}
|
[
"add",
"bem",
"engine"
] |
6ea49e5ecdd8e949dd5051ecc5762e40cbcead9c
|
https://github.com/express-bem/express-bem/blob/6ea49e5ecdd8e949dd5051ecc5762e40cbcead9c/lib/engines.js#L22-L28
|
|
39,121 |
express-bem/express-bem
|
lib/engines.js
|
function (name, options, cb) {
var engine = enginesByExtension[this.ext],
that = this,
// queue
stack = [],
ctx = {
name : name,
options : options,
cb : cb
};
this.engines = engines;
this.thru = function (name, _name, _options, _cb) {
var engine = engines[name];
if (!engine) {
return cb(Error('Unknown engine ' + name));
}
this.ext = engine.extension;
engine.call(this, _name || ctx.name, _options || ctx.options, _cb || ctx.cb);
};
options.forceLoad = options.hasOwnProperty('forceLoad') ? options.forceLoad : !expressBem.envLoadCache;
options.forceExec = options.hasOwnProperty('forceExec') ? options.forceExec : !expressBem.envExecCache;
if (!middlewares.length) {
return engine.call(this, ctx.name, ctx.options, ctx.cb);
}
// async fn queue
middlewares.forEach(function (mw) {
if (!mw.engine /* || shouldUseMiddlewareFor(mw.engine)*/) {
stack.push(mw.fn);
}
});
// put engine as last call
stack.push(function (ctx) {
engine.call(this, ctx.name, ctx.options, ctx.cb);
});
function next () {
var fn = stack.shift();
fn.call(that, ctx, next);
}
process.nextTick(next);
return this;
}
|
javascript
|
function (name, options, cb) {
var engine = enginesByExtension[this.ext],
that = this,
// queue
stack = [],
ctx = {
name : name,
options : options,
cb : cb
};
this.engines = engines;
this.thru = function (name, _name, _options, _cb) {
var engine = engines[name];
if (!engine) {
return cb(Error('Unknown engine ' + name));
}
this.ext = engine.extension;
engine.call(this, _name || ctx.name, _options || ctx.options, _cb || ctx.cb);
};
options.forceLoad = options.hasOwnProperty('forceLoad') ? options.forceLoad : !expressBem.envLoadCache;
options.forceExec = options.hasOwnProperty('forceExec') ? options.forceExec : !expressBem.envExecCache;
if (!middlewares.length) {
return engine.call(this, ctx.name, ctx.options, ctx.cb);
}
// async fn queue
middlewares.forEach(function (mw) {
if (!mw.engine /* || shouldUseMiddlewareFor(mw.engine)*/) {
stack.push(mw.fn);
}
});
// put engine as last call
stack.push(function (ctx) {
engine.call(this, ctx.name, ctx.options, ctx.cb);
});
function next () {
var fn = stack.shift();
fn.call(that, ctx, next);
}
process.nextTick(next);
return this;
}
|
[
"function",
"(",
"name",
",",
"options",
",",
"cb",
")",
"{",
"var",
"engine",
"=",
"enginesByExtension",
"[",
"this",
".",
"ext",
"]",
",",
"that",
"=",
"this",
",",
"// queue",
"stack",
"=",
"[",
"]",
",",
"ctx",
"=",
"{",
"name",
":",
"name",
",",
"options",
":",
"options",
",",
"cb",
":",
"cb",
"}",
";",
"this",
".",
"engines",
"=",
"engines",
";",
"this",
".",
"thru",
"=",
"function",
"(",
"name",
",",
"_name",
",",
"_options",
",",
"_cb",
")",
"{",
"var",
"engine",
"=",
"engines",
"[",
"name",
"]",
";",
"if",
"(",
"!",
"engine",
")",
"{",
"return",
"cb",
"(",
"Error",
"(",
"'Unknown engine '",
"+",
"name",
")",
")",
";",
"}",
"this",
".",
"ext",
"=",
"engine",
".",
"extension",
";",
"engine",
".",
"call",
"(",
"this",
",",
"_name",
"||",
"ctx",
".",
"name",
",",
"_options",
"||",
"ctx",
".",
"options",
",",
"_cb",
"||",
"ctx",
".",
"cb",
")",
";",
"}",
";",
"options",
".",
"forceLoad",
"=",
"options",
".",
"hasOwnProperty",
"(",
"'forceLoad'",
")",
"?",
"options",
".",
"forceLoad",
":",
"!",
"expressBem",
".",
"envLoadCache",
";",
"options",
".",
"forceExec",
"=",
"options",
".",
"hasOwnProperty",
"(",
"'forceExec'",
")",
"?",
"options",
".",
"forceExec",
":",
"!",
"expressBem",
".",
"envExecCache",
";",
"if",
"(",
"!",
"middlewares",
".",
"length",
")",
"{",
"return",
"engine",
".",
"call",
"(",
"this",
",",
"ctx",
".",
"name",
",",
"ctx",
".",
"options",
",",
"ctx",
".",
"cb",
")",
";",
"}",
"// async fn queue",
"middlewares",
".",
"forEach",
"(",
"function",
"(",
"mw",
")",
"{",
"if",
"(",
"!",
"mw",
".",
"engine",
"/* || shouldUseMiddlewareFor(mw.engine)*/",
")",
"{",
"stack",
".",
"push",
"(",
"mw",
".",
"fn",
")",
";",
"}",
"}",
")",
";",
"// put engine as last call",
"stack",
".",
"push",
"(",
"function",
"(",
"ctx",
")",
"{",
"engine",
".",
"call",
"(",
"this",
",",
"ctx",
".",
"name",
",",
"ctx",
".",
"options",
",",
"ctx",
".",
"cb",
")",
";",
"}",
")",
";",
"function",
"next",
"(",
")",
"{",
"var",
"fn",
"=",
"stack",
".",
"shift",
"(",
")",
";",
"fn",
".",
"call",
"(",
"that",
",",
"ctx",
",",
"next",
")",
";",
"}",
"process",
".",
"nextTick",
"(",
"next",
")",
";",
"return",
"this",
";",
"}"
] |
all engines will pass through it
|
[
"all",
"engines",
"will",
"pass",
"through",
"it"
] |
6ea49e5ecdd8e949dd5051ecc5762e40cbcead9c
|
https://github.com/express-bem/express-bem/blob/6ea49e5ecdd8e949dd5051ecc5762e40cbcead9c/lib/engines.js#L75-L123
|
|
39,122 |
chrisJohn404/ljswitchboard-ljm_device_curator
|
lib/dashboard/dashboard_operations.js
|
addListener
|
function addListener(uid) {
var addedListener = false;
if(typeof(dashboardListeners[uid]) === 'undefined') {
dashboardListeners[uid] = {
'startTime': new Date(),
'numIterations': 0,
'uid': uid,
'numStarts': 1,
};
addedListener = true;
} else {
// Don't add the listener.
dashboardListeners[uid].numStarts += 1;
}
return addedListener;
}
|
javascript
|
function addListener(uid) {
var addedListener = false;
if(typeof(dashboardListeners[uid]) === 'undefined') {
dashboardListeners[uid] = {
'startTime': new Date(),
'numIterations': 0,
'uid': uid,
'numStarts': 1,
};
addedListener = true;
} else {
// Don't add the listener.
dashboardListeners[uid].numStarts += 1;
}
return addedListener;
}
|
[
"function",
"addListener",
"(",
"uid",
")",
"{",
"var",
"addedListener",
"=",
"false",
";",
"if",
"(",
"typeof",
"(",
"dashboardListeners",
"[",
"uid",
"]",
")",
"===",
"'undefined'",
")",
"{",
"dashboardListeners",
"[",
"uid",
"]",
"=",
"{",
"'startTime'",
":",
"new",
"Date",
"(",
")",
",",
"'numIterations'",
":",
"0",
",",
"'uid'",
":",
"uid",
",",
"'numStarts'",
":",
"1",
",",
"}",
";",
"addedListener",
"=",
"true",
";",
"}",
"else",
"{",
"// Don't add the listener.",
"dashboardListeners",
"[",
"uid",
"]",
".",
"numStarts",
"+=",
"1",
";",
"}",
"return",
"addedListener",
";",
"}"
] |
Function that adds a data listener.
|
[
"Function",
"that",
"adds",
"a",
"data",
"listener",
"."
] |
36cb25645dfa0a68e906d5ec43e5514391947257
|
https://github.com/chrisJohn404/ljswitchboard-ljm_device_curator/blob/36cb25645dfa0a68e906d5ec43e5514391947257/lib/dashboard/dashboard_operations.js#L85-L100
|
39,123 |
chrisJohn404/ljswitchboard-ljm_device_curator
|
lib/dashboard/dashboard_operations.js
|
removeListener
|
function removeListener(uid) {
var removedListener = false;
if(typeof(dashboardListeners[uid]) !== 'undefined') {
dashboardListeners[uid] = undefined;
delete dashboardListeners[uid];
removedListener = true;
}
return removedListener;
}
|
javascript
|
function removeListener(uid) {
var removedListener = false;
if(typeof(dashboardListeners[uid]) !== 'undefined') {
dashboardListeners[uid] = undefined;
delete dashboardListeners[uid];
removedListener = true;
}
return removedListener;
}
|
[
"function",
"removeListener",
"(",
"uid",
")",
"{",
"var",
"removedListener",
"=",
"false",
";",
"if",
"(",
"typeof",
"(",
"dashboardListeners",
"[",
"uid",
"]",
")",
"!==",
"'undefined'",
")",
"{",
"dashboardListeners",
"[",
"uid",
"]",
"=",
"undefined",
";",
"delete",
"dashboardListeners",
"[",
"uid",
"]",
";",
"removedListener",
"=",
"true",
";",
"}",
"return",
"removedListener",
";",
"}"
] |
Function that removes a data listener.
|
[
"Function",
"that",
"removes",
"a",
"data",
"listener",
"."
] |
36cb25645dfa0a68e906d5ec43e5514391947257
|
https://github.com/chrisJohn404/ljswitchboard-ljm_device_curator/blob/36cb25645dfa0a68e906d5ec43e5514391947257/lib/dashboard/dashboard_operations.js#L103-L111
|
39,124 |
chrisJohn404/ljswitchboard-ljm_device_curator
|
lib/dashboard/dashboard_operations.js
|
dataCollectorHandler
|
function dataCollectorHandler(data) {
// debugDDC('New data', data['FIO0']);
var diffObj = _.diff(data, self.dataCache);
// console.log('Data Difference - diff', diffObj);
// Clean the object to get rid of empty results.
diffObj = _.pickBy(diffObj, function(value, key) {
return Object.keys(value).length > 0;
});
var numKeys = Object.keys(data);
var numNewKeys = Object.keys(diffObj);
// console.log('Num Keys for new data', numKeys, numNewKeys);
// console.log('Data Difference - pickBy', diffObj);
self.dataCache = data;
self.emit(device_events.DASHBOARD_DATA_UPDATE, diffObj);
}
|
javascript
|
function dataCollectorHandler(data) {
// debugDDC('New data', data['FIO0']);
var diffObj = _.diff(data, self.dataCache);
// console.log('Data Difference - diff', diffObj);
// Clean the object to get rid of empty results.
diffObj = _.pickBy(diffObj, function(value, key) {
return Object.keys(value).length > 0;
});
var numKeys = Object.keys(data);
var numNewKeys = Object.keys(diffObj);
// console.log('Num Keys for new data', numKeys, numNewKeys);
// console.log('Data Difference - pickBy', diffObj);
self.dataCache = data;
self.emit(device_events.DASHBOARD_DATA_UPDATE, diffObj);
}
|
[
"function",
"dataCollectorHandler",
"(",
"data",
")",
"{",
"// debugDDC('New data', data['FIO0']);",
"var",
"diffObj",
"=",
"_",
".",
"diff",
"(",
"data",
",",
"self",
".",
"dataCache",
")",
";",
"// console.log('Data Difference - diff', diffObj);",
"// Clean the object to get rid of empty results.",
"diffObj",
"=",
"_",
".",
"pickBy",
"(",
"diffObj",
",",
"function",
"(",
"value",
",",
"key",
")",
"{",
"return",
"Object",
".",
"keys",
"(",
"value",
")",
".",
"length",
">",
"0",
";",
"}",
")",
";",
"var",
"numKeys",
"=",
"Object",
".",
"keys",
"(",
"data",
")",
";",
"var",
"numNewKeys",
"=",
"Object",
".",
"keys",
"(",
"diffObj",
")",
";",
"// console.log('Num Keys for new data', numKeys, numNewKeys);",
"// console.log('Data Difference - pickBy', diffObj);",
"self",
".",
"dataCache",
"=",
"data",
";",
"self",
".",
"emit",
"(",
"device_events",
".",
"DASHBOARD_DATA_UPDATE",
",",
"diffObj",
")",
";",
"}"
] |
Function that handles the data collection "data" events. This data is the data returned by the read-commands that are performed. This data still needs to be interpreted saved, cached, and organized into "channels". Maybe?? The dashboard_data_collector has logic for each of the devices. This logic should probably be put there?
|
[
"Function",
"that",
"handles",
"the",
"data",
"collection",
"data",
"events",
".",
"This",
"data",
"is",
"the",
"data",
"returned",
"by",
"the",
"read",
"-",
"commands",
"that",
"are",
"performed",
".",
"This",
"data",
"still",
"needs",
"to",
"be",
"interpreted",
"saved",
"cached",
"and",
"organized",
"into",
"channels",
".",
"Maybe??",
"The",
"dashboard_data_collector",
"has",
"logic",
"for",
"each",
"of",
"the",
"devices",
".",
"This",
"logic",
"should",
"probably",
"be",
"put",
"there?"
] |
36cb25645dfa0a68e906d5ec43e5514391947257
|
https://github.com/chrisJohn404/ljswitchboard-ljm_device_curator/blob/36cb25645dfa0a68e906d5ec43e5514391947257/lib/dashboard/dashboard_operations.js#L143-L160
|
39,125 |
chrisJohn404/ljswitchboard-ljm_device_curator
|
lib/dashboard/dashboard_operations.js
|
innerStart
|
function innerStart (bundle) {
var defered = q.defer();
// Device Type is either T4, T5, or T7
var deviceType = self.savedAttributes.deviceTypeName;
// Save the created data collector object
dataCollector = new dashboard_data_collector.create(deviceType);
// Listen to only the next 'data' event emitted by the dataCollector.
dataCollector.once('data', function(data) {
debugDStart('dev_cur-dash_ops: First bit of data!');
// Listen to future data.
dataCollector.on('data', dataCollectorHandler);
// Save the data to the data cache.
self.dataCache = data;
bundle.data = data;
// Declare the innerStart function to be finished.
defered.resolve(bundle);
});
// Start the data collector.
dataCollector.start(self);
return defered.promise;
}
|
javascript
|
function innerStart (bundle) {
var defered = q.defer();
// Device Type is either T4, T5, or T7
var deviceType = self.savedAttributes.deviceTypeName;
// Save the created data collector object
dataCollector = new dashboard_data_collector.create(deviceType);
// Listen to only the next 'data' event emitted by the dataCollector.
dataCollector.once('data', function(data) {
debugDStart('dev_cur-dash_ops: First bit of data!');
// Listen to future data.
dataCollector.on('data', dataCollectorHandler);
// Save the data to the data cache.
self.dataCache = data;
bundle.data = data;
// Declare the innerStart function to be finished.
defered.resolve(bundle);
});
// Start the data collector.
dataCollector.start(self);
return defered.promise;
}
|
[
"function",
"innerStart",
"(",
"bundle",
")",
"{",
"var",
"defered",
"=",
"q",
".",
"defer",
"(",
")",
";",
"// Device Type is either T4, T5, or T7",
"var",
"deviceType",
"=",
"self",
".",
"savedAttributes",
".",
"deviceTypeName",
";",
"// Save the created data collector object",
"dataCollector",
"=",
"new",
"dashboard_data_collector",
".",
"create",
"(",
"deviceType",
")",
";",
"// Listen to only the next 'data' event emitted by the dataCollector.",
"dataCollector",
".",
"once",
"(",
"'data'",
",",
"function",
"(",
"data",
")",
"{",
"debugDStart",
"(",
"'dev_cur-dash_ops: First bit of data!'",
")",
";",
"// Listen to future data.",
"dataCollector",
".",
"on",
"(",
"'data'",
",",
"dataCollectorHandler",
")",
";",
"// Save the data to the data cache.",
"self",
".",
"dataCache",
"=",
"data",
";",
"bundle",
".",
"data",
"=",
"data",
";",
"// Declare the innerStart function to be finished.",
"defered",
".",
"resolve",
"(",
"bundle",
")",
";",
"}",
")",
";",
"// Start the data collector.",
"dataCollector",
".",
"start",
"(",
"self",
")",
";",
"return",
"defered",
".",
"promise",
";",
"}"
] |
This function starts the data collector and registers event listeners.
|
[
"This",
"function",
"starts",
"the",
"data",
"collector",
"and",
"registers",
"event",
"listeners",
"."
] |
36cb25645dfa0a68e906d5ec43e5514391947257
|
https://github.com/chrisJohn404/ljswitchboard-ljm_device_curator/blob/36cb25645dfa0a68e906d5ec43e5514391947257/lib/dashboard/dashboard_operations.js#L173-L201
|
39,126 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
function(k, i) {
var rval;
if(typeof(k) === 'undefined') {
rval = frag.query;
} else {
rval = frag.query[k];
if(rval && typeof(i) !== 'undefined') {
rval = rval[i];
}
}
return rval;
}
|
javascript
|
function(k, i) {
var rval;
if(typeof(k) === 'undefined') {
rval = frag.query;
} else {
rval = frag.query[k];
if(rval && typeof(i) !== 'undefined') {
rval = rval[i];
}
}
return rval;
}
|
[
"function",
"(",
"k",
",",
"i",
")",
"{",
"var",
"rval",
";",
"if",
"(",
"typeof",
"(",
"k",
")",
"===",
"'undefined'",
")",
"{",
"rval",
"=",
"frag",
".",
"query",
";",
"}",
"else",
"{",
"rval",
"=",
"frag",
".",
"query",
"[",
"k",
"]",
";",
"if",
"(",
"rval",
"&&",
"typeof",
"(",
"i",
")",
"!==",
"'undefined'",
")",
"{",
"rval",
"=",
"rval",
"[",
"i",
"]",
";",
"}",
"}",
"return",
"rval",
";",
"}"
] |
Get query, values for a key, or value for a key index.
@param k optional query key.
@param i optional query key index.
@return query, values for a key, or value for a key index.
|
[
"Get",
"query",
"values",
"for",
"a",
"key",
"or",
"value",
"for",
"a",
"key",
"index",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L2833-L2844
|
|
39,127 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
_expandKey
|
function _expandKey(key, decrypt) {
// copy the key's words to initialize the key schedule
var w = key.slice(0);
/* RotWord() will rotate a word, moving the first byte to the last
byte's position (shifting the other bytes left).
We will be getting the value of Rcon at i / Nk. 'i' will iterate
from Nk to (Nb * Nr+1). Nk = 4 (4 byte key), Nb = 4 (4 words in
a block), Nr = Nk + 6 (10). Therefore 'i' will iterate from
4 to 44 (exclusive). Each time we iterate 4 times, i / Nk will
increase by 1. We use a counter iNk to keep track of this.
*/
// go through the rounds expanding the key
var temp, iNk = 1;
var Nk = w.length;
var Nr1 = Nk + 6 + 1;
var end = Nb * Nr1;
for(var i = Nk; i < end; ++i) {
temp = w[i - 1];
if(i % Nk === 0) {
// temp = SubWord(RotWord(temp)) ^ Rcon[i / Nk]
temp =
sbox[temp >>> 16 & 255] << 24 ^
sbox[temp >>> 8 & 255] << 16 ^
sbox[temp & 255] << 8 ^
sbox[temp >>> 24] ^ (rcon[iNk] << 24);
iNk++;
} else if(Nk > 6 && (i % Nk === 4)) {
// temp = SubWord(temp)
temp =
sbox[temp >>> 24] << 24 ^
sbox[temp >>> 16 & 255] << 16 ^
sbox[temp >>> 8 & 255] << 8 ^
sbox[temp & 255];
}
w[i] = w[i - Nk] ^ temp;
}
/* When we are updating a cipher block we always use the code path for
encryption whether we are decrypting or not (to shorten code and
simplify the generation of look up tables). However, because there
are differences in the decryption algorithm, other than just swapping
in different look up tables, we must transform our key schedule to
account for these changes:
1. The decryption algorithm gets its key rounds in reverse order.
2. The decryption algorithm adds the round key before mixing columns
instead of afterwards.
We don't need to modify our key schedule to handle the first case,
we can just traverse the key schedule in reverse order when decrypting.
The second case requires a little work.
The tables we built for performing rounds will take an input and then
perform SubBytes() and MixColumns() or, for the decrypt version,
InvSubBytes() and InvMixColumns(). But the decrypt algorithm requires
us to AddRoundKey() before InvMixColumns(). This means we'll need to
apply some transformations to the round key to inverse-mix its columns
so they'll be correct for moving AddRoundKey() to after the state has
had its columns inverse-mixed.
To inverse-mix the columns of the state when we're decrypting we use a
lookup table that will apply InvSubBytes() and InvMixColumns() at the
same time. However, the round key's bytes are not inverse-substituted
in the decryption algorithm. To get around this problem, we can first
substitute the bytes in the round key so that when we apply the
transformation via the InvSubBytes()+InvMixColumns() table, it will
undo our substitution leaving us with the original value that we
want -- and then inverse-mix that value.
This change will correctly alter our key schedule so that we can XOR
each round key with our already transformed decryption state. This
allows us to use the same code path as the encryption algorithm.
We make one more change to the decryption key. Since the decryption
algorithm runs in reverse from the encryption algorithm, we reverse
the order of the round keys to avoid having to iterate over the key
schedule backwards when running the encryption algorithm later in
decryption mode. In addition to reversing the order of the round keys,
we also swap each round key's 2nd and 4th rows. See the comments
section where rounds are performed for more details about why this is
done. These changes are done inline with the other substitution
described above.
*/
if(decrypt) {
var tmp;
var m0 = imix[0];
var m1 = imix[1];
var m2 = imix[2];
var m3 = imix[3];
var wnew = w.slice(0);
end = w.length;
for(var i = 0, wi = end - Nb; i < end; i += Nb, wi -= Nb) {
// do not sub the first or last round key (round keys are Nb
// words) as no column mixing is performed before they are added,
// but do change the key order
if(i === 0 || i === (end - Nb)) {
wnew[i] = w[wi];
wnew[i + 1] = w[wi + 3];
wnew[i + 2] = w[wi + 2];
wnew[i + 3] = w[wi + 1];
} else {
// substitute each round key byte because the inverse-mix
// table will inverse-substitute it (effectively cancel the
// substitution because round key bytes aren't sub'd in
// decryption mode) and swap indexes 3 and 1
for(var n = 0; n < Nb; ++n) {
tmp = w[wi + n];
wnew[i + (3&-n)] =
m0[sbox[tmp >>> 24]] ^
m1[sbox[tmp >>> 16 & 255]] ^
m2[sbox[tmp >>> 8 & 255]] ^
m3[sbox[tmp & 255]];
}
}
}
w = wnew;
}
return w;
}
|
javascript
|
function _expandKey(key, decrypt) {
// copy the key's words to initialize the key schedule
var w = key.slice(0);
/* RotWord() will rotate a word, moving the first byte to the last
byte's position (shifting the other bytes left).
We will be getting the value of Rcon at i / Nk. 'i' will iterate
from Nk to (Nb * Nr+1). Nk = 4 (4 byte key), Nb = 4 (4 words in
a block), Nr = Nk + 6 (10). Therefore 'i' will iterate from
4 to 44 (exclusive). Each time we iterate 4 times, i / Nk will
increase by 1. We use a counter iNk to keep track of this.
*/
// go through the rounds expanding the key
var temp, iNk = 1;
var Nk = w.length;
var Nr1 = Nk + 6 + 1;
var end = Nb * Nr1;
for(var i = Nk; i < end; ++i) {
temp = w[i - 1];
if(i % Nk === 0) {
// temp = SubWord(RotWord(temp)) ^ Rcon[i / Nk]
temp =
sbox[temp >>> 16 & 255] << 24 ^
sbox[temp >>> 8 & 255] << 16 ^
sbox[temp & 255] << 8 ^
sbox[temp >>> 24] ^ (rcon[iNk] << 24);
iNk++;
} else if(Nk > 6 && (i % Nk === 4)) {
// temp = SubWord(temp)
temp =
sbox[temp >>> 24] << 24 ^
sbox[temp >>> 16 & 255] << 16 ^
sbox[temp >>> 8 & 255] << 8 ^
sbox[temp & 255];
}
w[i] = w[i - Nk] ^ temp;
}
/* When we are updating a cipher block we always use the code path for
encryption whether we are decrypting or not (to shorten code and
simplify the generation of look up tables). However, because there
are differences in the decryption algorithm, other than just swapping
in different look up tables, we must transform our key schedule to
account for these changes:
1. The decryption algorithm gets its key rounds in reverse order.
2. The decryption algorithm adds the round key before mixing columns
instead of afterwards.
We don't need to modify our key schedule to handle the first case,
we can just traverse the key schedule in reverse order when decrypting.
The second case requires a little work.
The tables we built for performing rounds will take an input and then
perform SubBytes() and MixColumns() or, for the decrypt version,
InvSubBytes() and InvMixColumns(). But the decrypt algorithm requires
us to AddRoundKey() before InvMixColumns(). This means we'll need to
apply some transformations to the round key to inverse-mix its columns
so they'll be correct for moving AddRoundKey() to after the state has
had its columns inverse-mixed.
To inverse-mix the columns of the state when we're decrypting we use a
lookup table that will apply InvSubBytes() and InvMixColumns() at the
same time. However, the round key's bytes are not inverse-substituted
in the decryption algorithm. To get around this problem, we can first
substitute the bytes in the round key so that when we apply the
transformation via the InvSubBytes()+InvMixColumns() table, it will
undo our substitution leaving us with the original value that we
want -- and then inverse-mix that value.
This change will correctly alter our key schedule so that we can XOR
each round key with our already transformed decryption state. This
allows us to use the same code path as the encryption algorithm.
We make one more change to the decryption key. Since the decryption
algorithm runs in reverse from the encryption algorithm, we reverse
the order of the round keys to avoid having to iterate over the key
schedule backwards when running the encryption algorithm later in
decryption mode. In addition to reversing the order of the round keys,
we also swap each round key's 2nd and 4th rows. See the comments
section where rounds are performed for more details about why this is
done. These changes are done inline with the other substitution
described above.
*/
if(decrypt) {
var tmp;
var m0 = imix[0];
var m1 = imix[1];
var m2 = imix[2];
var m3 = imix[3];
var wnew = w.slice(0);
end = w.length;
for(var i = 0, wi = end - Nb; i < end; i += Nb, wi -= Nb) {
// do not sub the first or last round key (round keys are Nb
// words) as no column mixing is performed before they are added,
// but do change the key order
if(i === 0 || i === (end - Nb)) {
wnew[i] = w[wi];
wnew[i + 1] = w[wi + 3];
wnew[i + 2] = w[wi + 2];
wnew[i + 3] = w[wi + 1];
} else {
// substitute each round key byte because the inverse-mix
// table will inverse-substitute it (effectively cancel the
// substitution because round key bytes aren't sub'd in
// decryption mode) and swap indexes 3 and 1
for(var n = 0; n < Nb; ++n) {
tmp = w[wi + n];
wnew[i + (3&-n)] =
m0[sbox[tmp >>> 24]] ^
m1[sbox[tmp >>> 16 & 255]] ^
m2[sbox[tmp >>> 8 & 255]] ^
m3[sbox[tmp & 255]];
}
}
}
w = wnew;
}
return w;
}
|
[
"function",
"_expandKey",
"(",
"key",
",",
"decrypt",
")",
"{",
"// copy the key's words to initialize the key schedule\r",
"var",
"w",
"=",
"key",
".",
"slice",
"(",
"0",
")",
";",
"/* RotWord() will rotate a word, moving the first byte to the last\r\n byte's position (shifting the other bytes left).\r\n\r\n We will be getting the value of Rcon at i / Nk. 'i' will iterate\r\n from Nk to (Nb * Nr+1). Nk = 4 (4 byte key), Nb = 4 (4 words in\r\n a block), Nr = Nk + 6 (10). Therefore 'i' will iterate from\r\n 4 to 44 (exclusive). Each time we iterate 4 times, i / Nk will\r\n increase by 1. We use a counter iNk to keep track of this.\r\n */",
"// go through the rounds expanding the key\r",
"var",
"temp",
",",
"iNk",
"=",
"1",
";",
"var",
"Nk",
"=",
"w",
".",
"length",
";",
"var",
"Nr1",
"=",
"Nk",
"+",
"6",
"+",
"1",
";",
"var",
"end",
"=",
"Nb",
"*",
"Nr1",
";",
"for",
"(",
"var",
"i",
"=",
"Nk",
";",
"i",
"<",
"end",
";",
"++",
"i",
")",
"{",
"temp",
"=",
"w",
"[",
"i",
"-",
"1",
"]",
";",
"if",
"(",
"i",
"%",
"Nk",
"===",
"0",
")",
"{",
"// temp = SubWord(RotWord(temp)) ^ Rcon[i / Nk]\r",
"temp",
"=",
"sbox",
"[",
"temp",
">>>",
"16",
"&",
"255",
"]",
"<<",
"24",
"^",
"sbox",
"[",
"temp",
">>>",
"8",
"&",
"255",
"]",
"<<",
"16",
"^",
"sbox",
"[",
"temp",
"&",
"255",
"]",
"<<",
"8",
"^",
"sbox",
"[",
"temp",
">>>",
"24",
"]",
"^",
"(",
"rcon",
"[",
"iNk",
"]",
"<<",
"24",
")",
";",
"iNk",
"++",
";",
"}",
"else",
"if",
"(",
"Nk",
">",
"6",
"&&",
"(",
"i",
"%",
"Nk",
"===",
"4",
")",
")",
"{",
"// temp = SubWord(temp)\r",
"temp",
"=",
"sbox",
"[",
"temp",
">>>",
"24",
"]",
"<<",
"24",
"^",
"sbox",
"[",
"temp",
">>>",
"16",
"&",
"255",
"]",
"<<",
"16",
"^",
"sbox",
"[",
"temp",
">>>",
"8",
"&",
"255",
"]",
"<<",
"8",
"^",
"sbox",
"[",
"temp",
"&",
"255",
"]",
";",
"}",
"w",
"[",
"i",
"]",
"=",
"w",
"[",
"i",
"-",
"Nk",
"]",
"^",
"temp",
";",
"}",
"/* When we are updating a cipher block we always use the code path for\r\n encryption whether we are decrypting or not (to shorten code and\r\n simplify the generation of look up tables). However, because there\r\n are differences in the decryption algorithm, other than just swapping\r\n in different look up tables, we must transform our key schedule to\r\n account for these changes:\r\n\r\n 1. The decryption algorithm gets its key rounds in reverse order.\r\n 2. The decryption algorithm adds the round key before mixing columns\r\n instead of afterwards.\r\n\r\n We don't need to modify our key schedule to handle the first case,\r\n we can just traverse the key schedule in reverse order when decrypting.\r\n\r\n The second case requires a little work.\r\n\r\n The tables we built for performing rounds will take an input and then\r\n perform SubBytes() and MixColumns() or, for the decrypt version,\r\n InvSubBytes() and InvMixColumns(). But the decrypt algorithm requires\r\n us to AddRoundKey() before InvMixColumns(). This means we'll need to\r\n apply some transformations to the round key to inverse-mix its columns\r\n so they'll be correct for moving AddRoundKey() to after the state has\r\n had its columns inverse-mixed.\r\n\r\n To inverse-mix the columns of the state when we're decrypting we use a\r\n lookup table that will apply InvSubBytes() and InvMixColumns() at the\r\n same time. However, the round key's bytes are not inverse-substituted\r\n in the decryption algorithm. To get around this problem, we can first\r\n substitute the bytes in the round key so that when we apply the\r\n transformation via the InvSubBytes()+InvMixColumns() table, it will\r\n undo our substitution leaving us with the original value that we\r\n want -- and then inverse-mix that value.\r\n\r\n This change will correctly alter our key schedule so that we can XOR\r\n each round key with our already transformed decryption state. This\r\n allows us to use the same code path as the encryption algorithm.\r\n\r\n We make one more change to the decryption key. Since the decryption\r\n algorithm runs in reverse from the encryption algorithm, we reverse\r\n the order of the round keys to avoid having to iterate over the key\r\n schedule backwards when running the encryption algorithm later in\r\n decryption mode. In addition to reversing the order of the round keys,\r\n we also swap each round key's 2nd and 4th rows. See the comments\r\n section where rounds are performed for more details about why this is\r\n done. These changes are done inline with the other substitution\r\n described above.\r\n */",
"if",
"(",
"decrypt",
")",
"{",
"var",
"tmp",
";",
"var",
"m0",
"=",
"imix",
"[",
"0",
"]",
";",
"var",
"m1",
"=",
"imix",
"[",
"1",
"]",
";",
"var",
"m2",
"=",
"imix",
"[",
"2",
"]",
";",
"var",
"m3",
"=",
"imix",
"[",
"3",
"]",
";",
"var",
"wnew",
"=",
"w",
".",
"slice",
"(",
"0",
")",
";",
"end",
"=",
"w",
".",
"length",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"wi",
"=",
"end",
"-",
"Nb",
";",
"i",
"<",
"end",
";",
"i",
"+=",
"Nb",
",",
"wi",
"-=",
"Nb",
")",
"{",
"// do not sub the first or last round key (round keys are Nb\r",
"// words) as no column mixing is performed before they are added,\r",
"// but do change the key order\r",
"if",
"(",
"i",
"===",
"0",
"||",
"i",
"===",
"(",
"end",
"-",
"Nb",
")",
")",
"{",
"wnew",
"[",
"i",
"]",
"=",
"w",
"[",
"wi",
"]",
";",
"wnew",
"[",
"i",
"+",
"1",
"]",
"=",
"w",
"[",
"wi",
"+",
"3",
"]",
";",
"wnew",
"[",
"i",
"+",
"2",
"]",
"=",
"w",
"[",
"wi",
"+",
"2",
"]",
";",
"wnew",
"[",
"i",
"+",
"3",
"]",
"=",
"w",
"[",
"wi",
"+",
"1",
"]",
";",
"}",
"else",
"{",
"// substitute each round key byte because the inverse-mix\r",
"// table will inverse-substitute it (effectively cancel the\r",
"// substitution because round key bytes aren't sub'd in\r",
"// decryption mode) and swap indexes 3 and 1\r",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"Nb",
";",
"++",
"n",
")",
"{",
"tmp",
"=",
"w",
"[",
"wi",
"+",
"n",
"]",
";",
"wnew",
"[",
"i",
"+",
"(",
"3",
"&",
"-",
"n",
")",
"]",
"=",
"m0",
"[",
"sbox",
"[",
"tmp",
">>>",
"24",
"]",
"]",
"^",
"m1",
"[",
"sbox",
"[",
"tmp",
">>>",
"16",
"&",
"255",
"]",
"]",
"^",
"m2",
"[",
"sbox",
"[",
"tmp",
">>>",
"8",
"&",
"255",
"]",
"]",
"^",
"m3",
"[",
"sbox",
"[",
"tmp",
"&",
"255",
"]",
"]",
";",
"}",
"}",
"}",
"w",
"=",
"wnew",
";",
"}",
"return",
"w",
";",
"}"
] |
Generates a key schedule using the AES key expansion algorithm.
The AES algorithm takes the Cipher Key, K, and performs a Key Expansion
routine to generate a key schedule. The Key Expansion generates a total
of Nb*(Nr + 1) words: the algorithm requires an initial set of Nb words,
and each of the Nr rounds requires Nb words of key data. The resulting
key schedule consists of a linear array of 4-byte words, denoted [wi ],
with i in the range 0 ≤ i < Nb(Nr + 1).
KeyExpansion(byte key[4*Nk], word w[Nb*(Nr+1)], Nk)
AES-128 (Nb=4, Nk=4, Nr=10)
AES-192 (Nb=4, Nk=6, Nr=12)
AES-256 (Nb=4, Nk=8, Nr=14)
Note: Nr=Nk+6.
Nb is the number of columns (32-bit words) comprising the State (or
number of bytes in a block). For AES, Nb=4.
@param key the key to schedule (as an array of 32-bit words).
@param decrypt true to modify the key schedule to decrypt, false not to.
@return the generated key schedule.
|
[
"Generates",
"a",
"key",
"schedule",
"using",
"the",
"AES",
"key",
"expansion",
"algorithm",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L5425-L5548
|
39,128 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
_update
|
function _update(s, w, bytes) {
// consume 512 bit (64 byte) chunks
var t, a, b, c, d, f, r, i;
var len = bytes.length();
while(len >= 64) {
// initialize hash value for this chunk
a = s.h0;
b = s.h1;
c = s.h2;
d = s.h3;
// round 1
for(i = 0; i < 16; ++i) {
w[i] = bytes.getInt32Le();
f = d ^ (b & (c ^ d));
t = (a + f + _k[i] + w[i]);
r = _r[i];
a = d;
d = c;
c = b;
b += (t << r) | (t >>> (32 - r));
}
// round 2
for(; i < 32; ++i) {
f = c ^ (d & (b ^ c));
t = (a + f + _k[i] + w[_g[i]]);
r = _r[i];
a = d;
d = c;
c = b;
b += (t << r) | (t >>> (32 - r));
}
// round 3
for(; i < 48; ++i) {
f = b ^ c ^ d;
t = (a + f + _k[i] + w[_g[i]]);
r = _r[i];
a = d;
d = c;
c = b;
b += (t << r) | (t >>> (32 - r));
}
// round 4
for(; i < 64; ++i) {
f = c ^ (b | ~d);
t = (a + f + _k[i] + w[_g[i]]);
r = _r[i];
a = d;
d = c;
c = b;
b += (t << r) | (t >>> (32 - r));
}
// update hash state
s.h0 = (s.h0 + a) | 0;
s.h1 = (s.h1 + b) | 0;
s.h2 = (s.h2 + c) | 0;
s.h3 = (s.h3 + d) | 0;
len -= 64;
}
}
|
javascript
|
function _update(s, w, bytes) {
// consume 512 bit (64 byte) chunks
var t, a, b, c, d, f, r, i;
var len = bytes.length();
while(len >= 64) {
// initialize hash value for this chunk
a = s.h0;
b = s.h1;
c = s.h2;
d = s.h3;
// round 1
for(i = 0; i < 16; ++i) {
w[i] = bytes.getInt32Le();
f = d ^ (b & (c ^ d));
t = (a + f + _k[i] + w[i]);
r = _r[i];
a = d;
d = c;
c = b;
b += (t << r) | (t >>> (32 - r));
}
// round 2
for(; i < 32; ++i) {
f = c ^ (d & (b ^ c));
t = (a + f + _k[i] + w[_g[i]]);
r = _r[i];
a = d;
d = c;
c = b;
b += (t << r) | (t >>> (32 - r));
}
// round 3
for(; i < 48; ++i) {
f = b ^ c ^ d;
t = (a + f + _k[i] + w[_g[i]]);
r = _r[i];
a = d;
d = c;
c = b;
b += (t << r) | (t >>> (32 - r));
}
// round 4
for(; i < 64; ++i) {
f = c ^ (b | ~d);
t = (a + f + _k[i] + w[_g[i]]);
r = _r[i];
a = d;
d = c;
c = b;
b += (t << r) | (t >>> (32 - r));
}
// update hash state
s.h0 = (s.h0 + a) | 0;
s.h1 = (s.h1 + b) | 0;
s.h2 = (s.h2 + c) | 0;
s.h3 = (s.h3 + d) | 0;
len -= 64;
}
}
|
[
"function",
"_update",
"(",
"s",
",",
"w",
",",
"bytes",
")",
"{",
"// consume 512 bit (64 byte) chunks\r",
"var",
"t",
",",
"a",
",",
"b",
",",
"c",
",",
"d",
",",
"f",
",",
"r",
",",
"i",
";",
"var",
"len",
"=",
"bytes",
".",
"length",
"(",
")",
";",
"while",
"(",
"len",
">=",
"64",
")",
"{",
"// initialize hash value for this chunk\r",
"a",
"=",
"s",
".",
"h0",
";",
"b",
"=",
"s",
".",
"h1",
";",
"c",
"=",
"s",
".",
"h2",
";",
"d",
"=",
"s",
".",
"h3",
";",
"// round 1\r",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"16",
";",
"++",
"i",
")",
"{",
"w",
"[",
"i",
"]",
"=",
"bytes",
".",
"getInt32Le",
"(",
")",
";",
"f",
"=",
"d",
"^",
"(",
"b",
"&",
"(",
"c",
"^",
"d",
")",
")",
";",
"t",
"=",
"(",
"a",
"+",
"f",
"+",
"_k",
"[",
"i",
"]",
"+",
"w",
"[",
"i",
"]",
")",
";",
"r",
"=",
"_r",
"[",
"i",
"]",
";",
"a",
"=",
"d",
";",
"d",
"=",
"c",
";",
"c",
"=",
"b",
";",
"b",
"+=",
"(",
"t",
"<<",
"r",
")",
"|",
"(",
"t",
">>>",
"(",
"32",
"-",
"r",
")",
")",
";",
"}",
"// round 2\r",
"for",
"(",
";",
"i",
"<",
"32",
";",
"++",
"i",
")",
"{",
"f",
"=",
"c",
"^",
"(",
"d",
"&",
"(",
"b",
"^",
"c",
")",
")",
";",
"t",
"=",
"(",
"a",
"+",
"f",
"+",
"_k",
"[",
"i",
"]",
"+",
"w",
"[",
"_g",
"[",
"i",
"]",
"]",
")",
";",
"r",
"=",
"_r",
"[",
"i",
"]",
";",
"a",
"=",
"d",
";",
"d",
"=",
"c",
";",
"c",
"=",
"b",
";",
"b",
"+=",
"(",
"t",
"<<",
"r",
")",
"|",
"(",
"t",
">>>",
"(",
"32",
"-",
"r",
")",
")",
";",
"}",
"// round 3\r",
"for",
"(",
";",
"i",
"<",
"48",
";",
"++",
"i",
")",
"{",
"f",
"=",
"b",
"^",
"c",
"^",
"d",
";",
"t",
"=",
"(",
"a",
"+",
"f",
"+",
"_k",
"[",
"i",
"]",
"+",
"w",
"[",
"_g",
"[",
"i",
"]",
"]",
")",
";",
"r",
"=",
"_r",
"[",
"i",
"]",
";",
"a",
"=",
"d",
";",
"d",
"=",
"c",
";",
"c",
"=",
"b",
";",
"b",
"+=",
"(",
"t",
"<<",
"r",
")",
"|",
"(",
"t",
">>>",
"(",
"32",
"-",
"r",
")",
")",
";",
"}",
"// round 4\r",
"for",
"(",
";",
"i",
"<",
"64",
";",
"++",
"i",
")",
"{",
"f",
"=",
"c",
"^",
"(",
"b",
"|",
"~",
"d",
")",
";",
"t",
"=",
"(",
"a",
"+",
"f",
"+",
"_k",
"[",
"i",
"]",
"+",
"w",
"[",
"_g",
"[",
"i",
"]",
"]",
")",
";",
"r",
"=",
"_r",
"[",
"i",
"]",
";",
"a",
"=",
"d",
";",
"d",
"=",
"c",
";",
"c",
"=",
"b",
";",
"b",
"+=",
"(",
"t",
"<<",
"r",
")",
"|",
"(",
"t",
">>>",
"(",
"32",
"-",
"r",
")",
")",
";",
"}",
"// update hash state\r",
"s",
".",
"h0",
"=",
"(",
"s",
".",
"h0",
"+",
"a",
")",
"|",
"0",
";",
"s",
".",
"h1",
"=",
"(",
"s",
".",
"h1",
"+",
"b",
")",
"|",
"0",
";",
"s",
".",
"h2",
"=",
"(",
"s",
".",
"h2",
"+",
"c",
")",
"|",
"0",
";",
"s",
".",
"h3",
"=",
"(",
"s",
".",
"h3",
"+",
"d",
")",
"|",
"0",
";",
"len",
"-=",
"64",
";",
"}",
"}"
] |
Updates an MD5 state with the given byte buffer.
@param s the MD5 state to update.
@param w the array to use to store words.
@param bytes the byte buffer to update with.
|
[
"Updates",
"an",
"MD5",
"state",
"with",
"the",
"given",
"byte",
"buffer",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L7563-L7624
|
39,129 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
_reseed
|
function _reseed(callback) {
if(ctx.pools[0].messageLength >= 32) {
_seed();
return callback();
}
// not enough seed data...
var needed = (32 - ctx.pools[0].messageLength) << 5;
ctx.seedFile(needed, function(err, bytes) {
if(err) {
return callback(err);
}
ctx.collect(bytes);
_seed();
callback();
});
}
|
javascript
|
function _reseed(callback) {
if(ctx.pools[0].messageLength >= 32) {
_seed();
return callback();
}
// not enough seed data...
var needed = (32 - ctx.pools[0].messageLength) << 5;
ctx.seedFile(needed, function(err, bytes) {
if(err) {
return callback(err);
}
ctx.collect(bytes);
_seed();
callback();
});
}
|
[
"function",
"_reseed",
"(",
"callback",
")",
"{",
"if",
"(",
"ctx",
".",
"pools",
"[",
"0",
"]",
".",
"messageLength",
">=",
"32",
")",
"{",
"_seed",
"(",
")",
";",
"return",
"callback",
"(",
")",
";",
"}",
"// not enough seed data...\r",
"var",
"needed",
"=",
"(",
"32",
"-",
"ctx",
".",
"pools",
"[",
"0",
"]",
".",
"messageLength",
")",
"<<",
"5",
";",
"ctx",
".",
"seedFile",
"(",
"needed",
",",
"function",
"(",
"err",
",",
"bytes",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"ctx",
".",
"collect",
"(",
"bytes",
")",
";",
"_seed",
"(",
")",
";",
"callback",
"(",
")",
";",
"}",
")",
";",
"}"
] |
Private function that asynchronously reseeds a generator.
@param callback(err) called once the operation completes.
|
[
"Private",
"function",
"that",
"asynchronously",
"reseeds",
"a",
"generator",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L10590-L10605
|
39,130 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
function(e) {
var data = e.data;
if(data.forge && data.forge.prng) {
ctx.seedFile(data.forge.prng.needed, function(err, bytes) {
worker.postMessage({forge: {prng: {err: err, bytes: bytes}}});
});
}
}
|
javascript
|
function(e) {
var data = e.data;
if(data.forge && data.forge.prng) {
ctx.seedFile(data.forge.prng.needed, function(err, bytes) {
worker.postMessage({forge: {prng: {err: err, bytes: bytes}}});
});
}
}
|
[
"function",
"(",
"e",
")",
"{",
"var",
"data",
"=",
"e",
".",
"data",
";",
"if",
"(",
"data",
".",
"forge",
"&&",
"data",
".",
"forge",
".",
"prng",
")",
"{",
"ctx",
".",
"seedFile",
"(",
"data",
".",
"forge",
".",
"prng",
".",
"needed",
",",
"function",
"(",
"err",
",",
"bytes",
")",
"{",
"worker",
".",
"postMessage",
"(",
"{",
"forge",
":",
"{",
"prng",
":",
"{",
"err",
":",
"err",
",",
"bytes",
":",
"bytes",
"}",
"}",
"}",
")",
";",
"}",
")",
";",
"}",
"}"
] |
main thread sends random bytes upon request
|
[
"main",
"thread",
"sends",
"random",
"bytes",
"upon",
"request"
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L10803-L10810
|
|
39,131 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
function(iv, output) {
if(iv) {
/* CBC mode */
if(typeof iv === 'string') {
iv = forge.util.createBuffer(iv);
}
}
_finish = false;
_input = forge.util.createBuffer();
_output = output || new forge.util.createBuffer();
_iv = iv;
cipher.output = _output;
}
|
javascript
|
function(iv, output) {
if(iv) {
/* CBC mode */
if(typeof iv === 'string') {
iv = forge.util.createBuffer(iv);
}
}
_finish = false;
_input = forge.util.createBuffer();
_output = output || new forge.util.createBuffer();
_iv = iv;
cipher.output = _output;
}
|
[
"function",
"(",
"iv",
",",
"output",
")",
"{",
"if",
"(",
"iv",
")",
"{",
"/* CBC mode */",
"if",
"(",
"typeof",
"iv",
"===",
"'string'",
")",
"{",
"iv",
"=",
"forge",
".",
"util",
".",
"createBuffer",
"(",
"iv",
")",
";",
"}",
"}",
"_finish",
"=",
"false",
";",
"_input",
"=",
"forge",
".",
"util",
".",
"createBuffer",
"(",
")",
";",
"_output",
"=",
"output",
"||",
"new",
"forge",
".",
"util",
".",
"createBuffer",
"(",
")",
";",
"_iv",
"=",
"iv",
";",
"cipher",
".",
"output",
"=",
"_output",
";",
"}"
] |
Starts or restarts the encryption or decryption process, whichever
was previously configured.
To use the cipher in CBC mode, iv may be given either as a string
of bytes, or as a byte buffer. For ECB mode, give null as iv.
@param iv the initialization vector to use, null for ECB mode.
@param output the output the buffer to write to, null to create one.
|
[
"Starts",
"or",
"restarts",
"the",
"encryption",
"or",
"decryption",
"process",
"whichever",
"was",
"previously",
"configured",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L11360-L11374
|
|
39,132 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
generateRandom
|
function generateRandom(bits, rng) {
var num = new BigInteger(bits, rng);
// force MSB set
var bits1 = bits - 1;
if(!num.testBit(bits1)) {
num.bitwiseTo(BigInteger.ONE.shiftLeft(bits1), op_or, num);
}
// align number on 30k+1 boundary
num.dAddOffset(31 - num.mod(THIRTY).byteValue(), 0);
return num;
}
|
javascript
|
function generateRandom(bits, rng) {
var num = new BigInteger(bits, rng);
// force MSB set
var bits1 = bits - 1;
if(!num.testBit(bits1)) {
num.bitwiseTo(BigInteger.ONE.shiftLeft(bits1), op_or, num);
}
// align number on 30k+1 boundary
num.dAddOffset(31 - num.mod(THIRTY).byteValue(), 0);
return num;
}
|
[
"function",
"generateRandom",
"(",
"bits",
",",
"rng",
")",
"{",
"var",
"num",
"=",
"new",
"BigInteger",
"(",
"bits",
",",
"rng",
")",
";",
"// force MSB set\r",
"var",
"bits1",
"=",
"bits",
"-",
"1",
";",
"if",
"(",
"!",
"num",
".",
"testBit",
"(",
"bits1",
")",
")",
"{",
"num",
".",
"bitwiseTo",
"(",
"BigInteger",
".",
"ONE",
".",
"shiftLeft",
"(",
"bits1",
")",
",",
"op_or",
",",
"num",
")",
";",
"}",
"// align number on 30k+1 boundary\r",
"num",
".",
"dAddOffset",
"(",
"31",
"-",
"num",
".",
"mod",
"(",
"THIRTY",
")",
".",
"byteValue",
"(",
")",
",",
"0",
")",
";",
"return",
"num",
";",
"}"
] |
Generates a random number using the given number of bits and RNG.
@param bits the number of bits for the number.
@param rng the random number generator to use.
@return the random number.
|
[
"Generates",
"a",
"random",
"number",
"using",
"the",
"given",
"number",
"of",
"bits",
"and",
"RNG",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L13481-L13491
|
39,133 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
function(md) {
// get the oid for the algorithm
var oid;
if(md.algorithm in pki.oids) {
oid = pki.oids[md.algorithm];
} else {
var error = new Error('Unknown message digest algorithm.');
error.algorithm = md.algorithm;
throw error;
}
var oidBytes = asn1.oidToDer(oid).getBytes();
// create the digest info
var digestInfo = asn1.create(
asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, []);
var digestAlgorithm = asn1.create(
asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, []);
digestAlgorithm.value.push(asn1.create(
asn1.Class.UNIVERSAL, asn1.Type.OID, false, oidBytes));
digestAlgorithm.value.push(asn1.create(
asn1.Class.UNIVERSAL, asn1.Type.NULL, false, ''));
var digest = asn1.create(
asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING,
false, md.digest().getBytes());
digestInfo.value.push(digestAlgorithm);
digestInfo.value.push(digest);
// encode digest info
return asn1.toDer(digestInfo).getBytes();
}
|
javascript
|
function(md) {
// get the oid for the algorithm
var oid;
if(md.algorithm in pki.oids) {
oid = pki.oids[md.algorithm];
} else {
var error = new Error('Unknown message digest algorithm.');
error.algorithm = md.algorithm;
throw error;
}
var oidBytes = asn1.oidToDer(oid).getBytes();
// create the digest info
var digestInfo = asn1.create(
asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, []);
var digestAlgorithm = asn1.create(
asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, []);
digestAlgorithm.value.push(asn1.create(
asn1.Class.UNIVERSAL, asn1.Type.OID, false, oidBytes));
digestAlgorithm.value.push(asn1.create(
asn1.Class.UNIVERSAL, asn1.Type.NULL, false, ''));
var digest = asn1.create(
asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING,
false, md.digest().getBytes());
digestInfo.value.push(digestAlgorithm);
digestInfo.value.push(digest);
// encode digest info
return asn1.toDer(digestInfo).getBytes();
}
|
[
"function",
"(",
"md",
")",
"{",
"// get the oid for the algorithm\r",
"var",
"oid",
";",
"if",
"(",
"md",
".",
"algorithm",
"in",
"pki",
".",
"oids",
")",
"{",
"oid",
"=",
"pki",
".",
"oids",
"[",
"md",
".",
"algorithm",
"]",
";",
"}",
"else",
"{",
"var",
"error",
"=",
"new",
"Error",
"(",
"'Unknown message digest algorithm.'",
")",
";",
"error",
".",
"algorithm",
"=",
"md",
".",
"algorithm",
";",
"throw",
"error",
";",
"}",
"var",
"oidBytes",
"=",
"asn1",
".",
"oidToDer",
"(",
"oid",
")",
".",
"getBytes",
"(",
")",
";",
"// create the digest info\r",
"var",
"digestInfo",
"=",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"SEQUENCE",
",",
"true",
",",
"[",
"]",
")",
";",
"var",
"digestAlgorithm",
"=",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"SEQUENCE",
",",
"true",
",",
"[",
"]",
")",
";",
"digestAlgorithm",
".",
"value",
".",
"push",
"(",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"OID",
",",
"false",
",",
"oidBytes",
")",
")",
";",
"digestAlgorithm",
".",
"value",
".",
"push",
"(",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"NULL",
",",
"false",
",",
"''",
")",
")",
";",
"var",
"digest",
"=",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"OCTETSTRING",
",",
"false",
",",
"md",
".",
"digest",
"(",
")",
".",
"getBytes",
"(",
")",
")",
";",
"digestInfo",
".",
"value",
".",
"push",
"(",
"digestAlgorithm",
")",
";",
"digestInfo",
".",
"value",
".",
"push",
"(",
"digest",
")",
";",
"// encode digest info\r",
"return",
"asn1",
".",
"toDer",
"(",
"digestInfo",
")",
".",
"getBytes",
"(",
")",
";",
"}"
] |
Wrap digest in DigestInfo object.
This function implements EMSA-PKCS1-v1_5-ENCODE as per RFC 3447.
DigestInfo ::= SEQUENCE {
digestAlgorithm DigestAlgorithmIdentifier,
digest Digest
}
DigestAlgorithmIdentifier ::= AlgorithmIdentifier
Digest ::= OCTET STRING
@param md the message digest object with the hash to sign.
@return the encoded message (ready for RSA encrytion)
|
[
"Wrap",
"digest",
"in",
"DigestInfo",
"object",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L13846-L13875
|
|
39,134 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
_getAttribute
|
function _getAttribute(obj, options) {
if(typeof options === 'string') {
options = {shortName: options};
}
var rval = null;
var attr;
for(var i = 0; rval === null && i < obj.attributes.length; ++i) {
attr = obj.attributes[i];
if(options.type && options.type === attr.type) {
rval = attr;
} else if(options.name && options.name === attr.name) {
rval = attr;
} else if(options.shortName && options.shortName === attr.shortName) {
rval = attr;
}
}
return rval;
}
|
javascript
|
function _getAttribute(obj, options) {
if(typeof options === 'string') {
options = {shortName: options};
}
var rval = null;
var attr;
for(var i = 0; rval === null && i < obj.attributes.length; ++i) {
attr = obj.attributes[i];
if(options.type && options.type === attr.type) {
rval = attr;
} else if(options.name && options.name === attr.name) {
rval = attr;
} else if(options.shortName && options.shortName === attr.shortName) {
rval = attr;
}
}
return rval;
}
|
[
"function",
"_getAttribute",
"(",
"obj",
",",
"options",
")",
"{",
"if",
"(",
"typeof",
"options",
"===",
"'string'",
")",
"{",
"options",
"=",
"{",
"shortName",
":",
"options",
"}",
";",
"}",
"var",
"rval",
"=",
"null",
";",
"var",
"attr",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"rval",
"===",
"null",
"&&",
"i",
"<",
"obj",
".",
"attributes",
".",
"length",
";",
"++",
"i",
")",
"{",
"attr",
"=",
"obj",
".",
"attributes",
"[",
"i",
"]",
";",
"if",
"(",
"options",
".",
"type",
"&&",
"options",
".",
"type",
"===",
"attr",
".",
"type",
")",
"{",
"rval",
"=",
"attr",
";",
"}",
"else",
"if",
"(",
"options",
".",
"name",
"&&",
"options",
".",
"name",
"===",
"attr",
".",
"name",
")",
"{",
"rval",
"=",
"attr",
";",
"}",
"else",
"if",
"(",
"options",
".",
"shortName",
"&&",
"options",
".",
"shortName",
"===",
"attr",
".",
"shortName",
")",
"{",
"rval",
"=",
"attr",
";",
"}",
"}",
"return",
"rval",
";",
"}"
] |
Gets an issuer or subject attribute from its name, type, or short name.
@param obj the issuer or subject object.
@param options a short name string or an object with:
shortName the short name for the attribute.
name the name for the attribute.
type the type for the attribute.
@return the attribute.
|
[
"Gets",
"an",
"issuer",
"or",
"subject",
"attribute",
"from",
"its",
"name",
"type",
"or",
"short",
"name",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L17787-L17805
|
39,135 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
function(oid, obj, fillDefaults) {
var params = {};
if(oid !== oids['RSASSA-PSS']) {
return params;
}
if(fillDefaults) {
params = {
hash: {
algorithmOid: oids['sha1']
},
mgf: {
algorithmOid: oids['mgf1'],
hash: {
algorithmOid: oids['sha1']
}
},
saltLength: 20
};
}
var capture = {};
var errors = [];
if(!asn1.validate(obj, rsassaPssParameterValidator, capture, errors)) {
var error = new Error('Cannot read RSASSA-PSS parameter block.');
error.errors = errors;
throw error;
}
if(capture.hashOid !== undefined) {
params.hash = params.hash || {};
params.hash.algorithmOid = asn1.derToOid(capture.hashOid);
}
if(capture.maskGenOid !== undefined) {
params.mgf = params.mgf || {};
params.mgf.algorithmOid = asn1.derToOid(capture.maskGenOid);
params.mgf.hash = params.mgf.hash || {};
params.mgf.hash.algorithmOid = asn1.derToOid(capture.maskGenHashOid);
}
if(capture.saltLength !== undefined) {
params.saltLength = capture.saltLength.charCodeAt(0);
}
return params;
}
|
javascript
|
function(oid, obj, fillDefaults) {
var params = {};
if(oid !== oids['RSASSA-PSS']) {
return params;
}
if(fillDefaults) {
params = {
hash: {
algorithmOid: oids['sha1']
},
mgf: {
algorithmOid: oids['mgf1'],
hash: {
algorithmOid: oids['sha1']
}
},
saltLength: 20
};
}
var capture = {};
var errors = [];
if(!asn1.validate(obj, rsassaPssParameterValidator, capture, errors)) {
var error = new Error('Cannot read RSASSA-PSS parameter block.');
error.errors = errors;
throw error;
}
if(capture.hashOid !== undefined) {
params.hash = params.hash || {};
params.hash.algorithmOid = asn1.derToOid(capture.hashOid);
}
if(capture.maskGenOid !== undefined) {
params.mgf = params.mgf || {};
params.mgf.algorithmOid = asn1.derToOid(capture.maskGenOid);
params.mgf.hash = params.mgf.hash || {};
params.mgf.hash.algorithmOid = asn1.derToOid(capture.maskGenHashOid);
}
if(capture.saltLength !== undefined) {
params.saltLength = capture.saltLength.charCodeAt(0);
}
return params;
}
|
[
"function",
"(",
"oid",
",",
"obj",
",",
"fillDefaults",
")",
"{",
"var",
"params",
"=",
"{",
"}",
";",
"if",
"(",
"oid",
"!==",
"oids",
"[",
"'RSASSA-PSS'",
"]",
")",
"{",
"return",
"params",
";",
"}",
"if",
"(",
"fillDefaults",
")",
"{",
"params",
"=",
"{",
"hash",
":",
"{",
"algorithmOid",
":",
"oids",
"[",
"'sha1'",
"]",
"}",
",",
"mgf",
":",
"{",
"algorithmOid",
":",
"oids",
"[",
"'mgf1'",
"]",
",",
"hash",
":",
"{",
"algorithmOid",
":",
"oids",
"[",
"'sha1'",
"]",
"}",
"}",
",",
"saltLength",
":",
"20",
"}",
";",
"}",
"var",
"capture",
"=",
"{",
"}",
";",
"var",
"errors",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"asn1",
".",
"validate",
"(",
"obj",
",",
"rsassaPssParameterValidator",
",",
"capture",
",",
"errors",
")",
")",
"{",
"var",
"error",
"=",
"new",
"Error",
"(",
"'Cannot read RSASSA-PSS parameter block.'",
")",
";",
"error",
".",
"errors",
"=",
"errors",
";",
"throw",
"error",
";",
"}",
"if",
"(",
"capture",
".",
"hashOid",
"!==",
"undefined",
")",
"{",
"params",
".",
"hash",
"=",
"params",
".",
"hash",
"||",
"{",
"}",
";",
"params",
".",
"hash",
".",
"algorithmOid",
"=",
"asn1",
".",
"derToOid",
"(",
"capture",
".",
"hashOid",
")",
";",
"}",
"if",
"(",
"capture",
".",
"maskGenOid",
"!==",
"undefined",
")",
"{",
"params",
".",
"mgf",
"=",
"params",
".",
"mgf",
"||",
"{",
"}",
";",
"params",
".",
"mgf",
".",
"algorithmOid",
"=",
"asn1",
".",
"derToOid",
"(",
"capture",
".",
"maskGenOid",
")",
";",
"params",
".",
"mgf",
".",
"hash",
"=",
"params",
".",
"mgf",
".",
"hash",
"||",
"{",
"}",
";",
"params",
".",
"mgf",
".",
"hash",
".",
"algorithmOid",
"=",
"asn1",
".",
"derToOid",
"(",
"capture",
".",
"maskGenHashOid",
")",
";",
"}",
"if",
"(",
"capture",
".",
"saltLength",
"!==",
"undefined",
")",
"{",
"params",
".",
"saltLength",
"=",
"capture",
".",
"saltLength",
".",
"charCodeAt",
"(",
"0",
")",
";",
"}",
"return",
"params",
";",
"}"
] |
Converts signature parameters from ASN.1 structure.
Currently only RSASSA-PSS supported. The PKCS#1 v1.5 signature scheme had
no parameters.
RSASSA-PSS-params ::= SEQUENCE {
hashAlgorithm [0] HashAlgorithm DEFAULT
sha1Identifier,
maskGenAlgorithm [1] MaskGenAlgorithm DEFAULT
mgf1SHA1Identifier,
saltLength [2] INTEGER DEFAULT 20,
trailerField [3] INTEGER DEFAULT 1
}
HashAlgorithm ::= AlgorithmIdentifier
MaskGenAlgorithm ::= AlgorithmIdentifier
AlgorithmIdentifer ::= SEQUENCE {
algorithm OBJECT IDENTIFIER,
parameters ANY DEFINED BY algorithm OPTIONAL
}
@param oid The OID specifying the signature algorithm
@param obj The ASN.1 structure holding the parameters
@param fillDefaults Whether to use return default values where omitted
@return signature parameter object
|
[
"Converts",
"signature",
"parameters",
"from",
"ASN",
".",
"1",
"structure",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L17836-L17883
|
|
39,136 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
_dnToAsn1
|
function _dnToAsn1(obj) {
// create an empty RDNSequence
var rval = asn1.create(
asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, []);
// iterate over attributes
var attr, set;
var attrs = obj.attributes;
for(var i = 0; i < attrs.length; ++i) {
attr = attrs[i];
var value = attr.value;
// reuse tag class for attribute value if available
var valueTagClass = asn1.Type.PRINTABLESTRING;
if('valueTagClass' in attr) {
valueTagClass = attr.valueTagClass;
if(valueTagClass === asn1.Type.UTF8) {
value = forge.util.encodeUtf8(value);
}
// FIXME: handle more encodings
}
// create a RelativeDistinguishedName set
// each value in the set is an AttributeTypeAndValue first
// containing the type (an OID) and second the value
set = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, [
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
// AttributeType
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
asn1.oidToDer(attr.type).getBytes()),
// AttributeValue
asn1.create(asn1.Class.UNIVERSAL, valueTagClass, false, value)
])
]);
rval.value.push(set);
}
return rval;
}
|
javascript
|
function _dnToAsn1(obj) {
// create an empty RDNSequence
var rval = asn1.create(
asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, []);
// iterate over attributes
var attr, set;
var attrs = obj.attributes;
for(var i = 0; i < attrs.length; ++i) {
attr = attrs[i];
var value = attr.value;
// reuse tag class for attribute value if available
var valueTagClass = asn1.Type.PRINTABLESTRING;
if('valueTagClass' in attr) {
valueTagClass = attr.valueTagClass;
if(valueTagClass === asn1.Type.UTF8) {
value = forge.util.encodeUtf8(value);
}
// FIXME: handle more encodings
}
// create a RelativeDistinguishedName set
// each value in the set is an AttributeTypeAndValue first
// containing the type (an OID) and second the value
set = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, [
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
// AttributeType
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
asn1.oidToDer(attr.type).getBytes()),
// AttributeValue
asn1.create(asn1.Class.UNIVERSAL, valueTagClass, false, value)
])
]);
rval.value.push(set);
}
return rval;
}
|
[
"function",
"_dnToAsn1",
"(",
"obj",
")",
"{",
"// create an empty RDNSequence\r",
"var",
"rval",
"=",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"SEQUENCE",
",",
"true",
",",
"[",
"]",
")",
";",
"// iterate over attributes\r",
"var",
"attr",
",",
"set",
";",
"var",
"attrs",
"=",
"obj",
".",
"attributes",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"attrs",
".",
"length",
";",
"++",
"i",
")",
"{",
"attr",
"=",
"attrs",
"[",
"i",
"]",
";",
"var",
"value",
"=",
"attr",
".",
"value",
";",
"// reuse tag class for attribute value if available\r",
"var",
"valueTagClass",
"=",
"asn1",
".",
"Type",
".",
"PRINTABLESTRING",
";",
"if",
"(",
"'valueTagClass'",
"in",
"attr",
")",
"{",
"valueTagClass",
"=",
"attr",
".",
"valueTagClass",
";",
"if",
"(",
"valueTagClass",
"===",
"asn1",
".",
"Type",
".",
"UTF8",
")",
"{",
"value",
"=",
"forge",
".",
"util",
".",
"encodeUtf8",
"(",
"value",
")",
";",
"}",
"// FIXME: handle more encodings\r",
"}",
"// create a RelativeDistinguishedName set\r",
"// each value in the set is an AttributeTypeAndValue first\r",
"// containing the type (an OID) and second the value\r",
"set",
"=",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"SET",
",",
"true",
",",
"[",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"SEQUENCE",
",",
"true",
",",
"[",
"// AttributeType\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"OID",
",",
"false",
",",
"asn1",
".",
"oidToDer",
"(",
"attr",
".",
"type",
")",
".",
"getBytes",
"(",
")",
")",
",",
"// AttributeValue\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"valueTagClass",
",",
"false",
",",
"value",
")",
"]",
")",
"]",
")",
";",
"rval",
".",
"value",
".",
"push",
"(",
"set",
")",
";",
"}",
"return",
"rval",
";",
"}"
] |
Converts an X.509 subject or issuer to an ASN.1 RDNSequence.
@param obj the subject or issuer (distinguished name).
@return the ASN.1 RDNSequence.
|
[
"Converts",
"an",
"X",
".",
"509",
"subject",
"or",
"issuer",
"to",
"an",
"ASN",
".",
"1",
"RDNSequence",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L19150-L19189
|
39,137 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
_signatureParametersToAsn1
|
function _signatureParametersToAsn1(oid, params) {
switch(oid) {
case oids['RSASSA-PSS']:
var parts = [];
if(params.hash.algorithmOid !== undefined) {
parts.push(asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
asn1.oidToDer(params.hash.algorithmOid).getBytes()),
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '')
])
]));
}
if(params.mgf.algorithmOid !== undefined) {
parts.push(asn1.create(asn1.Class.CONTEXT_SPECIFIC, 1, true, [
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
asn1.oidToDer(params.mgf.algorithmOid).getBytes()),
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
asn1.oidToDer(params.mgf.hash.algorithmOid).getBytes()),
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '')
])
])
]));
}
if(params.saltLength !== undefined) {
parts.push(asn1.create(asn1.Class.CONTEXT_SPECIFIC, 2, true, [
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
asn1.integerToDer(params.saltLength).getBytes())
]));
}
return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, parts);
default:
return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '');
}
}
|
javascript
|
function _signatureParametersToAsn1(oid, params) {
switch(oid) {
case oids['RSASSA-PSS']:
var parts = [];
if(params.hash.algorithmOid !== undefined) {
parts.push(asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
asn1.oidToDer(params.hash.algorithmOid).getBytes()),
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '')
])
]));
}
if(params.mgf.algorithmOid !== undefined) {
parts.push(asn1.create(asn1.Class.CONTEXT_SPECIFIC, 1, true, [
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
asn1.oidToDer(params.mgf.algorithmOid).getBytes()),
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
asn1.oidToDer(params.mgf.hash.algorithmOid).getBytes()),
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '')
])
])
]));
}
if(params.saltLength !== undefined) {
parts.push(asn1.create(asn1.Class.CONTEXT_SPECIFIC, 2, true, [
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
asn1.integerToDer(params.saltLength).getBytes())
]));
}
return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, parts);
default:
return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '');
}
}
|
[
"function",
"_signatureParametersToAsn1",
"(",
"oid",
",",
"params",
")",
"{",
"switch",
"(",
"oid",
")",
"{",
"case",
"oids",
"[",
"'RSASSA-PSS'",
"]",
":",
"var",
"parts",
"=",
"[",
"]",
";",
"if",
"(",
"params",
".",
"hash",
".",
"algorithmOid",
"!==",
"undefined",
")",
"{",
"parts",
".",
"push",
"(",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"CONTEXT_SPECIFIC",
",",
"0",
",",
"true",
",",
"[",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"SEQUENCE",
",",
"true",
",",
"[",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"OID",
",",
"false",
",",
"asn1",
".",
"oidToDer",
"(",
"params",
".",
"hash",
".",
"algorithmOid",
")",
".",
"getBytes",
"(",
")",
")",
",",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"NULL",
",",
"false",
",",
"''",
")",
"]",
")",
"]",
")",
")",
";",
"}",
"if",
"(",
"params",
".",
"mgf",
".",
"algorithmOid",
"!==",
"undefined",
")",
"{",
"parts",
".",
"push",
"(",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"CONTEXT_SPECIFIC",
",",
"1",
",",
"true",
",",
"[",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"SEQUENCE",
",",
"true",
",",
"[",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"OID",
",",
"false",
",",
"asn1",
".",
"oidToDer",
"(",
"params",
".",
"mgf",
".",
"algorithmOid",
")",
".",
"getBytes",
"(",
")",
")",
",",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"SEQUENCE",
",",
"true",
",",
"[",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"OID",
",",
"false",
",",
"asn1",
".",
"oidToDer",
"(",
"params",
".",
"mgf",
".",
"hash",
".",
"algorithmOid",
")",
".",
"getBytes",
"(",
")",
")",
",",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"NULL",
",",
"false",
",",
"''",
")",
"]",
")",
"]",
")",
"]",
")",
")",
";",
"}",
"if",
"(",
"params",
".",
"saltLength",
"!==",
"undefined",
")",
"{",
"parts",
".",
"push",
"(",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"CONTEXT_SPECIFIC",
",",
"2",
",",
"true",
",",
"[",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"INTEGER",
",",
"false",
",",
"asn1",
".",
"integerToDer",
"(",
"params",
".",
"saltLength",
")",
".",
"getBytes",
"(",
")",
")",
"]",
")",
")",
";",
"}",
"return",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"SEQUENCE",
",",
"true",
",",
"parts",
")",
";",
"default",
":",
"return",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"NULL",
",",
"false",
",",
"''",
")",
";",
"}",
"}"
] |
Convert signature parameters object to ASN.1
@param {String} oid Signature algorithm OID
@param params The signature parametrs object
@return ASN.1 object representing signature parameters
|
[
"Convert",
"signature",
"parameters",
"object",
"to",
"ASN",
".",
"1"
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L19504-L19545
|
39,138 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
_getBagsByAttribute
|
function _getBagsByAttribute(safeContents, attrName, attrValue, bagType) {
var result = [];
for(var i = 0; i < safeContents.length; i ++) {
for(var j = 0; j < safeContents[i].safeBags.length; j ++) {
var bag = safeContents[i].safeBags[j];
if(bagType !== undefined && bag.type !== bagType) {
continue;
}
// only filter by bag type, no attribute specified
if(attrName === null) {
result.push(bag);
continue;
}
if(bag.attributes[attrName] !== undefined &&
bag.attributes[attrName].indexOf(attrValue) >= 0) {
result.push(bag);
}
}
}
return result;
}
|
javascript
|
function _getBagsByAttribute(safeContents, attrName, attrValue, bagType) {
var result = [];
for(var i = 0; i < safeContents.length; i ++) {
for(var j = 0; j < safeContents[i].safeBags.length; j ++) {
var bag = safeContents[i].safeBags[j];
if(bagType !== undefined && bag.type !== bagType) {
continue;
}
// only filter by bag type, no attribute specified
if(attrName === null) {
result.push(bag);
continue;
}
if(bag.attributes[attrName] !== undefined &&
bag.attributes[attrName].indexOf(attrValue) >= 0) {
result.push(bag);
}
}
}
return result;
}
|
[
"function",
"_getBagsByAttribute",
"(",
"safeContents",
",",
"attrName",
",",
"attrValue",
",",
"bagType",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"safeContents",
".",
"length",
";",
"i",
"++",
")",
"{",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"safeContents",
"[",
"i",
"]",
".",
"safeBags",
".",
"length",
";",
"j",
"++",
")",
"{",
"var",
"bag",
"=",
"safeContents",
"[",
"i",
"]",
".",
"safeBags",
"[",
"j",
"]",
";",
"if",
"(",
"bagType",
"!==",
"undefined",
"&&",
"bag",
".",
"type",
"!==",
"bagType",
")",
"{",
"continue",
";",
"}",
"// only filter by bag type, no attribute specified\r",
"if",
"(",
"attrName",
"===",
"null",
")",
"{",
"result",
".",
"push",
"(",
"bag",
")",
";",
"continue",
";",
"}",
"if",
"(",
"bag",
".",
"attributes",
"[",
"attrName",
"]",
"!==",
"undefined",
"&&",
"bag",
".",
"attributes",
"[",
"attrName",
"]",
".",
"indexOf",
"(",
"attrValue",
")",
">=",
"0",
")",
"{",
"result",
".",
"push",
"(",
"bag",
")",
";",
"}",
"}",
"}",
"return",
"result",
";",
"}"
] |
Search SafeContents structure for bags with matching attributes.
The search can optionally be narrowed by a certain bag type.
@param safeContents the SafeContents structure to search in.
@param attrName the name of the attribute to compare against.
@param attrValue the attribute value to search for.
@param [bagType] bag type to narrow search by.
@return an array of matching bags.
|
[
"Search",
"SafeContents",
"structure",
"for",
"bags",
"with",
"matching",
"attributes",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L20671-L20693
|
39,139 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
function(c, record, s) {
var rval = false;
try {
var bytes = c.inflate(record.fragment.getBytes());
record.fragment = forge.util.createBuffer(bytes);
record.length = bytes.length;
rval = true;
} catch(ex) {
// inflate error, fail out
}
return rval;
}
|
javascript
|
function(c, record, s) {
var rval = false;
try {
var bytes = c.inflate(record.fragment.getBytes());
record.fragment = forge.util.createBuffer(bytes);
record.length = bytes.length;
rval = true;
} catch(ex) {
// inflate error, fail out
}
return rval;
}
|
[
"function",
"(",
"c",
",",
"record",
",",
"s",
")",
"{",
"var",
"rval",
"=",
"false",
";",
"try",
"{",
"var",
"bytes",
"=",
"c",
".",
"inflate",
"(",
"record",
".",
"fragment",
".",
"getBytes",
"(",
")",
")",
";",
"record",
".",
"fragment",
"=",
"forge",
".",
"util",
".",
"createBuffer",
"(",
"bytes",
")",
";",
"record",
".",
"length",
"=",
"bytes",
".",
"length",
";",
"rval",
"=",
"true",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"// inflate error, fail out\r",
"}",
"return",
"rval",
";",
"}"
] |
Decompresses the TLSCompressed record into a TLSPlaintext record using the
deflate algorithm.
@param c the TLS connection.
@param record the TLSCompressed record to decompress.
@param s the ConnectionState to use.
@return true on success, false on failure.
|
[
"Decompresses",
"the",
"TLSCompressed",
"record",
"into",
"a",
"TLSPlaintext",
"record",
"using",
"the",
"deflate",
"algorithm",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L22117-L22130
|
|
39,140 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
function(b, lenBytes) {
var len = 0;
switch(lenBytes) {
case 1:
len = b.getByte();
break;
case 2:
len = b.getInt16();
break;
case 3:
len = b.getInt24();
break;
case 4:
len = b.getInt32();
break;
}
// read vector bytes into a new buffer
return forge.util.createBuffer(b.getBytes(len));
}
|
javascript
|
function(b, lenBytes) {
var len = 0;
switch(lenBytes) {
case 1:
len = b.getByte();
break;
case 2:
len = b.getInt16();
break;
case 3:
len = b.getInt24();
break;
case 4:
len = b.getInt32();
break;
}
// read vector bytes into a new buffer
return forge.util.createBuffer(b.getBytes(len));
}
|
[
"function",
"(",
"b",
",",
"lenBytes",
")",
"{",
"var",
"len",
"=",
"0",
";",
"switch",
"(",
"lenBytes",
")",
"{",
"case",
"1",
":",
"len",
"=",
"b",
".",
"getByte",
"(",
")",
";",
"break",
";",
"case",
"2",
":",
"len",
"=",
"b",
".",
"getInt16",
"(",
")",
";",
"break",
";",
"case",
"3",
":",
"len",
"=",
"b",
".",
"getInt24",
"(",
")",
";",
"break",
";",
"case",
"4",
":",
"len",
"=",
"b",
".",
"getInt32",
"(",
")",
";",
"break",
";",
"}",
"// read vector bytes into a new buffer\r",
"return",
"forge",
".",
"util",
".",
"createBuffer",
"(",
"b",
".",
"getBytes",
"(",
"len",
")",
")",
";",
"}"
] |
Reads a TLS variable-length vector from a byte buffer.
Variable-length vectors are defined by specifying a subrange of legal
lengths, inclusively, using the notation <floor..ceiling>. When these are
encoded, the actual length precedes the vector's contents in the byte
stream. The length will be in the form of a number consuming as many bytes
as required to hold the vector's specified maximum (ceiling) length. A
variable-length vector with an actual length field of zero is referred to
as an empty vector.
@param b the byte buffer.
@param lenBytes the number of bytes required to store the length.
@return the resulting byte buffer.
|
[
"Reads",
"a",
"TLS",
"variable",
"-",
"length",
"vector",
"from",
"a",
"byte",
"buffer",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L22148-L22167
|
|
39,141 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
function(b, lenBytes, v) {
// encode length at the start of the vector, where the number of bytes for
// the length is the maximum number of bytes it would take to encode the
// vector's ceiling
b.putInt(v.length(), lenBytes << 3);
b.putBuffer(v);
}
|
javascript
|
function(b, lenBytes, v) {
// encode length at the start of the vector, where the number of bytes for
// the length is the maximum number of bytes it would take to encode the
// vector's ceiling
b.putInt(v.length(), lenBytes << 3);
b.putBuffer(v);
}
|
[
"function",
"(",
"b",
",",
"lenBytes",
",",
"v",
")",
"{",
"// encode length at the start of the vector, where the number of bytes for\r",
"// the length is the maximum number of bytes it would take to encode the\r",
"// vector's ceiling\r",
"b",
".",
"putInt",
"(",
"v",
".",
"length",
"(",
")",
",",
"lenBytes",
"<<",
"3",
")",
";",
"b",
".",
"putBuffer",
"(",
"v",
")",
";",
"}"
] |
Writes a TLS variable-length vector to a byte buffer.
@param b the byte buffer.
@param lenBytes the number of bytes required to store the length.
@param v the byte buffer vector.
|
[
"Writes",
"a",
"TLS",
"variable",
"-",
"length",
"vector",
"to",
"a",
"byte",
"buffer",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L22176-L22182
|
|
39,142 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
function(desc) {
switch(desc) {
case true:
return true;
case tls.Alert.Description.bad_certificate:
return forge.pki.certificateError.bad_certificate;
case tls.Alert.Description.unsupported_certificate:
return forge.pki.certificateError.unsupported_certificate;
case tls.Alert.Description.certificate_revoked:
return forge.pki.certificateError.certificate_revoked;
case tls.Alert.Description.certificate_expired:
return forge.pki.certificateError.certificate_expired;
case tls.Alert.Description.certificate_unknown:
return forge.pki.certificateError.certificate_unknown;
case tls.Alert.Description.unknown_ca:
return forge.pki.certificateError.unknown_ca;
default:
return forge.pki.certificateError.bad_certificate;
}
}
|
javascript
|
function(desc) {
switch(desc) {
case true:
return true;
case tls.Alert.Description.bad_certificate:
return forge.pki.certificateError.bad_certificate;
case tls.Alert.Description.unsupported_certificate:
return forge.pki.certificateError.unsupported_certificate;
case tls.Alert.Description.certificate_revoked:
return forge.pki.certificateError.certificate_revoked;
case tls.Alert.Description.certificate_expired:
return forge.pki.certificateError.certificate_expired;
case tls.Alert.Description.certificate_unknown:
return forge.pki.certificateError.certificate_unknown;
case tls.Alert.Description.unknown_ca:
return forge.pki.certificateError.unknown_ca;
default:
return forge.pki.certificateError.bad_certificate;
}
}
|
[
"function",
"(",
"desc",
")",
"{",
"switch",
"(",
"desc",
")",
"{",
"case",
"true",
":",
"return",
"true",
";",
"case",
"tls",
".",
"Alert",
".",
"Description",
".",
"bad_certificate",
":",
"return",
"forge",
".",
"pki",
".",
"certificateError",
".",
"bad_certificate",
";",
"case",
"tls",
".",
"Alert",
".",
"Description",
".",
"unsupported_certificate",
":",
"return",
"forge",
".",
"pki",
".",
"certificateError",
".",
"unsupported_certificate",
";",
"case",
"tls",
".",
"Alert",
".",
"Description",
".",
"certificate_revoked",
":",
"return",
"forge",
".",
"pki",
".",
"certificateError",
".",
"certificate_revoked",
";",
"case",
"tls",
".",
"Alert",
".",
"Description",
".",
"certificate_expired",
":",
"return",
"forge",
".",
"pki",
".",
"certificateError",
".",
"certificate_expired",
";",
"case",
"tls",
".",
"Alert",
".",
"Description",
".",
"certificate_unknown",
":",
"return",
"forge",
".",
"pki",
".",
"certificateError",
".",
"certificate_unknown",
";",
"case",
"tls",
".",
"Alert",
".",
"Description",
".",
"unknown_ca",
":",
"return",
"forge",
".",
"pki",
".",
"certificateError",
".",
"unknown_ca",
";",
"default",
":",
"return",
"forge",
".",
"pki",
".",
"certificateError",
".",
"bad_certificate",
";",
"}",
"}"
] |
Maps a tls.Alert.Description to a pki.certificateError.
@param desc the alert description.
@return the certificate error.
|
[
"Maps",
"a",
"tls",
".",
"Alert",
".",
"Description",
"to",
"a",
"pki",
".",
"certificateError",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L25174-L25193
|
|
39,143 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
function(c, record) {
// get record handler (align type in table by subtracting lowest)
var aligned = record.type - tls.ContentType.change_cipher_spec;
var handlers = ctTable[c.entity][c.expect];
if(aligned in handlers) {
handlers[aligned](c, record);
} else {
// unexpected record
tls.handleUnexpected(c, record);
}
}
|
javascript
|
function(c, record) {
// get record handler (align type in table by subtracting lowest)
var aligned = record.type - tls.ContentType.change_cipher_spec;
var handlers = ctTable[c.entity][c.expect];
if(aligned in handlers) {
handlers[aligned](c, record);
} else {
// unexpected record
tls.handleUnexpected(c, record);
}
}
|
[
"function",
"(",
"c",
",",
"record",
")",
"{",
"// get record handler (align type in table by subtracting lowest)\r",
"var",
"aligned",
"=",
"record",
".",
"type",
"-",
"tls",
".",
"ContentType",
".",
"change_cipher_spec",
";",
"var",
"handlers",
"=",
"ctTable",
"[",
"c",
".",
"entity",
"]",
"[",
"c",
".",
"expect",
"]",
";",
"if",
"(",
"aligned",
"in",
"handlers",
")",
"{",
"handlers",
"[",
"aligned",
"]",
"(",
"c",
",",
"record",
")",
";",
"}",
"else",
"{",
"// unexpected record\r",
"tls",
".",
"handleUnexpected",
"(",
"c",
",",
"record",
")",
";",
"}",
"}"
] |
Updates the current TLS engine state based on the given record.
@param c the TLS connection.
@param record the TLS record to act on.
|
[
"Updates",
"the",
"current",
"TLS",
"engine",
"state",
"based",
"on",
"the",
"given",
"record",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L25474-L25484
|
|
39,144 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
function(c) {
var rval = 0;
// get input buffer and its length
var b = c.input;
var len = b.length();
// need at least 5 bytes to initialize a record
if(len < 5) {
rval = 5 - len;
} else {
// enough bytes for header
// initialize record
c.record = {
type: b.getByte(),
version: {
major: b.getByte(),
minor: b.getByte()
},
length: b.getInt16(),
fragment: forge.util.createBuffer(),
ready: false
};
// check record version
var compatibleVersion = (c.record.version.major === c.version.major);
if(compatibleVersion && c.session && c.session.version) {
// session version already set, require same minor version
compatibleVersion = (c.record.version.minor === c.version.minor);
}
if(!compatibleVersion) {
c.error(c, {
message: 'Incompatible TLS version.',
send: true,
alert: {
level: tls.Alert.Level.fatal,
description: tls.Alert.Description.protocol_version
}
});
}
}
return rval;
}
|
javascript
|
function(c) {
var rval = 0;
// get input buffer and its length
var b = c.input;
var len = b.length();
// need at least 5 bytes to initialize a record
if(len < 5) {
rval = 5 - len;
} else {
// enough bytes for header
// initialize record
c.record = {
type: b.getByte(),
version: {
major: b.getByte(),
minor: b.getByte()
},
length: b.getInt16(),
fragment: forge.util.createBuffer(),
ready: false
};
// check record version
var compatibleVersion = (c.record.version.major === c.version.major);
if(compatibleVersion && c.session && c.session.version) {
// session version already set, require same minor version
compatibleVersion = (c.record.version.minor === c.version.minor);
}
if(!compatibleVersion) {
c.error(c, {
message: 'Incompatible TLS version.',
send: true,
alert: {
level: tls.Alert.Level.fatal,
description: tls.Alert.Description.protocol_version
}
});
}
}
return rval;
}
|
[
"function",
"(",
"c",
")",
"{",
"var",
"rval",
"=",
"0",
";",
"// get input buffer and its length\r",
"var",
"b",
"=",
"c",
".",
"input",
";",
"var",
"len",
"=",
"b",
".",
"length",
"(",
")",
";",
"// need at least 5 bytes to initialize a record\r",
"if",
"(",
"len",
"<",
"5",
")",
"{",
"rval",
"=",
"5",
"-",
"len",
";",
"}",
"else",
"{",
"// enough bytes for header\r",
"// initialize record\r",
"c",
".",
"record",
"=",
"{",
"type",
":",
"b",
".",
"getByte",
"(",
")",
",",
"version",
":",
"{",
"major",
":",
"b",
".",
"getByte",
"(",
")",
",",
"minor",
":",
"b",
".",
"getByte",
"(",
")",
"}",
",",
"length",
":",
"b",
".",
"getInt16",
"(",
")",
",",
"fragment",
":",
"forge",
".",
"util",
".",
"createBuffer",
"(",
")",
",",
"ready",
":",
"false",
"}",
";",
"// check record version\r",
"var",
"compatibleVersion",
"=",
"(",
"c",
".",
"record",
".",
"version",
".",
"major",
"===",
"c",
".",
"version",
".",
"major",
")",
";",
"if",
"(",
"compatibleVersion",
"&&",
"c",
".",
"session",
"&&",
"c",
".",
"session",
".",
"version",
")",
"{",
"// session version already set, require same minor version\r",
"compatibleVersion",
"=",
"(",
"c",
".",
"record",
".",
"version",
".",
"minor",
"===",
"c",
".",
"version",
".",
"minor",
")",
";",
"}",
"if",
"(",
"!",
"compatibleVersion",
")",
"{",
"c",
".",
"error",
"(",
"c",
",",
"{",
"message",
":",
"'Incompatible TLS version.'",
",",
"send",
":",
"true",
",",
"alert",
":",
"{",
"level",
":",
"tls",
".",
"Alert",
".",
"Level",
".",
"fatal",
",",
"description",
":",
"tls",
".",
"Alert",
".",
"Description",
".",
"protocol_version",
"}",
"}",
")",
";",
"}",
"}",
"return",
"rval",
";",
"}"
] |
Reads the record header and initializes the next record on the given
connection.
@param c the TLS connection with the next record.
@return 0 if the input data could be processed, otherwise the
number of bytes required for data to be processed.
|
[
"Reads",
"the",
"record",
"header",
"and",
"initializes",
"the",
"next",
"record",
"on",
"the",
"given",
"connection",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L25495-L25538
|
|
39,145 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
function(c) {
var rval = 0;
// ensure there is enough input data to get the entire record
var b = c.input;
var len = b.length();
if(len < c.record.length) {
// not enough data yet, return how much is required
rval = c.record.length - len;
} else {
// there is enough data to parse the pending record
// fill record fragment and compact input buffer
c.record.fragment.putBytes(b.getBytes(c.record.length));
b.compact();
// update record using current read state
var s = c.state.current.read;
if(s.update(c, c.record)) {
// see if there is a previously fragmented message that the
// new record's message fragment should be appended to
if(c.fragmented !== null) {
// if the record type matches a previously fragmented
// record, append the record fragment to it
if(c.fragmented.type === c.record.type) {
// concatenate record fragments
c.fragmented.fragment.putBuffer(c.record.fragment);
c.record = c.fragmented;
} else {
// error, invalid fragmented record
c.error(c, {
message: 'Invalid fragmented record.',
send: true,
alert: {
level: tls.Alert.Level.fatal,
description:
tls.Alert.Description.unexpected_message
}
});
}
}
// record is now ready
c.record.ready = true;
}
}
return rval;
}
|
javascript
|
function(c) {
var rval = 0;
// ensure there is enough input data to get the entire record
var b = c.input;
var len = b.length();
if(len < c.record.length) {
// not enough data yet, return how much is required
rval = c.record.length - len;
} else {
// there is enough data to parse the pending record
// fill record fragment and compact input buffer
c.record.fragment.putBytes(b.getBytes(c.record.length));
b.compact();
// update record using current read state
var s = c.state.current.read;
if(s.update(c, c.record)) {
// see if there is a previously fragmented message that the
// new record's message fragment should be appended to
if(c.fragmented !== null) {
// if the record type matches a previously fragmented
// record, append the record fragment to it
if(c.fragmented.type === c.record.type) {
// concatenate record fragments
c.fragmented.fragment.putBuffer(c.record.fragment);
c.record = c.fragmented;
} else {
// error, invalid fragmented record
c.error(c, {
message: 'Invalid fragmented record.',
send: true,
alert: {
level: tls.Alert.Level.fatal,
description:
tls.Alert.Description.unexpected_message
}
});
}
}
// record is now ready
c.record.ready = true;
}
}
return rval;
}
|
[
"function",
"(",
"c",
")",
"{",
"var",
"rval",
"=",
"0",
";",
"// ensure there is enough input data to get the entire record\r",
"var",
"b",
"=",
"c",
".",
"input",
";",
"var",
"len",
"=",
"b",
".",
"length",
"(",
")",
";",
"if",
"(",
"len",
"<",
"c",
".",
"record",
".",
"length",
")",
"{",
"// not enough data yet, return how much is required\r",
"rval",
"=",
"c",
".",
"record",
".",
"length",
"-",
"len",
";",
"}",
"else",
"{",
"// there is enough data to parse the pending record\r",
"// fill record fragment and compact input buffer\r",
"c",
".",
"record",
".",
"fragment",
".",
"putBytes",
"(",
"b",
".",
"getBytes",
"(",
"c",
".",
"record",
".",
"length",
")",
")",
";",
"b",
".",
"compact",
"(",
")",
";",
"// update record using current read state\r",
"var",
"s",
"=",
"c",
".",
"state",
".",
"current",
".",
"read",
";",
"if",
"(",
"s",
".",
"update",
"(",
"c",
",",
"c",
".",
"record",
")",
")",
"{",
"// see if there is a previously fragmented message that the\r",
"// new record's message fragment should be appended to\r",
"if",
"(",
"c",
".",
"fragmented",
"!==",
"null",
")",
"{",
"// if the record type matches a previously fragmented\r",
"// record, append the record fragment to it\r",
"if",
"(",
"c",
".",
"fragmented",
".",
"type",
"===",
"c",
".",
"record",
".",
"type",
")",
"{",
"// concatenate record fragments\r",
"c",
".",
"fragmented",
".",
"fragment",
".",
"putBuffer",
"(",
"c",
".",
"record",
".",
"fragment",
")",
";",
"c",
".",
"record",
"=",
"c",
".",
"fragmented",
";",
"}",
"else",
"{",
"// error, invalid fragmented record\r",
"c",
".",
"error",
"(",
"c",
",",
"{",
"message",
":",
"'Invalid fragmented record.'",
",",
"send",
":",
"true",
",",
"alert",
":",
"{",
"level",
":",
"tls",
".",
"Alert",
".",
"Level",
".",
"fatal",
",",
"description",
":",
"tls",
".",
"Alert",
".",
"Description",
".",
"unexpected_message",
"}",
"}",
")",
";",
"}",
"}",
"// record is now ready\r",
"c",
".",
"record",
".",
"ready",
"=",
"true",
";",
"}",
"}",
"return",
"rval",
";",
"}"
] |
Reads the next record's contents and appends its message to any
previously fragmented message.
@param c the TLS connection with the next record.
@return 0 if the input data could be processed, otherwise the
number of bytes required for data to be processed.
|
[
"Reads",
"the",
"next",
"record",
"s",
"contents",
"and",
"appends",
"its",
"message",
"to",
"any",
"previously",
"fragmented",
"message",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L25549-L25596
|
|
39,146 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
encrypt_aes_cbc_sha1_padding
|
function encrypt_aes_cbc_sha1_padding(blockSize, input, decrypt) {
/* The encrypted data length (TLSCiphertext.length) is one more than the sum
of SecurityParameters.block_length, TLSCompressed.length,
SecurityParameters.mac_length, and padding_length.
The padding may be any length up to 255 bytes long, as long as it results in
the TLSCiphertext.length being an integral multiple of the block length.
Lengths longer than necessary might be desirable to frustrate attacks on a
protocol based on analysis of the lengths of exchanged messages. Each uint8
in the padding data vector must be filled with the padding length value.
The padding length should be such that the total size of the
GenericBlockCipher structure is a multiple of the cipher's block length.
Legal values range from zero to 255, inclusive. This length specifies the
length of the padding field exclusive of the padding_length field itself.
This is slightly different from PKCS#7 because the padding value is 1
less than the actual number of padding bytes if you include the
padding_length uint8 itself as a padding byte. */
if(!decrypt) {
// get the number of padding bytes required to reach the blockSize and
// subtract 1 for the padding value (to make room for the padding_length
// uint8)
var padding = blockSize - (input.length() % blockSize);
input.fillWithByte(padding - 1, padding);
}
return true;
}
|
javascript
|
function encrypt_aes_cbc_sha1_padding(blockSize, input, decrypt) {
/* The encrypted data length (TLSCiphertext.length) is one more than the sum
of SecurityParameters.block_length, TLSCompressed.length,
SecurityParameters.mac_length, and padding_length.
The padding may be any length up to 255 bytes long, as long as it results in
the TLSCiphertext.length being an integral multiple of the block length.
Lengths longer than necessary might be desirable to frustrate attacks on a
protocol based on analysis of the lengths of exchanged messages. Each uint8
in the padding data vector must be filled with the padding length value.
The padding length should be such that the total size of the
GenericBlockCipher structure is a multiple of the cipher's block length.
Legal values range from zero to 255, inclusive. This length specifies the
length of the padding field exclusive of the padding_length field itself.
This is slightly different from PKCS#7 because the padding value is 1
less than the actual number of padding bytes if you include the
padding_length uint8 itself as a padding byte. */
if(!decrypt) {
// get the number of padding bytes required to reach the blockSize and
// subtract 1 for the padding value (to make room for the padding_length
// uint8)
var padding = blockSize - (input.length() % blockSize);
input.fillWithByte(padding - 1, padding);
}
return true;
}
|
[
"function",
"encrypt_aes_cbc_sha1_padding",
"(",
"blockSize",
",",
"input",
",",
"decrypt",
")",
"{",
"/* The encrypted data length (TLSCiphertext.length) is one more than the sum\r\n of SecurityParameters.block_length, TLSCompressed.length,\r\n SecurityParameters.mac_length, and padding_length.\r\n\r\n The padding may be any length up to 255 bytes long, as long as it results in\r\n the TLSCiphertext.length being an integral multiple of the block length.\r\n Lengths longer than necessary might be desirable to frustrate attacks on a\r\n protocol based on analysis of the lengths of exchanged messages. Each uint8\r\n in the padding data vector must be filled with the padding length value.\r\n\r\n The padding length should be such that the total size of the\r\n GenericBlockCipher structure is a multiple of the cipher's block length.\r\n Legal values range from zero to 255, inclusive. This length specifies the\r\n length of the padding field exclusive of the padding_length field itself.\r\n\r\n This is slightly different from PKCS#7 because the padding value is 1\r\n less than the actual number of padding bytes if you include the\r\n padding_length uint8 itself as a padding byte. */",
"if",
"(",
"!",
"decrypt",
")",
"{",
"// get the number of padding bytes required to reach the blockSize and\r",
"// subtract 1 for the padding value (to make room for the padding_length\r",
"// uint8)\r",
"var",
"padding",
"=",
"blockSize",
"-",
"(",
"input",
".",
"length",
"(",
")",
"%",
"blockSize",
")",
";",
"input",
".",
"fillWithByte",
"(",
"padding",
"-",
"1",
",",
"padding",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Handles padding for aes_cbc_sha1 in encrypt mode.
@param blockSize the block size.
@param input the input buffer.
@param decrypt true in decrypt mode, false in encrypt mode.
@return true on success, false on failure.
|
[
"Handles",
"padding",
"for",
"aes_cbc_sha1",
"in",
"encrypt",
"mode",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L26143-L26170
|
39,147 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
compareMacs
|
function compareMacs(key, mac1, mac2) {
var hmac = forge.hmac.create();
hmac.start('SHA1', key);
hmac.update(mac1);
mac1 = hmac.digest().getBytes();
hmac.start(null, null);
hmac.update(mac2);
mac2 = hmac.digest().getBytes();
return mac1 === mac2;
}
|
javascript
|
function compareMacs(key, mac1, mac2) {
var hmac = forge.hmac.create();
hmac.start('SHA1', key);
hmac.update(mac1);
mac1 = hmac.digest().getBytes();
hmac.start(null, null);
hmac.update(mac2);
mac2 = hmac.digest().getBytes();
return mac1 === mac2;
}
|
[
"function",
"compareMacs",
"(",
"key",
",",
"mac1",
",",
"mac2",
")",
"{",
"var",
"hmac",
"=",
"forge",
".",
"hmac",
".",
"create",
"(",
")",
";",
"hmac",
".",
"start",
"(",
"'SHA1'",
",",
"key",
")",
";",
"hmac",
".",
"update",
"(",
"mac1",
")",
";",
"mac1",
"=",
"hmac",
".",
"digest",
"(",
")",
".",
"getBytes",
"(",
")",
";",
"hmac",
".",
"start",
"(",
"null",
",",
"null",
")",
";",
"hmac",
".",
"update",
"(",
"mac2",
")",
";",
"mac2",
"=",
"hmac",
".",
"digest",
"(",
")",
".",
"getBytes",
"(",
")",
";",
"return",
"mac1",
"===",
"mac2",
";",
"}"
] |
Safely compare two MACs. This function will compare two MACs in a way
that protects against timing attacks.
TODO: Expose elsewhere as a utility API.
See: https://www.nccgroup.trust/us/about-us/newsroom-and-events/blog/2011/february/double-hmac-verification/
@param key the MAC key to use.
@param mac1 as a binary-encoded string of bytes.
@param mac2 as a binary-encoded string of bytes.
@return true if the MACs are the same, false if not.
|
[
"Safely",
"compare",
"two",
"MACs",
".",
"This",
"function",
"will",
"compare",
"two",
"MACs",
"in",
"a",
"way",
"that",
"protects",
"against",
"timing",
"attacks",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L26281-L26293
|
39,148 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
_createKDF
|
function _createKDF(kdf, md, counterStart, digestLength) {
/**
* Generate a key of the specified length.
*
* @param x the binary-encoded byte string to generate a key from.
* @param length the number of bytes to generate (the size of the key).
*
* @return the key as a binary-encoded string.
*/
kdf.generate = function(x, length) {
var key = new forge.util.ByteBuffer();
// run counter from counterStart to ceil(length / Hash.len)
var k = Math.ceil(length / digestLength) + counterStart;
var c = new forge.util.ByteBuffer();
for(var i = counterStart; i < k; ++i) {
// I2OSP(i, 4): convert counter to an octet string of 4 octets
c.putInt32(i);
// digest 'x' and the counter and add the result to the key
md.start();
md.update(x + c.getBytes());
var hash = md.digest();
key.putBytes(hash.getBytes(digestLength));
}
// truncate to the correct key length
key.truncate(key.length() - length);
return key.getBytes();
};
}
|
javascript
|
function _createKDF(kdf, md, counterStart, digestLength) {
/**
* Generate a key of the specified length.
*
* @param x the binary-encoded byte string to generate a key from.
* @param length the number of bytes to generate (the size of the key).
*
* @return the key as a binary-encoded string.
*/
kdf.generate = function(x, length) {
var key = new forge.util.ByteBuffer();
// run counter from counterStart to ceil(length / Hash.len)
var k = Math.ceil(length / digestLength) + counterStart;
var c = new forge.util.ByteBuffer();
for(var i = counterStart; i < k; ++i) {
// I2OSP(i, 4): convert counter to an octet string of 4 octets
c.putInt32(i);
// digest 'x' and the counter and add the result to the key
md.start();
md.update(x + c.getBytes());
var hash = md.digest();
key.putBytes(hash.getBytes(digestLength));
}
// truncate to the correct key length
key.truncate(key.length() - length);
return key.getBytes();
};
}
|
[
"function",
"_createKDF",
"(",
"kdf",
",",
"md",
",",
"counterStart",
",",
"digestLength",
")",
"{",
"/**\r\n * Generate a key of the specified length.\r\n *\r\n * @param x the binary-encoded byte string to generate a key from.\r\n * @param length the number of bytes to generate (the size of the key).\r\n *\r\n * @return the key as a binary-encoded string.\r\n */",
"kdf",
".",
"generate",
"=",
"function",
"(",
"x",
",",
"length",
")",
"{",
"var",
"key",
"=",
"new",
"forge",
".",
"util",
".",
"ByteBuffer",
"(",
")",
";",
"// run counter from counterStart to ceil(length / Hash.len)\r",
"var",
"k",
"=",
"Math",
".",
"ceil",
"(",
"length",
"/",
"digestLength",
")",
"+",
"counterStart",
";",
"var",
"c",
"=",
"new",
"forge",
".",
"util",
".",
"ByteBuffer",
"(",
")",
";",
"for",
"(",
"var",
"i",
"=",
"counterStart",
";",
"i",
"<",
"k",
";",
"++",
"i",
")",
"{",
"// I2OSP(i, 4): convert counter to an octet string of 4 octets\r",
"c",
".",
"putInt32",
"(",
"i",
")",
";",
"// digest 'x' and the counter and add the result to the key\r",
"md",
".",
"start",
"(",
")",
";",
"md",
".",
"update",
"(",
"x",
"+",
"c",
".",
"getBytes",
"(",
")",
")",
";",
"var",
"hash",
"=",
"md",
".",
"digest",
"(",
")",
";",
"key",
".",
"putBytes",
"(",
"hash",
".",
"getBytes",
"(",
"digestLength",
")",
")",
";",
"}",
"// truncate to the correct key length\r",
"key",
".",
"truncate",
"(",
"key",
".",
"length",
"(",
")",
"-",
"length",
")",
";",
"return",
"key",
".",
"getBytes",
"(",
")",
";",
"}",
";",
"}"
] |
Creates a KDF1 or KDF2 API object.
@param md the hash API to use.
@param counterStart the starting index for the counter.
@param digestLength the digest length to use.
@return the KDF API object.
|
[
"Creates",
"a",
"KDF1",
"or",
"KDF2",
"API",
"object",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L26619-L26650
|
39,149 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
function(logger, message) {
forge.log.prepareStandardFull(message);
console.log(message.standardFull);
}
|
javascript
|
function(logger, message) {
forge.log.prepareStandardFull(message);
console.log(message.standardFull);
}
|
[
"function",
"(",
"logger",
",",
"message",
")",
"{",
"forge",
".",
"log",
".",
"prepareStandardFull",
"(",
"message",
")",
";",
"console",
".",
"log",
"(",
"message",
".",
"standardFull",
")",
";",
"}"
] |
only appear to have basic console.log
|
[
"only",
"appear",
"to",
"have",
"basic",
"console",
".",
"log"
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L26977-L26980
|
|
39,150 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
function(cert) {
// convert from PEM
if(typeof cert === 'string') {
cert = forge.pki.certificateFromPem(cert);
}
msg.certificates.push(cert);
}
|
javascript
|
function(cert) {
// convert from PEM
if(typeof cert === 'string') {
cert = forge.pki.certificateFromPem(cert);
}
msg.certificates.push(cert);
}
|
[
"function",
"(",
"cert",
")",
"{",
"// convert from PEM\r",
"if",
"(",
"typeof",
"cert",
"===",
"'string'",
")",
"{",
"cert",
"=",
"forge",
".",
"pki",
".",
"certificateFromPem",
"(",
"cert",
")",
";",
"}",
"msg",
".",
"certificates",
".",
"push",
"(",
"cert",
")",
";",
"}"
] |
Add a certificate.
@param cert the certificate to add.
|
[
"Add",
"a",
"certificate",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L27452-L27458
|
|
39,151 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
function(cert) {
var sAttr = cert.issuer.attributes;
for(var i = 0; i < msg.recipients.length; ++i) {
var r = msg.recipients[i];
var rAttr = r.issuer;
if(r.serialNumber !== cert.serialNumber) {
continue;
}
if(rAttr.length !== sAttr.length) {
continue;
}
var match = true;
for(var j = 0; j < sAttr.length; ++j) {
if(rAttr[j].type !== sAttr[j].type ||
rAttr[j].value !== sAttr[j].value) {
match = false;
break;
}
}
if(match) {
return r;
}
}
return null;
}
|
javascript
|
function(cert) {
var sAttr = cert.issuer.attributes;
for(var i = 0; i < msg.recipients.length; ++i) {
var r = msg.recipients[i];
var rAttr = r.issuer;
if(r.serialNumber !== cert.serialNumber) {
continue;
}
if(rAttr.length !== sAttr.length) {
continue;
}
var match = true;
for(var j = 0; j < sAttr.length; ++j) {
if(rAttr[j].type !== sAttr[j].type ||
rAttr[j].value !== sAttr[j].value) {
match = false;
break;
}
}
if(match) {
return r;
}
}
return null;
}
|
[
"function",
"(",
"cert",
")",
"{",
"var",
"sAttr",
"=",
"cert",
".",
"issuer",
".",
"attributes",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"msg",
".",
"recipients",
".",
"length",
";",
"++",
"i",
")",
"{",
"var",
"r",
"=",
"msg",
".",
"recipients",
"[",
"i",
"]",
";",
"var",
"rAttr",
"=",
"r",
".",
"issuer",
";",
"if",
"(",
"r",
".",
"serialNumber",
"!==",
"cert",
".",
"serialNumber",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"rAttr",
".",
"length",
"!==",
"sAttr",
".",
"length",
")",
"{",
"continue",
";",
"}",
"var",
"match",
"=",
"true",
";",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"sAttr",
".",
"length",
";",
"++",
"j",
")",
"{",
"if",
"(",
"rAttr",
"[",
"j",
"]",
".",
"type",
"!==",
"sAttr",
"[",
"j",
"]",
".",
"type",
"||",
"rAttr",
"[",
"j",
"]",
".",
"value",
"!==",
"sAttr",
"[",
"j",
"]",
".",
"value",
")",
"{",
"match",
"=",
"false",
";",
"break",
";",
"}",
"}",
"if",
"(",
"match",
")",
"{",
"return",
"r",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Find recipient by X.509 certificate's issuer.
@param cert the certificate with the issuer to look for.
@return the recipient object.
|
[
"Find",
"recipient",
"by",
"X",
".",
"509",
"certificate",
"s",
"issuer",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L27693-L27723
|
|
39,152 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
function(recipient, privKey) {
if(msg.encryptedContent.key === undefined && recipient !== undefined &&
privKey !== undefined) {
switch(recipient.encryptedContent.algorithm) {
case forge.pki.oids.rsaEncryption:
case forge.pki.oids.desCBC:
var key = privKey.decrypt(recipient.encryptedContent.content);
msg.encryptedContent.key = forge.util.createBuffer(key);
break;
default:
throw new Error('Unsupported asymmetric cipher, ' +
'OID ' + recipient.encryptedContent.algorithm);
}
}
_decryptContent(msg);
}
|
javascript
|
function(recipient, privKey) {
if(msg.encryptedContent.key === undefined && recipient !== undefined &&
privKey !== undefined) {
switch(recipient.encryptedContent.algorithm) {
case forge.pki.oids.rsaEncryption:
case forge.pki.oids.desCBC:
var key = privKey.decrypt(recipient.encryptedContent.content);
msg.encryptedContent.key = forge.util.createBuffer(key);
break;
default:
throw new Error('Unsupported asymmetric cipher, ' +
'OID ' + recipient.encryptedContent.algorithm);
}
}
_decryptContent(msg);
}
|
[
"function",
"(",
"recipient",
",",
"privKey",
")",
"{",
"if",
"(",
"msg",
".",
"encryptedContent",
".",
"key",
"===",
"undefined",
"&&",
"recipient",
"!==",
"undefined",
"&&",
"privKey",
"!==",
"undefined",
")",
"{",
"switch",
"(",
"recipient",
".",
"encryptedContent",
".",
"algorithm",
")",
"{",
"case",
"forge",
".",
"pki",
".",
"oids",
".",
"rsaEncryption",
":",
"case",
"forge",
".",
"pki",
".",
"oids",
".",
"desCBC",
":",
"var",
"key",
"=",
"privKey",
".",
"decrypt",
"(",
"recipient",
".",
"encryptedContent",
".",
"content",
")",
";",
"msg",
".",
"encryptedContent",
".",
"key",
"=",
"forge",
".",
"util",
".",
"createBuffer",
"(",
"key",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"Error",
"(",
"'Unsupported asymmetric cipher, '",
"+",
"'OID '",
"+",
"recipient",
".",
"encryptedContent",
".",
"algorithm",
")",
";",
"}",
"}",
"_decryptContent",
"(",
"msg",
")",
";",
"}"
] |
Decrypt enveloped content
@param recipient The recipient object related to the private key
@param privKey The (RSA) private key object
|
[
"Decrypt",
"enveloped",
"content"
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L27731-L27748
|
|
39,153 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
function(key, cipher) {
// Part 1: Symmetric encryption
if(msg.encryptedContent.content === undefined) {
cipher = cipher || msg.encryptedContent.algorithm;
key = key || msg.encryptedContent.key;
var keyLen, ivLen, ciphFn;
switch(cipher) {
case forge.pki.oids['aes128-CBC']:
keyLen = 16;
ivLen = 16;
ciphFn = forge.aes.createEncryptionCipher;
break;
case forge.pki.oids['aes192-CBC']:
keyLen = 24;
ivLen = 16;
ciphFn = forge.aes.createEncryptionCipher;
break;
case forge.pki.oids['aes256-CBC']:
keyLen = 32;
ivLen = 16;
ciphFn = forge.aes.createEncryptionCipher;
break;
case forge.pki.oids['des-EDE3-CBC']:
keyLen = 24;
ivLen = 8;
ciphFn = forge.des.createEncryptionCipher;
break;
default:
throw new Error('Unsupported symmetric cipher, OID ' + cipher);
}
if(key === undefined) {
key = forge.util.createBuffer(forge.random.getBytes(keyLen));
} else if(key.length() != keyLen) {
throw new Error('Symmetric key has wrong length; ' +
'got ' + key.length() + ' bytes, expected ' + keyLen + '.');
}
// Keep a copy of the key & IV in the object, so the caller can
// use it for whatever reason.
msg.encryptedContent.algorithm = cipher;
msg.encryptedContent.key = key;
msg.encryptedContent.parameter = forge.util.createBuffer(
forge.random.getBytes(ivLen));
var ciph = ciphFn(key);
ciph.start(msg.encryptedContent.parameter.copy());
ciph.update(msg.content);
// The finish function does PKCS#7 padding by default, therefore
// no action required by us.
if(!ciph.finish()) {
throw new Error('Symmetric encryption failed.');
}
msg.encryptedContent.content = ciph.output;
}
// Part 2: asymmetric encryption for each recipient
for(var i = 0; i < msg.recipients.length; ++i) {
var recipient = msg.recipients[i];
// Nothing to do, encryption already done.
if(recipient.encryptedContent.content !== undefined) {
continue;
}
switch(recipient.encryptedContent.algorithm) {
case forge.pki.oids.rsaEncryption:
recipient.encryptedContent.content =
recipient.encryptedContent.key.encrypt(
msg.encryptedContent.key.data);
break;
default:
throw new Error('Unsupported asymmetric cipher, OID ' +
recipient.encryptedContent.algorithm);
}
}
}
|
javascript
|
function(key, cipher) {
// Part 1: Symmetric encryption
if(msg.encryptedContent.content === undefined) {
cipher = cipher || msg.encryptedContent.algorithm;
key = key || msg.encryptedContent.key;
var keyLen, ivLen, ciphFn;
switch(cipher) {
case forge.pki.oids['aes128-CBC']:
keyLen = 16;
ivLen = 16;
ciphFn = forge.aes.createEncryptionCipher;
break;
case forge.pki.oids['aes192-CBC']:
keyLen = 24;
ivLen = 16;
ciphFn = forge.aes.createEncryptionCipher;
break;
case forge.pki.oids['aes256-CBC']:
keyLen = 32;
ivLen = 16;
ciphFn = forge.aes.createEncryptionCipher;
break;
case forge.pki.oids['des-EDE3-CBC']:
keyLen = 24;
ivLen = 8;
ciphFn = forge.des.createEncryptionCipher;
break;
default:
throw new Error('Unsupported symmetric cipher, OID ' + cipher);
}
if(key === undefined) {
key = forge.util.createBuffer(forge.random.getBytes(keyLen));
} else if(key.length() != keyLen) {
throw new Error('Symmetric key has wrong length; ' +
'got ' + key.length() + ' bytes, expected ' + keyLen + '.');
}
// Keep a copy of the key & IV in the object, so the caller can
// use it for whatever reason.
msg.encryptedContent.algorithm = cipher;
msg.encryptedContent.key = key;
msg.encryptedContent.parameter = forge.util.createBuffer(
forge.random.getBytes(ivLen));
var ciph = ciphFn(key);
ciph.start(msg.encryptedContent.parameter.copy());
ciph.update(msg.content);
// The finish function does PKCS#7 padding by default, therefore
// no action required by us.
if(!ciph.finish()) {
throw new Error('Symmetric encryption failed.');
}
msg.encryptedContent.content = ciph.output;
}
// Part 2: asymmetric encryption for each recipient
for(var i = 0; i < msg.recipients.length; ++i) {
var recipient = msg.recipients[i];
// Nothing to do, encryption already done.
if(recipient.encryptedContent.content !== undefined) {
continue;
}
switch(recipient.encryptedContent.algorithm) {
case forge.pki.oids.rsaEncryption:
recipient.encryptedContent.content =
recipient.encryptedContent.key.encrypt(
msg.encryptedContent.key.data);
break;
default:
throw new Error('Unsupported asymmetric cipher, OID ' +
recipient.encryptedContent.algorithm);
}
}
}
|
[
"function",
"(",
"key",
",",
"cipher",
")",
"{",
"// Part 1: Symmetric encryption\r",
"if",
"(",
"msg",
".",
"encryptedContent",
".",
"content",
"===",
"undefined",
")",
"{",
"cipher",
"=",
"cipher",
"||",
"msg",
".",
"encryptedContent",
".",
"algorithm",
";",
"key",
"=",
"key",
"||",
"msg",
".",
"encryptedContent",
".",
"key",
";",
"var",
"keyLen",
",",
"ivLen",
",",
"ciphFn",
";",
"switch",
"(",
"cipher",
")",
"{",
"case",
"forge",
".",
"pki",
".",
"oids",
"[",
"'aes128-CBC'",
"]",
":",
"keyLen",
"=",
"16",
";",
"ivLen",
"=",
"16",
";",
"ciphFn",
"=",
"forge",
".",
"aes",
".",
"createEncryptionCipher",
";",
"break",
";",
"case",
"forge",
".",
"pki",
".",
"oids",
"[",
"'aes192-CBC'",
"]",
":",
"keyLen",
"=",
"24",
";",
"ivLen",
"=",
"16",
";",
"ciphFn",
"=",
"forge",
".",
"aes",
".",
"createEncryptionCipher",
";",
"break",
";",
"case",
"forge",
".",
"pki",
".",
"oids",
"[",
"'aes256-CBC'",
"]",
":",
"keyLen",
"=",
"32",
";",
"ivLen",
"=",
"16",
";",
"ciphFn",
"=",
"forge",
".",
"aes",
".",
"createEncryptionCipher",
";",
"break",
";",
"case",
"forge",
".",
"pki",
".",
"oids",
"[",
"'des-EDE3-CBC'",
"]",
":",
"keyLen",
"=",
"24",
";",
"ivLen",
"=",
"8",
";",
"ciphFn",
"=",
"forge",
".",
"des",
".",
"createEncryptionCipher",
";",
"break",
";",
"default",
":",
"throw",
"new",
"Error",
"(",
"'Unsupported symmetric cipher, OID '",
"+",
"cipher",
")",
";",
"}",
"if",
"(",
"key",
"===",
"undefined",
")",
"{",
"key",
"=",
"forge",
".",
"util",
".",
"createBuffer",
"(",
"forge",
".",
"random",
".",
"getBytes",
"(",
"keyLen",
")",
")",
";",
"}",
"else",
"if",
"(",
"key",
".",
"length",
"(",
")",
"!=",
"keyLen",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Symmetric key has wrong length; '",
"+",
"'got '",
"+",
"key",
".",
"length",
"(",
")",
"+",
"' bytes, expected '",
"+",
"keyLen",
"+",
"'.'",
")",
";",
"}",
"// Keep a copy of the key & IV in the object, so the caller can\r",
"// use it for whatever reason.\r",
"msg",
".",
"encryptedContent",
".",
"algorithm",
"=",
"cipher",
";",
"msg",
".",
"encryptedContent",
".",
"key",
"=",
"key",
";",
"msg",
".",
"encryptedContent",
".",
"parameter",
"=",
"forge",
".",
"util",
".",
"createBuffer",
"(",
"forge",
".",
"random",
".",
"getBytes",
"(",
"ivLen",
")",
")",
";",
"var",
"ciph",
"=",
"ciphFn",
"(",
"key",
")",
";",
"ciph",
".",
"start",
"(",
"msg",
".",
"encryptedContent",
".",
"parameter",
".",
"copy",
"(",
")",
")",
";",
"ciph",
".",
"update",
"(",
"msg",
".",
"content",
")",
";",
"// The finish function does PKCS#7 padding by default, therefore\r",
"// no action required by us.\r",
"if",
"(",
"!",
"ciph",
".",
"finish",
"(",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Symmetric encryption failed.'",
")",
";",
"}",
"msg",
".",
"encryptedContent",
".",
"content",
"=",
"ciph",
".",
"output",
";",
"}",
"// Part 2: asymmetric encryption for each recipient\r",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"msg",
".",
"recipients",
".",
"length",
";",
"++",
"i",
")",
"{",
"var",
"recipient",
"=",
"msg",
".",
"recipients",
"[",
"i",
"]",
";",
"// Nothing to do, encryption already done.\r",
"if",
"(",
"recipient",
".",
"encryptedContent",
".",
"content",
"!==",
"undefined",
")",
"{",
"continue",
";",
"}",
"switch",
"(",
"recipient",
".",
"encryptedContent",
".",
"algorithm",
")",
"{",
"case",
"forge",
".",
"pki",
".",
"oids",
".",
"rsaEncryption",
":",
"recipient",
".",
"encryptedContent",
".",
"content",
"=",
"recipient",
".",
"encryptedContent",
".",
"key",
".",
"encrypt",
"(",
"msg",
".",
"encryptedContent",
".",
"key",
".",
"data",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"Error",
"(",
"'Unsupported asymmetric cipher, OID '",
"+",
"recipient",
".",
"encryptedContent",
".",
"algorithm",
")",
";",
"}",
"}",
"}"
] |
Encrypt enveloped content.
This function supports two optional arguments, cipher and key, which
can be used to influence symmetric encryption. Unless cipher is
provided, the cipher specified in encryptedContent.algorithm is used
(defaults to AES-256-CBC). If no key is provided, encryptedContent.key
is (re-)used. If that one's not set, a random key will be generated
automatically.
@param [key] The key to be used for symmetric encryption.
@param [cipher] The OID of the symmetric cipher to use.
|
[
"Encrypt",
"enveloped",
"content",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L27783-L27867
|
|
39,154 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
_recipientFromAsn1
|
function _recipientFromAsn1(obj) {
// validate EnvelopedData content block and capture data
var capture = {};
var errors = [];
if(!asn1.validate(obj, p7.asn1.recipientInfoValidator, capture, errors)) {
var error = new Error('Cannot read PKCS#7 RecipientInfo. ' +
'ASN.1 object is not an PKCS#7 RecipientInfo.');
error.errors = errors;
throw error;
}
return {
version: capture.version.charCodeAt(0),
issuer: forge.pki.RDNAttributesAsArray(capture.issuer),
serialNumber: forge.util.createBuffer(capture.serial).toHex(),
encryptedContent: {
algorithm: asn1.derToOid(capture.encAlgorithm),
parameter: capture.encParameter.value,
content: capture.encKey
}
};
}
|
javascript
|
function _recipientFromAsn1(obj) {
// validate EnvelopedData content block and capture data
var capture = {};
var errors = [];
if(!asn1.validate(obj, p7.asn1.recipientInfoValidator, capture, errors)) {
var error = new Error('Cannot read PKCS#7 RecipientInfo. ' +
'ASN.1 object is not an PKCS#7 RecipientInfo.');
error.errors = errors;
throw error;
}
return {
version: capture.version.charCodeAt(0),
issuer: forge.pki.RDNAttributesAsArray(capture.issuer),
serialNumber: forge.util.createBuffer(capture.serial).toHex(),
encryptedContent: {
algorithm: asn1.derToOid(capture.encAlgorithm),
parameter: capture.encParameter.value,
content: capture.encKey
}
};
}
|
[
"function",
"_recipientFromAsn1",
"(",
"obj",
")",
"{",
"// validate EnvelopedData content block and capture data\r",
"var",
"capture",
"=",
"{",
"}",
";",
"var",
"errors",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"asn1",
".",
"validate",
"(",
"obj",
",",
"p7",
".",
"asn1",
".",
"recipientInfoValidator",
",",
"capture",
",",
"errors",
")",
")",
"{",
"var",
"error",
"=",
"new",
"Error",
"(",
"'Cannot read PKCS#7 RecipientInfo. '",
"+",
"'ASN.1 object is not an PKCS#7 RecipientInfo.'",
")",
";",
"error",
".",
"errors",
"=",
"errors",
";",
"throw",
"error",
";",
"}",
"return",
"{",
"version",
":",
"capture",
".",
"version",
".",
"charCodeAt",
"(",
"0",
")",
",",
"issuer",
":",
"forge",
".",
"pki",
".",
"RDNAttributesAsArray",
"(",
"capture",
".",
"issuer",
")",
",",
"serialNumber",
":",
"forge",
".",
"util",
".",
"createBuffer",
"(",
"capture",
".",
"serial",
")",
".",
"toHex",
"(",
")",
",",
"encryptedContent",
":",
"{",
"algorithm",
":",
"asn1",
".",
"derToOid",
"(",
"capture",
".",
"encAlgorithm",
")",
",",
"parameter",
":",
"capture",
".",
"encParameter",
".",
"value",
",",
"content",
":",
"capture",
".",
"encKey",
"}",
"}",
";",
"}"
] |
Converts a single recipient from an ASN.1 object.
@param obj the ASN.1 RecipientInfo.
@return the recipient object.
|
[
"Converts",
"a",
"single",
"recipient",
"from",
"an",
"ASN",
".",
"1",
"object",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L27879-L27900
|
39,155 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
_recipientToAsn1
|
function _recipientToAsn1(obj) {
return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
// Version
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
asn1.integerToDer(obj.version).getBytes()),
// IssuerAndSerialNumber
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
// Name
forge.pki.distinguishedNameToAsn1({attributes: obj.issuer}),
// Serial
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
forge.util.hexToBytes(obj.serialNumber))
]),
// KeyEncryptionAlgorithmIdentifier
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
// Algorithm
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
asn1.oidToDer(obj.encryptedContent.algorithm).getBytes()),
// Parameter, force NULL, only RSA supported for now.
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '')
]),
// EncryptedKey
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false,
obj.encryptedContent.content)
]);
}
|
javascript
|
function _recipientToAsn1(obj) {
return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
// Version
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
asn1.integerToDer(obj.version).getBytes()),
// IssuerAndSerialNumber
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
// Name
forge.pki.distinguishedNameToAsn1({attributes: obj.issuer}),
// Serial
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
forge.util.hexToBytes(obj.serialNumber))
]),
// KeyEncryptionAlgorithmIdentifier
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
// Algorithm
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
asn1.oidToDer(obj.encryptedContent.algorithm).getBytes()),
// Parameter, force NULL, only RSA supported for now.
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '')
]),
// EncryptedKey
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false,
obj.encryptedContent.content)
]);
}
|
[
"function",
"_recipientToAsn1",
"(",
"obj",
")",
"{",
"return",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"SEQUENCE",
",",
"true",
",",
"[",
"// Version\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"INTEGER",
",",
"false",
",",
"asn1",
".",
"integerToDer",
"(",
"obj",
".",
"version",
")",
".",
"getBytes",
"(",
")",
")",
",",
"// IssuerAndSerialNumber\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"SEQUENCE",
",",
"true",
",",
"[",
"// Name\r",
"forge",
".",
"pki",
".",
"distinguishedNameToAsn1",
"(",
"{",
"attributes",
":",
"obj",
".",
"issuer",
"}",
")",
",",
"// Serial\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"INTEGER",
",",
"false",
",",
"forge",
".",
"util",
".",
"hexToBytes",
"(",
"obj",
".",
"serialNumber",
")",
")",
"]",
")",
",",
"// KeyEncryptionAlgorithmIdentifier\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"SEQUENCE",
",",
"true",
",",
"[",
"// Algorithm\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"OID",
",",
"false",
",",
"asn1",
".",
"oidToDer",
"(",
"obj",
".",
"encryptedContent",
".",
"algorithm",
")",
".",
"getBytes",
"(",
")",
")",
",",
"// Parameter, force NULL, only RSA supported for now.\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"NULL",
",",
"false",
",",
"''",
")",
"]",
")",
",",
"// EncryptedKey\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"OCTETSTRING",
",",
"false",
",",
"obj",
".",
"encryptedContent",
".",
"content",
")",
"]",
")",
";",
"}"
] |
Converts a single recipient object to an ASN.1 object.
@param obj the recipient object.
@return the ASN.1 RecipientInfo.
|
[
"Converts",
"a",
"single",
"recipient",
"object",
"to",
"an",
"ASN",
".",
"1",
"object",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L27909-L27934
|
39,156 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
_recipientsFromAsn1
|
function _recipientsFromAsn1(infos) {
var ret = [];
for(var i = 0; i < infos.length; ++i) {
ret.push(_recipientFromAsn1(infos[i]));
}
return ret;
}
|
javascript
|
function _recipientsFromAsn1(infos) {
var ret = [];
for(var i = 0; i < infos.length; ++i) {
ret.push(_recipientFromAsn1(infos[i]));
}
return ret;
}
|
[
"function",
"_recipientsFromAsn1",
"(",
"infos",
")",
"{",
"var",
"ret",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"infos",
".",
"length",
";",
"++",
"i",
")",
"{",
"ret",
".",
"push",
"(",
"_recipientFromAsn1",
"(",
"infos",
"[",
"i",
"]",
")",
")",
";",
"}",
"return",
"ret",
";",
"}"
] |
Map a set of RecipientInfo ASN.1 objects to recipient objects.
@param infos an array of ASN.1 representations RecipientInfo (i.e. SET OF).
@return an array of recipient objects.
|
[
"Map",
"a",
"set",
"of",
"RecipientInfo",
"ASN",
".",
"1",
"objects",
"to",
"recipient",
"objects",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L27943-L27949
|
39,157 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
_recipientsToAsn1
|
function _recipientsToAsn1(recipients) {
var ret = [];
for(var i = 0; i < recipients.length; ++i) {
ret.push(_recipientToAsn1(recipients[i]));
}
return ret;
}
|
javascript
|
function _recipientsToAsn1(recipients) {
var ret = [];
for(var i = 0; i < recipients.length; ++i) {
ret.push(_recipientToAsn1(recipients[i]));
}
return ret;
}
|
[
"function",
"_recipientsToAsn1",
"(",
"recipients",
")",
"{",
"var",
"ret",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"recipients",
".",
"length",
";",
"++",
"i",
")",
"{",
"ret",
".",
"push",
"(",
"_recipientToAsn1",
"(",
"recipients",
"[",
"i",
"]",
")",
")",
";",
"}",
"return",
"ret",
";",
"}"
] |
Map an array of recipient objects to ASN.1 RecipientInfo objects.
@param recipients an array of recipientInfo objects.
@return an array of ASN.1 RecipientInfos.
|
[
"Map",
"an",
"array",
"of",
"recipient",
"objects",
"to",
"ASN",
".",
"1",
"RecipientInfo",
"objects",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L27958-L27964
|
39,158 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
_signerFromAsn1
|
function _signerFromAsn1(obj) {
// validate EnvelopedData content block and capture data
var capture = {};
var errors = [];
if(!asn1.validate(obj, p7.asn1.signerInfoValidator, capture, errors)) {
var error = new Error('Cannot read PKCS#7 SignerInfo. ' +
'ASN.1 object is not an PKCS#7 SignerInfo.');
error.errors = errors;
throw error;
}
var rval = {
version: capture.version.charCodeAt(0),
issuer: forge.pki.RDNAttributesAsArray(capture.issuer),
serialNumber: forge.util.createBuffer(capture.serial).toHex(),
digestAlgorithm: asn1.derToOid(capture.digestAlgorithm),
signatureAlgorithm: asn1.derToOid(capture.signatureAlgorithm),
signature: capture.signature,
authenticatedAttributes: [],
unauthenticatedAttributes: []
};
// TODO: convert attributes
var authenticatedAttributes = capture.authenticatedAttributes || [];
var unauthenticatedAttributes = capture.unauthenticatedAttributes || [];
return rval;
}
|
javascript
|
function _signerFromAsn1(obj) {
// validate EnvelopedData content block and capture data
var capture = {};
var errors = [];
if(!asn1.validate(obj, p7.asn1.signerInfoValidator, capture, errors)) {
var error = new Error('Cannot read PKCS#7 SignerInfo. ' +
'ASN.1 object is not an PKCS#7 SignerInfo.');
error.errors = errors;
throw error;
}
var rval = {
version: capture.version.charCodeAt(0),
issuer: forge.pki.RDNAttributesAsArray(capture.issuer),
serialNumber: forge.util.createBuffer(capture.serial).toHex(),
digestAlgorithm: asn1.derToOid(capture.digestAlgorithm),
signatureAlgorithm: asn1.derToOid(capture.signatureAlgorithm),
signature: capture.signature,
authenticatedAttributes: [],
unauthenticatedAttributes: []
};
// TODO: convert attributes
var authenticatedAttributes = capture.authenticatedAttributes || [];
var unauthenticatedAttributes = capture.unauthenticatedAttributes || [];
return rval;
}
|
[
"function",
"_signerFromAsn1",
"(",
"obj",
")",
"{",
"// validate EnvelopedData content block and capture data\r",
"var",
"capture",
"=",
"{",
"}",
";",
"var",
"errors",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"asn1",
".",
"validate",
"(",
"obj",
",",
"p7",
".",
"asn1",
".",
"signerInfoValidator",
",",
"capture",
",",
"errors",
")",
")",
"{",
"var",
"error",
"=",
"new",
"Error",
"(",
"'Cannot read PKCS#7 SignerInfo. '",
"+",
"'ASN.1 object is not an PKCS#7 SignerInfo.'",
")",
";",
"error",
".",
"errors",
"=",
"errors",
";",
"throw",
"error",
";",
"}",
"var",
"rval",
"=",
"{",
"version",
":",
"capture",
".",
"version",
".",
"charCodeAt",
"(",
"0",
")",
",",
"issuer",
":",
"forge",
".",
"pki",
".",
"RDNAttributesAsArray",
"(",
"capture",
".",
"issuer",
")",
",",
"serialNumber",
":",
"forge",
".",
"util",
".",
"createBuffer",
"(",
"capture",
".",
"serial",
")",
".",
"toHex",
"(",
")",
",",
"digestAlgorithm",
":",
"asn1",
".",
"derToOid",
"(",
"capture",
".",
"digestAlgorithm",
")",
",",
"signatureAlgorithm",
":",
"asn1",
".",
"derToOid",
"(",
"capture",
".",
"signatureAlgorithm",
")",
",",
"signature",
":",
"capture",
".",
"signature",
",",
"authenticatedAttributes",
":",
"[",
"]",
",",
"unauthenticatedAttributes",
":",
"[",
"]",
"}",
";",
"// TODO: convert attributes\r",
"var",
"authenticatedAttributes",
"=",
"capture",
".",
"authenticatedAttributes",
"||",
"[",
"]",
";",
"var",
"unauthenticatedAttributes",
"=",
"capture",
".",
"unauthenticatedAttributes",
"||",
"[",
"]",
";",
"return",
"rval",
";",
"}"
] |
Converts a single signer from an ASN.1 object.
@param obj the ASN.1 representation of a SignerInfo.
@return the signer object.
|
[
"Converts",
"a",
"single",
"signer",
"from",
"an",
"ASN",
".",
"1",
"object",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L27973-L28000
|
39,159 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
_signerToAsn1
|
function _signerToAsn1(obj) {
// SignerInfo
var rval = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
// version
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
asn1.integerToDer(obj.version).getBytes()),
// issuerAndSerialNumber
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
// name
forge.pki.distinguishedNameToAsn1({attributes: obj.issuer}),
// serial
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
forge.util.hexToBytes(obj.serialNumber))
]),
// digestAlgorithm
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
// algorithm
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
asn1.oidToDer(obj.digestAlgorithm).getBytes()),
// parameters (null)
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '')
])
]);
// authenticatedAttributes (OPTIONAL)
if(obj.authenticatedAttributesAsn1) {
// add ASN.1 previously generated during signing
rval.value.push(obj.authenticatedAttributesAsn1);
}
// digestEncryptionAlgorithm
rval.value.push(asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
// algorithm
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
asn1.oidToDer(obj.signatureAlgorithm).getBytes()),
// parameters (null)
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '')
]));
// encryptedDigest
rval.value.push(asn1.create(
asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, obj.signature));
// unauthenticatedAttributes (OPTIONAL)
if(obj.unauthenticatedAttributes.length > 0) {
// [1] IMPLICIT
var attrsAsn1 = asn1.create(asn1.Class.CONTEXT_SPECIFIC, 1, true, []);
for(var i = 0; i < obj.unauthenticatedAttributes.length; ++i) {
var attr = obj.unauthenticatedAttributes[i];
attrsAsn1.values.push(_attributeToAsn1(attr));
}
rval.value.push(attrsAsn1);
}
return rval;
}
|
javascript
|
function _signerToAsn1(obj) {
// SignerInfo
var rval = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
// version
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
asn1.integerToDer(obj.version).getBytes()),
// issuerAndSerialNumber
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
// name
forge.pki.distinguishedNameToAsn1({attributes: obj.issuer}),
// serial
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
forge.util.hexToBytes(obj.serialNumber))
]),
// digestAlgorithm
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
// algorithm
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
asn1.oidToDer(obj.digestAlgorithm).getBytes()),
// parameters (null)
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '')
])
]);
// authenticatedAttributes (OPTIONAL)
if(obj.authenticatedAttributesAsn1) {
// add ASN.1 previously generated during signing
rval.value.push(obj.authenticatedAttributesAsn1);
}
// digestEncryptionAlgorithm
rval.value.push(asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
// algorithm
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
asn1.oidToDer(obj.signatureAlgorithm).getBytes()),
// parameters (null)
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '')
]));
// encryptedDigest
rval.value.push(asn1.create(
asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, obj.signature));
// unauthenticatedAttributes (OPTIONAL)
if(obj.unauthenticatedAttributes.length > 0) {
// [1] IMPLICIT
var attrsAsn1 = asn1.create(asn1.Class.CONTEXT_SPECIFIC, 1, true, []);
for(var i = 0; i < obj.unauthenticatedAttributes.length; ++i) {
var attr = obj.unauthenticatedAttributes[i];
attrsAsn1.values.push(_attributeToAsn1(attr));
}
rval.value.push(attrsAsn1);
}
return rval;
}
|
[
"function",
"_signerToAsn1",
"(",
"obj",
")",
"{",
"// SignerInfo\r",
"var",
"rval",
"=",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"SEQUENCE",
",",
"true",
",",
"[",
"// version\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"INTEGER",
",",
"false",
",",
"asn1",
".",
"integerToDer",
"(",
"obj",
".",
"version",
")",
".",
"getBytes",
"(",
")",
")",
",",
"// issuerAndSerialNumber\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"SEQUENCE",
",",
"true",
",",
"[",
"// name\r",
"forge",
".",
"pki",
".",
"distinguishedNameToAsn1",
"(",
"{",
"attributes",
":",
"obj",
".",
"issuer",
"}",
")",
",",
"// serial\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"INTEGER",
",",
"false",
",",
"forge",
".",
"util",
".",
"hexToBytes",
"(",
"obj",
".",
"serialNumber",
")",
")",
"]",
")",
",",
"// digestAlgorithm\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"SEQUENCE",
",",
"true",
",",
"[",
"// algorithm\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"OID",
",",
"false",
",",
"asn1",
".",
"oidToDer",
"(",
"obj",
".",
"digestAlgorithm",
")",
".",
"getBytes",
"(",
")",
")",
",",
"// parameters (null)\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"NULL",
",",
"false",
",",
"''",
")",
"]",
")",
"]",
")",
";",
"// authenticatedAttributes (OPTIONAL)\r",
"if",
"(",
"obj",
".",
"authenticatedAttributesAsn1",
")",
"{",
"// add ASN.1 previously generated during signing\r",
"rval",
".",
"value",
".",
"push",
"(",
"obj",
".",
"authenticatedAttributesAsn1",
")",
";",
"}",
"// digestEncryptionAlgorithm\r",
"rval",
".",
"value",
".",
"push",
"(",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"SEQUENCE",
",",
"true",
",",
"[",
"// algorithm\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"OID",
",",
"false",
",",
"asn1",
".",
"oidToDer",
"(",
"obj",
".",
"signatureAlgorithm",
")",
".",
"getBytes",
"(",
")",
")",
",",
"// parameters (null)\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"NULL",
",",
"false",
",",
"''",
")",
"]",
")",
")",
";",
"// encryptedDigest\r",
"rval",
".",
"value",
".",
"push",
"(",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"OCTETSTRING",
",",
"false",
",",
"obj",
".",
"signature",
")",
")",
";",
"// unauthenticatedAttributes (OPTIONAL)\r",
"if",
"(",
"obj",
".",
"unauthenticatedAttributes",
".",
"length",
">",
"0",
")",
"{",
"// [1] IMPLICIT\r",
"var",
"attrsAsn1",
"=",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"CONTEXT_SPECIFIC",
",",
"1",
",",
"true",
",",
"[",
"]",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"obj",
".",
"unauthenticatedAttributes",
".",
"length",
";",
"++",
"i",
")",
"{",
"var",
"attr",
"=",
"obj",
".",
"unauthenticatedAttributes",
"[",
"i",
"]",
";",
"attrsAsn1",
".",
"values",
".",
"push",
"(",
"_attributeToAsn1",
"(",
"attr",
")",
")",
";",
"}",
"rval",
".",
"value",
".",
"push",
"(",
"attrsAsn1",
")",
";",
"}",
"return",
"rval",
";",
"}"
] |
Converts a single signerInfo object to an ASN.1 object.
@param obj the signerInfo object.
@return the ASN.1 representation of a SignerInfo.
|
[
"Converts",
"a",
"single",
"signerInfo",
"object",
"to",
"an",
"ASN",
".",
"1",
"object",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L28009-L28064
|
39,160 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
_signersFromAsn1
|
function _signersFromAsn1(signerInfoAsn1s) {
var ret = [];
for(var i = 0; i < signerInfoAsn1s.length; ++i) {
ret.push(_signerFromAsn1(signerInfoAsn1s[i]));
}
return ret;
}
|
javascript
|
function _signersFromAsn1(signerInfoAsn1s) {
var ret = [];
for(var i = 0; i < signerInfoAsn1s.length; ++i) {
ret.push(_signerFromAsn1(signerInfoAsn1s[i]));
}
return ret;
}
|
[
"function",
"_signersFromAsn1",
"(",
"signerInfoAsn1s",
")",
"{",
"var",
"ret",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"signerInfoAsn1s",
".",
"length",
";",
"++",
"i",
")",
"{",
"ret",
".",
"push",
"(",
"_signerFromAsn1",
"(",
"signerInfoAsn1s",
"[",
"i",
"]",
")",
")",
";",
"}",
"return",
"ret",
";",
"}"
] |
Map a set of SignerInfo ASN.1 objects to an array of signer objects.
@param signerInfoAsn1s an array of ASN.1 SignerInfos (i.e. SET OF).
@return an array of signers objects.
|
[
"Map",
"a",
"set",
"of",
"SignerInfo",
"ASN",
".",
"1",
"objects",
"to",
"an",
"array",
"of",
"signer",
"objects",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L28073-L28079
|
39,161 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
_signersToAsn1
|
function _signersToAsn1(signers) {
var ret = [];
for(var i = 0; i < signers.length; ++i) {
ret.push(_signerToAsn1(signers[i]));
}
return ret;
}
|
javascript
|
function _signersToAsn1(signers) {
var ret = [];
for(var i = 0; i < signers.length; ++i) {
ret.push(_signerToAsn1(signers[i]));
}
return ret;
}
|
[
"function",
"_signersToAsn1",
"(",
"signers",
")",
"{",
"var",
"ret",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"signers",
".",
"length",
";",
"++",
"i",
")",
"{",
"ret",
".",
"push",
"(",
"_signerToAsn1",
"(",
"signers",
"[",
"i",
"]",
")",
")",
";",
"}",
"return",
"ret",
";",
"}"
] |
Map an array of signer objects to ASN.1 objects.
@param signers an array of signer objects.
@return an array of ASN.1 SignerInfos.
|
[
"Map",
"an",
"array",
"of",
"signer",
"objects",
"to",
"ASN",
".",
"1",
"objects",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L28088-L28094
|
39,162 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
_attributeToAsn1
|
function _attributeToAsn1(attr) {
var value;
// TODO: generalize to support more attributes
if(attr.type === forge.pki.oids.contentType) {
value = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
asn1.oidToDer(attr.value).getBytes());
} else if(attr.type === forge.pki.oids.messageDigest) {
value = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false,
attr.value.bytes());
} else if(attr.type === forge.pki.oids.signingTime) {
/* Note per RFC 2985: Dates between 1 January 1950 and 31 December 2049
(inclusive) MUST be encoded as UTCTime. Any dates with year values
before 1950 or after 2049 MUST be encoded as GeneralizedTime. [Further,]
UTCTime values MUST be expressed in Greenwich Mean Time (Zulu) and MUST
include seconds (i.e., times are YYMMDDHHMMSSZ), even where the
number of seconds is zero. Midnight (GMT) must be represented as
"YYMMDD000000Z". */
// TODO: make these module-level constants
var jan_1_1950 = new Date('Jan 1, 1950 00:00:00Z');
var jan_1_2050 = new Date('Jan 1, 2050 00:00:00Z');
var date = attr.value;
if(typeof date === 'string') {
// try to parse date
var timestamp = Date.parse(date);
if(!isNaN(timestamp)) {
date = new Date(timestamp);
} else if(date.length === 13) {
// YYMMDDHHMMSSZ (13 chars for UTCTime)
date = asn1.utcTimeToDate(date);
} else {
// assume generalized time
date = asn1.generalizedTimeToDate(date);
}
}
if(date >= jan_1_1950 && date < jan_1_2050) {
value = asn1.create(
asn1.Class.UNIVERSAL, asn1.Type.UTCTIME, false,
asn1.dateToUtcTime(date));
} else {
value = asn1.create(
asn1.Class.UNIVERSAL, asn1.Type.GENERALIZEDTIME, false,
asn1.dateToGeneralizedTime(date));
}
}
// TODO: expose as common API call
// create a RelativeDistinguishedName set
// each value in the set is an AttributeTypeAndValue first
// containing the type (an OID) and second the value
return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
// AttributeType
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
asn1.oidToDer(attr.type).getBytes()),
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, [
// AttributeValue
value
])
]);
}
|
javascript
|
function _attributeToAsn1(attr) {
var value;
// TODO: generalize to support more attributes
if(attr.type === forge.pki.oids.contentType) {
value = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
asn1.oidToDer(attr.value).getBytes());
} else if(attr.type === forge.pki.oids.messageDigest) {
value = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false,
attr.value.bytes());
} else if(attr.type === forge.pki.oids.signingTime) {
/* Note per RFC 2985: Dates between 1 January 1950 and 31 December 2049
(inclusive) MUST be encoded as UTCTime. Any dates with year values
before 1950 or after 2049 MUST be encoded as GeneralizedTime. [Further,]
UTCTime values MUST be expressed in Greenwich Mean Time (Zulu) and MUST
include seconds (i.e., times are YYMMDDHHMMSSZ), even where the
number of seconds is zero. Midnight (GMT) must be represented as
"YYMMDD000000Z". */
// TODO: make these module-level constants
var jan_1_1950 = new Date('Jan 1, 1950 00:00:00Z');
var jan_1_2050 = new Date('Jan 1, 2050 00:00:00Z');
var date = attr.value;
if(typeof date === 'string') {
// try to parse date
var timestamp = Date.parse(date);
if(!isNaN(timestamp)) {
date = new Date(timestamp);
} else if(date.length === 13) {
// YYMMDDHHMMSSZ (13 chars for UTCTime)
date = asn1.utcTimeToDate(date);
} else {
// assume generalized time
date = asn1.generalizedTimeToDate(date);
}
}
if(date >= jan_1_1950 && date < jan_1_2050) {
value = asn1.create(
asn1.Class.UNIVERSAL, asn1.Type.UTCTIME, false,
asn1.dateToUtcTime(date));
} else {
value = asn1.create(
asn1.Class.UNIVERSAL, asn1.Type.GENERALIZEDTIME, false,
asn1.dateToGeneralizedTime(date));
}
}
// TODO: expose as common API call
// create a RelativeDistinguishedName set
// each value in the set is an AttributeTypeAndValue first
// containing the type (an OID) and second the value
return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
// AttributeType
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
asn1.oidToDer(attr.type).getBytes()),
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, [
// AttributeValue
value
])
]);
}
|
[
"function",
"_attributeToAsn1",
"(",
"attr",
")",
"{",
"var",
"value",
";",
"// TODO: generalize to support more attributes\r",
"if",
"(",
"attr",
".",
"type",
"===",
"forge",
".",
"pki",
".",
"oids",
".",
"contentType",
")",
"{",
"value",
"=",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"OID",
",",
"false",
",",
"asn1",
".",
"oidToDer",
"(",
"attr",
".",
"value",
")",
".",
"getBytes",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"attr",
".",
"type",
"===",
"forge",
".",
"pki",
".",
"oids",
".",
"messageDigest",
")",
"{",
"value",
"=",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"OCTETSTRING",
",",
"false",
",",
"attr",
".",
"value",
".",
"bytes",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"attr",
".",
"type",
"===",
"forge",
".",
"pki",
".",
"oids",
".",
"signingTime",
")",
"{",
"/* Note per RFC 2985: Dates between 1 January 1950 and 31 December 2049\r\n (inclusive) MUST be encoded as UTCTime. Any dates with year values\r\n before 1950 or after 2049 MUST be encoded as GeneralizedTime. [Further,]\r\n UTCTime values MUST be expressed in Greenwich Mean Time (Zulu) and MUST\r\n include seconds (i.e., times are YYMMDDHHMMSSZ), even where the\r\n number of seconds is zero. Midnight (GMT) must be represented as\r\n \"YYMMDD000000Z\". */",
"// TODO: make these module-level constants\r",
"var",
"jan_1_1950",
"=",
"new",
"Date",
"(",
"'Jan 1, 1950 00:00:00Z'",
")",
";",
"var",
"jan_1_2050",
"=",
"new",
"Date",
"(",
"'Jan 1, 2050 00:00:00Z'",
")",
";",
"var",
"date",
"=",
"attr",
".",
"value",
";",
"if",
"(",
"typeof",
"date",
"===",
"'string'",
")",
"{",
"// try to parse date\r",
"var",
"timestamp",
"=",
"Date",
".",
"parse",
"(",
"date",
")",
";",
"if",
"(",
"!",
"isNaN",
"(",
"timestamp",
")",
")",
"{",
"date",
"=",
"new",
"Date",
"(",
"timestamp",
")",
";",
"}",
"else",
"if",
"(",
"date",
".",
"length",
"===",
"13",
")",
"{",
"// YYMMDDHHMMSSZ (13 chars for UTCTime)\r",
"date",
"=",
"asn1",
".",
"utcTimeToDate",
"(",
"date",
")",
";",
"}",
"else",
"{",
"// assume generalized time\r",
"date",
"=",
"asn1",
".",
"generalizedTimeToDate",
"(",
"date",
")",
";",
"}",
"}",
"if",
"(",
"date",
">=",
"jan_1_1950",
"&&",
"date",
"<",
"jan_1_2050",
")",
"{",
"value",
"=",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"UTCTIME",
",",
"false",
",",
"asn1",
".",
"dateToUtcTime",
"(",
"date",
")",
")",
";",
"}",
"else",
"{",
"value",
"=",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"GENERALIZEDTIME",
",",
"false",
",",
"asn1",
".",
"dateToGeneralizedTime",
"(",
"date",
")",
")",
";",
"}",
"}",
"// TODO: expose as common API call\r",
"// create a RelativeDistinguishedName set\r",
"// each value in the set is an AttributeTypeAndValue first\r",
"// containing the type (an OID) and second the value\r",
"return",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"SEQUENCE",
",",
"true",
",",
"[",
"// AttributeType\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"OID",
",",
"false",
",",
"asn1",
".",
"oidToDer",
"(",
"attr",
".",
"type",
")",
".",
"getBytes",
"(",
")",
")",
",",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"SET",
",",
"true",
",",
"[",
"// AttributeValue\r",
"value",
"]",
")",
"]",
")",
";",
"}"
] |
Convert an attribute object to an ASN.1 Attribute.
@param attr the attribute object.
@return the ASN.1 Attribute.
|
[
"Convert",
"an",
"attribute",
"object",
"to",
"an",
"ASN",
".",
"1",
"Attribute",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L28103-L28163
|
39,163 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
_encryptedContentToAsn1
|
function _encryptedContentToAsn1(ec) {
return [
// ContentType, always Data for the moment
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
asn1.oidToDer(forge.pki.oids.data).getBytes()),
// ContentEncryptionAlgorithmIdentifier
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
// Algorithm
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
asn1.oidToDer(ec.algorithm).getBytes()),
// Parameters (IV)
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false,
ec.parameter.getBytes())
]),
// [0] EncryptedContent
asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false,
ec.content.getBytes())
])
];
}
|
javascript
|
function _encryptedContentToAsn1(ec) {
return [
// ContentType, always Data for the moment
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
asn1.oidToDer(forge.pki.oids.data).getBytes()),
// ContentEncryptionAlgorithmIdentifier
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
// Algorithm
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
asn1.oidToDer(ec.algorithm).getBytes()),
// Parameters (IV)
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false,
ec.parameter.getBytes())
]),
// [0] EncryptedContent
asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false,
ec.content.getBytes())
])
];
}
|
[
"function",
"_encryptedContentToAsn1",
"(",
"ec",
")",
"{",
"return",
"[",
"// ContentType, always Data for the moment\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"OID",
",",
"false",
",",
"asn1",
".",
"oidToDer",
"(",
"forge",
".",
"pki",
".",
"oids",
".",
"data",
")",
".",
"getBytes",
"(",
")",
")",
",",
"// ContentEncryptionAlgorithmIdentifier\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"SEQUENCE",
",",
"true",
",",
"[",
"// Algorithm\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"OID",
",",
"false",
",",
"asn1",
".",
"oidToDer",
"(",
"ec",
".",
"algorithm",
")",
".",
"getBytes",
"(",
")",
")",
",",
"// Parameters (IV)\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"OCTETSTRING",
",",
"false",
",",
"ec",
".",
"parameter",
".",
"getBytes",
"(",
")",
")",
"]",
")",
",",
"// [0] EncryptedContent\r",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"CONTEXT_SPECIFIC",
",",
"0",
",",
"true",
",",
"[",
"asn1",
".",
"create",
"(",
"asn1",
".",
"Class",
".",
"UNIVERSAL",
",",
"asn1",
".",
"Type",
".",
"OCTETSTRING",
",",
"false",
",",
"ec",
".",
"content",
".",
"getBytes",
"(",
")",
")",
"]",
")",
"]",
";",
"}"
] |
Map messages encrypted content to ASN.1 objects.
@param ec The encryptedContent object of the message.
@return ASN.1 representation of the encryptedContent object (SEQUENCE).
|
[
"Map",
"messages",
"encrypted",
"content",
"to",
"ASN",
".",
"1",
"objects",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L28172-L28192
|
39,164 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
_sha1
|
function _sha1() {
var sha = forge.md.sha1.create();
var num = arguments.length;
for (var i = 0; i < num; ++i) {
sha.update(arguments[i]);
}
return sha.digest();
}
|
javascript
|
function _sha1() {
var sha = forge.md.sha1.create();
var num = arguments.length;
for (var i = 0; i < num; ++i) {
sha.update(arguments[i]);
}
return sha.digest();
}
|
[
"function",
"_sha1",
"(",
")",
"{",
"var",
"sha",
"=",
"forge",
".",
"md",
".",
"sha1",
".",
"create",
"(",
")",
";",
"var",
"num",
"=",
"arguments",
".",
"length",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"num",
";",
"++",
"i",
")",
"{",
"sha",
".",
"update",
"(",
"arguments",
"[",
"i",
"]",
")",
";",
"}",
"return",
"sha",
".",
"digest",
"(",
")",
";",
"}"
] |
Hashes the arguments into one value using SHA-1.
@return the sha1 hash of the provided arguments.
|
[
"Hashes",
"the",
"arguments",
"into",
"one",
"value",
"using",
"SHA",
"-",
"1",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L28606-L28613
|
39,165 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
function(options) {
// task id
this.id = -1;
// task name
this.name = options.name || sNoTaskName;
// task has no parent
this.parent = options.parent || null;
// save run function
this.run = options.run;
// create a queue of subtasks to run
this.subtasks = [];
// error flag
this.error = false;
// state of the task
this.state = READY;
// number of times the task has been blocked (also the number
// of permits needed to be released to continue running)
this.blocks = 0;
// timeout id when sleeping
this.timeoutId = null;
// no swap time yet
this.swapTime = null;
// no user data
this.userData = null;
// initialize task
// FIXME: deal with overflow
this.id = sNextTaskId++;
sTasks[this.id] = this;
if(sVL >= 1) {
forge.log.verbose(cat, '[%s][%s] init', this.id, this.name, this);
}
}
|
javascript
|
function(options) {
// task id
this.id = -1;
// task name
this.name = options.name || sNoTaskName;
// task has no parent
this.parent = options.parent || null;
// save run function
this.run = options.run;
// create a queue of subtasks to run
this.subtasks = [];
// error flag
this.error = false;
// state of the task
this.state = READY;
// number of times the task has been blocked (also the number
// of permits needed to be released to continue running)
this.blocks = 0;
// timeout id when sleeping
this.timeoutId = null;
// no swap time yet
this.swapTime = null;
// no user data
this.userData = null;
// initialize task
// FIXME: deal with overflow
this.id = sNextTaskId++;
sTasks[this.id] = this;
if(sVL >= 1) {
forge.log.verbose(cat, '[%s][%s] init', this.id, this.name, this);
}
}
|
[
"function",
"(",
"options",
")",
"{",
"// task id\r",
"this",
".",
"id",
"=",
"-",
"1",
";",
"// task name\r",
"this",
".",
"name",
"=",
"options",
".",
"name",
"||",
"sNoTaskName",
";",
"// task has no parent\r",
"this",
".",
"parent",
"=",
"options",
".",
"parent",
"||",
"null",
";",
"// save run function\r",
"this",
".",
"run",
"=",
"options",
".",
"run",
";",
"// create a queue of subtasks to run\r",
"this",
".",
"subtasks",
"=",
"[",
"]",
";",
"// error flag\r",
"this",
".",
"error",
"=",
"false",
";",
"// state of the task\r",
"this",
".",
"state",
"=",
"READY",
";",
"// number of times the task has been blocked (also the number\r",
"// of permits needed to be released to continue running)\r",
"this",
".",
"blocks",
"=",
"0",
";",
"// timeout id when sleeping\r",
"this",
".",
"timeoutId",
"=",
"null",
";",
"// no swap time yet\r",
"this",
".",
"swapTime",
"=",
"null",
";",
"// no user data\r",
"this",
".",
"userData",
"=",
"null",
";",
"// initialize task\r",
"// FIXME: deal with overflow\r",
"this",
".",
"id",
"=",
"sNextTaskId",
"++",
";",
"sTasks",
"[",
"this",
".",
"id",
"]",
"=",
"this",
";",
"if",
"(",
"sVL",
">=",
"1",
")",
"{",
"forge",
".",
"log",
".",
"verbose",
"(",
"cat",
",",
"'[%s][%s] init'",
",",
"this",
".",
"id",
",",
"this",
".",
"name",
",",
"this",
")",
";",
"}",
"}"
] |
Creates a new task.
@param options options for this task
run: the run function for the task (required)
name: the run function for the task (optional)
parent: parent of this task (optional)
@return the empty task.
|
[
"Creates",
"a",
"new",
"task",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L28835-L28877
|
|
39,166 |
FelixMcFelix/conductor-chord
|
web_modules/forge.bundle.js
|
function(task) {
task.error = false;
task.state = sStateTable[task.state][START];
setTimeout(function() {
if(task.state === RUNNING) {
task.swapTime = +new Date();
task.run(task);
runNext(task, 0);
}
}, 0);
}
|
javascript
|
function(task) {
task.error = false;
task.state = sStateTable[task.state][START];
setTimeout(function() {
if(task.state === RUNNING) {
task.swapTime = +new Date();
task.run(task);
runNext(task, 0);
}
}, 0);
}
|
[
"function",
"(",
"task",
")",
"{",
"task",
".",
"error",
"=",
"false",
";",
"task",
".",
"state",
"=",
"sStateTable",
"[",
"task",
".",
"state",
"]",
"[",
"START",
"]",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"task",
".",
"state",
"===",
"RUNNING",
")",
"{",
"task",
".",
"swapTime",
"=",
"+",
"new",
"Date",
"(",
")",
";",
"task",
".",
"run",
"(",
"task",
")",
";",
"runNext",
"(",
"task",
",",
"0",
")",
";",
"}",
"}",
",",
"0",
")",
";",
"}"
] |
Asynchronously start a task.
@param task the task to start.
|
[
"Asynchronously",
"start",
"a",
"task",
"."
] |
f5326861a0754a0f43f4e8585275de271a969c4c
|
https://github.com/FelixMcFelix/conductor-chord/blob/f5326861a0754a0f43f4e8585275de271a969c4c/web_modules/forge.bundle.js#L29153-L29163
|
|
39,167 |
eface2face/jquery-meteor-blaze
|
gulpfile.js
|
bundle
|
function bundle() {
return browserify( config.inputDir + config.inputFile ).bundle()
.pipe(
source( config.outputFile )
)
.pipe(
rename( config.outputFile )
)
.pipe(
gulp.dest( config.outputDir ) // Create the .devel.js
)
.pipe(
streamify( jsmin() )
)
.pipe(
rename( config.outputFileMin )
)
.pipe(
gulp.dest( config.outputDir ) // Create the .min.js
)
.pipe(
streamify( gzip() )
)
.pipe(
rename( config.outputFileMinGz )
)
.pipe(
gulp.dest( config.outputDir ) // Create the .min.gz
);
}
|
javascript
|
function bundle() {
return browserify( config.inputDir + config.inputFile ).bundle()
.pipe(
source( config.outputFile )
)
.pipe(
rename( config.outputFile )
)
.pipe(
gulp.dest( config.outputDir ) // Create the .devel.js
)
.pipe(
streamify( jsmin() )
)
.pipe(
rename( config.outputFileMin )
)
.pipe(
gulp.dest( config.outputDir ) // Create the .min.js
)
.pipe(
streamify( gzip() )
)
.pipe(
rename( config.outputFileMinGz )
)
.pipe(
gulp.dest( config.outputDir ) // Create the .min.gz
);
}
|
[
"function",
"bundle",
"(",
")",
"{",
"return",
"browserify",
"(",
"config",
".",
"inputDir",
"+",
"config",
".",
"inputFile",
")",
".",
"bundle",
"(",
")",
".",
"pipe",
"(",
"source",
"(",
"config",
".",
"outputFile",
")",
")",
".",
"pipe",
"(",
"rename",
"(",
"config",
".",
"outputFile",
")",
")",
".",
"pipe",
"(",
"gulp",
".",
"dest",
"(",
"config",
".",
"outputDir",
")",
"// Create the .devel.js",
")",
".",
"pipe",
"(",
"streamify",
"(",
"jsmin",
"(",
")",
")",
")",
".",
"pipe",
"(",
"rename",
"(",
"config",
".",
"outputFileMin",
")",
")",
".",
"pipe",
"(",
"gulp",
".",
"dest",
"(",
"config",
".",
"outputDir",
")",
"// Create the .min.js",
")",
".",
"pipe",
"(",
"streamify",
"(",
"gzip",
"(",
")",
")",
")",
".",
"pipe",
"(",
"rename",
"(",
"config",
".",
"outputFileMinGz",
")",
")",
".",
"pipe",
"(",
"gulp",
".",
"dest",
"(",
"config",
".",
"outputDir",
")",
"// Create the .min.gz",
")",
";",
"}"
] |
Produce outfile, min, and gzip versions
|
[
"Produce",
"outfile",
"min",
"and",
"gzip",
"versions"
] |
5d8776cf8915622905d3c5ff1da1c3259e7eee24
|
https://github.com/eface2face/jquery-meteor-blaze/blob/5d8776cf8915622905d3c5ff1da1c3259e7eee24/gulpfile.js#L31-L60
|
39,168 |
IonicaBizau/node-gh-polyglot
|
lib/index.js
|
GhPolyglot
|
function GhPolyglot (input, token, host) {
var splits = input.split("/");
this.user = splits[0];
this.repo = splits[1];
this.full_name = input;
this.gh = new GitHub({ token: token, host: host });
}
|
javascript
|
function GhPolyglot (input, token, host) {
var splits = input.split("/");
this.user = splits[0];
this.repo = splits[1];
this.full_name = input;
this.gh = new GitHub({ token: token, host: host });
}
|
[
"function",
"GhPolyglot",
"(",
"input",
",",
"token",
",",
"host",
")",
"{",
"var",
"splits",
"=",
"input",
".",
"split",
"(",
"\"/\"",
")",
";",
"this",
".",
"user",
"=",
"splits",
"[",
"0",
"]",
";",
"this",
".",
"repo",
"=",
"splits",
"[",
"1",
"]",
";",
"this",
".",
"full_name",
"=",
"input",
";",
"this",
".",
"gh",
"=",
"new",
"GitHub",
"(",
"{",
"token",
":",
"token",
",",
"host",
":",
"host",
"}",
")",
";",
"}"
] |
GhPolyglot
Creates a new instance of `GhPolyglot`.
@name GhPolyglot
@function
@param {String} input The repository full name
(e.g. `"IonicaBizau/gh-polyglot"`) or the username (e.g. `"IonicaBizau"`).
@param {String} token An optional GitHub token used for making
authenticated requests.
@param {String} host An optional alternative Github FQDN (e.g. `"https://github.myenterprise.com/api/v3/"`)
@return {GhPolyglot} The `GhPolyglot` instance.
|
[
"GhPolyglot",
"Creates",
"a",
"new",
"instance",
"of",
"GhPolyglot",
"."
] |
1656b7a056bc57d6ab4c18cce68672dfb79baf8a
|
https://github.com/IonicaBizau/node-gh-polyglot/blob/1656b7a056bc57d6ab4c18cce68672dfb79baf8a/lib/index.js#L19-L25
|
39,169 |
hhdevelopment/boxes-scroll
|
src/boxesscroll.js
|
getInnerLimit
|
function getInnerLimit() {
var items = getItems();
var notInDeck = 0;
if (items.length) {
do {
notInDeck = notInDeck + 1;
var cont = false;
var item = items[items.length - notInDeck];
if (item) {
var area = getArea(item);
if (ctrl.horizontal) {
cont = area.right > getEltArea().right;
} else {
cont = area.bottom > getEltArea().bottom;
}
if (!cont) {
notInDeck--;
}
}
} while (cont);
} else {
notInDeck = 1;
}
var fix = ($scope.ngLimit - items.length) + notInDeck;
return $scope.max ? $scope.ngLimit : $scope.ngLimit - fix;
}
|
javascript
|
function getInnerLimit() {
var items = getItems();
var notInDeck = 0;
if (items.length) {
do {
notInDeck = notInDeck + 1;
var cont = false;
var item = items[items.length - notInDeck];
if (item) {
var area = getArea(item);
if (ctrl.horizontal) {
cont = area.right > getEltArea().right;
} else {
cont = area.bottom > getEltArea().bottom;
}
if (!cont) {
notInDeck--;
}
}
} while (cont);
} else {
notInDeck = 1;
}
var fix = ($scope.ngLimit - items.length) + notInDeck;
return $scope.max ? $scope.ngLimit : $scope.ngLimit - fix;
}
|
[
"function",
"getInnerLimit",
"(",
")",
"{",
"var",
"items",
"=",
"getItems",
"(",
")",
";",
"var",
"notInDeck",
"=",
"0",
";",
"if",
"(",
"items",
".",
"length",
")",
"{",
"do",
"{",
"notInDeck",
"=",
"notInDeck",
"+",
"1",
";",
"var",
"cont",
"=",
"false",
";",
"var",
"item",
"=",
"items",
"[",
"items",
".",
"length",
"-",
"notInDeck",
"]",
";",
"if",
"(",
"item",
")",
"{",
"var",
"area",
"=",
"getArea",
"(",
"item",
")",
";",
"if",
"(",
"ctrl",
".",
"horizontal",
")",
"{",
"cont",
"=",
"area",
".",
"right",
">",
"getEltArea",
"(",
")",
".",
"right",
";",
"}",
"else",
"{",
"cont",
"=",
"area",
".",
"bottom",
">",
"getEltArea",
"(",
")",
".",
"bottom",
";",
"}",
"if",
"(",
"!",
"cont",
")",
"{",
"notInDeck",
"--",
";",
"}",
"}",
"}",
"while",
"(",
"cont",
")",
";",
"}",
"else",
"{",
"notInDeck",
"=",
"1",
";",
"}",
"var",
"fix",
"=",
"(",
"$scope",
".",
"ngLimit",
"-",
"items",
".",
"length",
")",
"+",
"notInDeck",
";",
"return",
"$scope",
".",
"max",
"?",
"$scope",
".",
"ngLimit",
":",
"$scope",
".",
"ngLimit",
"-",
"fix",
";",
"}"
] |
Retourne la limit pour les calcul interne, cad le nombre d'items vraiment visible
@returns {Number|type.ngLimit|boxesscrollL#1.BoxScrollCtrl.$scope.ngLimit}
|
[
"Retourne",
"la",
"limit",
"pour",
"les",
"calcul",
"interne",
"cad",
"le",
"nombre",
"d",
"items",
"vraiment",
"visible"
] |
1d707715cbc25c35d9f30baaa95885cd36e0fec5
|
https://github.com/hhdevelopment/boxes-scroll/blob/1d707715cbc25c35d9f30baaa95885cd36e0fec5/src/boxesscroll.js#L89-L114
|
39,170 |
hhdevelopment/boxes-scroll
|
src/boxesscroll.js
|
addEventListeners
|
function addEventListeners() {
ctrl.ngelt.on('wheel', wheelOnElt);
ctrl.ngelt.on('computegrabbersizes', ctrl.updateSize);
// ctrl.elt.addEventListener("wheel", function (event) {
// boxesScrollServices.execAndApplyIfScrollable($scope, this, wheel, [event]);
// }, {passive: true, capture: true});
ctrl.ngsb.on("mouseout", mouseoutOnSb);
ctrl.ngsb.on("mousedown", mousedownOnSb); // sur le mousedown, si dans le grabber, on init le mode drag, sinon on inc/dec les pages tant que l'on est appuyé
ctrl.ngsb.on("mouseup", mouseup); // on stop l'inc/dec des pages
ctrl.ngsb.on("click", boxesScrollServices.stopEvent); // desactive la propagation entre autrepour eviter la fermeture des popup
ctrl.ngelt.on("mousemove", mousemoveOnElt); // on définit la couleur du grabber
if (!ctrl.ngelt.css('display') !== 'none') { // si c'est une popup, le resize de l'ecran ne joue pas
ng.element($window).on("resize", updateSize);
}
$document.on("mousedown", mousedownOnDoc);
$document.on("keydown", keydownOnOnDoc);
$document.on("scroll", invalidSizes);
}
|
javascript
|
function addEventListeners() {
ctrl.ngelt.on('wheel', wheelOnElt);
ctrl.ngelt.on('computegrabbersizes', ctrl.updateSize);
// ctrl.elt.addEventListener("wheel", function (event) {
// boxesScrollServices.execAndApplyIfScrollable($scope, this, wheel, [event]);
// }, {passive: true, capture: true});
ctrl.ngsb.on("mouseout", mouseoutOnSb);
ctrl.ngsb.on("mousedown", mousedownOnSb); // sur le mousedown, si dans le grabber, on init le mode drag, sinon on inc/dec les pages tant que l'on est appuyé
ctrl.ngsb.on("mouseup", mouseup); // on stop l'inc/dec des pages
ctrl.ngsb.on("click", boxesScrollServices.stopEvent); // desactive la propagation entre autrepour eviter la fermeture des popup
ctrl.ngelt.on("mousemove", mousemoveOnElt); // on définit la couleur du grabber
if (!ctrl.ngelt.css('display') !== 'none') { // si c'est une popup, le resize de l'ecran ne joue pas
ng.element($window).on("resize", updateSize);
}
$document.on("mousedown", mousedownOnDoc);
$document.on("keydown", keydownOnOnDoc);
$document.on("scroll", invalidSizes);
}
|
[
"function",
"addEventListeners",
"(",
")",
"{",
"ctrl",
".",
"ngelt",
".",
"on",
"(",
"'wheel'",
",",
"wheelOnElt",
")",
";",
"ctrl",
".",
"ngelt",
".",
"on",
"(",
"'computegrabbersizes'",
",",
"ctrl",
".",
"updateSize",
")",
";",
"//\t\t\tctrl.elt.addEventListener(\"wheel\", function (event) {",
"//\t\t\t\tboxesScrollServices.execAndApplyIfScrollable($scope, this, wheel, [event]);",
"//\t\t\t}, {passive: true, capture: true});",
"ctrl",
".",
"ngsb",
".",
"on",
"(",
"\"mouseout\"",
",",
"mouseoutOnSb",
")",
";",
"ctrl",
".",
"ngsb",
".",
"on",
"(",
"\"mousedown\"",
",",
"mousedownOnSb",
")",
";",
"// sur le mousedown, si dans le grabber, on init le mode drag, sinon on inc/dec les pages tant que l'on est appuyé",
"ctrl",
".",
"ngsb",
".",
"on",
"(",
"\"mouseup\"",
",",
"mouseup",
")",
";",
"// on stop l'inc/dec des pages",
"ctrl",
".",
"ngsb",
".",
"on",
"(",
"\"click\"",
",",
"boxesScrollServices",
".",
"stopEvent",
")",
";",
"// desactive la propagation entre autrepour eviter la fermeture des popup",
"ctrl",
".",
"ngelt",
".",
"on",
"(",
"\"mousemove\"",
",",
"mousemoveOnElt",
")",
";",
"// on définit la couleur du grabber",
"if",
"(",
"!",
"ctrl",
".",
"ngelt",
".",
"css",
"(",
"'display'",
")",
"!==",
"'none'",
")",
"{",
"// si c'est une popup, le resize de l'ecran ne joue pas",
"ng",
".",
"element",
"(",
"$window",
")",
".",
"on",
"(",
"\"resize\"",
",",
"updateSize",
")",
";",
"}",
"$document",
".",
"on",
"(",
"\"mousedown\"",
",",
"mousedownOnDoc",
")",
";",
"$document",
".",
"on",
"(",
"\"keydown\"",
",",
"keydownOnOnDoc",
")",
";",
"$document",
".",
"on",
"(",
"\"scroll\"",
",",
"invalidSizes",
")",
";",
"}"
] |
Ajoute et Supprime tous les handlers
|
[
"Ajoute",
"et",
"Supprime",
"tous",
"les",
"handlers"
] |
1d707715cbc25c35d9f30baaa95885cd36e0fec5
|
https://github.com/hhdevelopment/boxes-scroll/blob/1d707715cbc25c35d9f30baaa95885cd36e0fec5/src/boxesscroll.js#L119-L136
|
39,171 |
hhdevelopment/boxes-scroll
|
src/boxesscroll.js
|
keydown
|
function keydown(event) {
var inc = 0;
if (ctrl.horizontal) {
if (event.which === 37) { // LEFT
inc = -1;
} else if (event.which === 39) { // RIGHT
inc = 1;
}
} else {
var innerLimit = ctrl.getInnerLimit();
if (event.which === 38) { // UP
inc = -1;
} else if (event.which === 40) { // DOWN
inc = 1;
} else if (event.which === 33) { // PAGEUP
inc = -innerLimit;
} else if (event.which === 34) { // PAGEDOWN
inc = innerLimit;
} else if (event.which === 35) { // END
inc = $scope.total - $scope.ngBegin - innerLimit;
} else if (event.which === 36) { // HOME
inc = -$scope.ngBegin;
}
}
if (inc !== 0) {
boxesScrollServices.stopEvent(event);
$scope.ngBegin = $scope.ngBegin + inc;
}
}
|
javascript
|
function keydown(event) {
var inc = 0;
if (ctrl.horizontal) {
if (event.which === 37) { // LEFT
inc = -1;
} else if (event.which === 39) { // RIGHT
inc = 1;
}
} else {
var innerLimit = ctrl.getInnerLimit();
if (event.which === 38) { // UP
inc = -1;
} else if (event.which === 40) { // DOWN
inc = 1;
} else if (event.which === 33) { // PAGEUP
inc = -innerLimit;
} else if (event.which === 34) { // PAGEDOWN
inc = innerLimit;
} else if (event.which === 35) { // END
inc = $scope.total - $scope.ngBegin - innerLimit;
} else if (event.which === 36) { // HOME
inc = -$scope.ngBegin;
}
}
if (inc !== 0) {
boxesScrollServices.stopEvent(event);
$scope.ngBegin = $scope.ngBegin + inc;
}
}
|
[
"function",
"keydown",
"(",
"event",
")",
"{",
"var",
"inc",
"=",
"0",
";",
"if",
"(",
"ctrl",
".",
"horizontal",
")",
"{",
"if",
"(",
"event",
".",
"which",
"===",
"37",
")",
"{",
"// LEFT",
"inc",
"=",
"-",
"1",
";",
"}",
"else",
"if",
"(",
"event",
".",
"which",
"===",
"39",
")",
"{",
"// RIGHT",
"inc",
"=",
"1",
";",
"}",
"}",
"else",
"{",
"var",
"innerLimit",
"=",
"ctrl",
".",
"getInnerLimit",
"(",
")",
";",
"if",
"(",
"event",
".",
"which",
"===",
"38",
")",
"{",
"// UP",
"inc",
"=",
"-",
"1",
";",
"}",
"else",
"if",
"(",
"event",
".",
"which",
"===",
"40",
")",
"{",
"// DOWN",
"inc",
"=",
"1",
";",
"}",
"else",
"if",
"(",
"event",
".",
"which",
"===",
"33",
")",
"{",
"// PAGEUP",
"inc",
"=",
"-",
"innerLimit",
";",
"}",
"else",
"if",
"(",
"event",
".",
"which",
"===",
"34",
")",
"{",
"// PAGEDOWN",
"inc",
"=",
"innerLimit",
";",
"}",
"else",
"if",
"(",
"event",
".",
"which",
"===",
"35",
")",
"{",
"// END",
"inc",
"=",
"$scope",
".",
"total",
"-",
"$scope",
".",
"ngBegin",
"-",
"innerLimit",
";",
"}",
"else",
"if",
"(",
"event",
".",
"which",
"===",
"36",
")",
"{",
"// HOME",
"inc",
"=",
"-",
"$scope",
".",
"ngBegin",
";",
"}",
"}",
"if",
"(",
"inc",
"!==",
"0",
")",
"{",
"boxesScrollServices",
".",
"stopEvent",
"(",
"event",
")",
";",
"$scope",
".",
"ngBegin",
"=",
"$scope",
".",
"ngBegin",
"+",
"inc",
";",
"}",
"}"
] |
Gere la navigation clavier
@param {type} event
|
[
"Gere",
"la",
"navigation",
"clavier"
] |
1d707715cbc25c35d9f30baaa95885cd36e0fec5
|
https://github.com/hhdevelopment/boxes-scroll/blob/1d707715cbc25c35d9f30baaa95885cd36e0fec5/src/boxesscroll.js#L274-L302
|
39,172 |
hhdevelopment/boxes-scroll
|
src/boxesscroll.js
|
isScrollbarOver
|
function isScrollbarOver(m) {
return document.elementFromPoint(m.x, m.y) === ctrl.sb;
}
|
javascript
|
function isScrollbarOver(m) {
return document.elementFromPoint(m.x, m.y) === ctrl.sb;
}
|
[
"function",
"isScrollbarOver",
"(",
"m",
")",
"{",
"return",
"document",
".",
"elementFromPoint",
"(",
"m",
".",
"x",
",",
"m",
".",
"y",
")",
"===",
"ctrl",
".",
"sb",
";",
"}"
] |
La souris est elle au dessus de la scrollbar
@param {MouseCoordonates} m
@returns {Boolean}
|
[
"La",
"souris",
"est",
"elle",
"au",
"dessus",
"de",
"la",
"scrollbar"
] |
1d707715cbc25c35d9f30baaa95885cd36e0fec5
|
https://github.com/hhdevelopment/boxes-scroll/blob/1d707715cbc25c35d9f30baaa95885cd36e0fec5/src/boxesscroll.js#L436-L438
|
39,173 |
hhdevelopment/boxes-scroll
|
src/boxesscroll.js
|
updateGrabberSizes
|
function updateGrabberSizes() {
if (ctrl.horizontal !== undefined) {
var bgSizeElt = ctrl.ngelt.css('background-size');
var bgSizeSb = ctrl.ngsb.css('background-size');
var grabbersizePixel = '100%';
if(getInnerLimit() !== $scope.total) {
grabbersizePixel = getGrabberSizePixelFromPercent(getGrabberSizePercentFromScopeValues())+'px';
}
if (ctrl.horizontal) {
bgSizeElt = bgSizeElt.replace(/.*\s+/, grabbersizePixel + ' ');
bgSizeSb = bgSizeSb.replace(/.*\s+/, grabbersizePixel + ' ');
} else {
bgSizeElt = bgSizeElt.replace(/px\s+\d+(\.\d+)*.*/, 'px ' + grabbersizePixel);
bgSizeSb = bgSizeSb.replace(/px\s+\d+(\.\d+)*.*/, 'px ' + grabbersizePixel);
}
ctrl.ngelt.css({'background-size': bgSizeElt});
ctrl.ngsb.css({'background-size': bgSizeSb});
}
}
|
javascript
|
function updateGrabberSizes() {
if (ctrl.horizontal !== undefined) {
var bgSizeElt = ctrl.ngelt.css('background-size');
var bgSizeSb = ctrl.ngsb.css('background-size');
var grabbersizePixel = '100%';
if(getInnerLimit() !== $scope.total) {
grabbersizePixel = getGrabberSizePixelFromPercent(getGrabberSizePercentFromScopeValues())+'px';
}
if (ctrl.horizontal) {
bgSizeElt = bgSizeElt.replace(/.*\s+/, grabbersizePixel + ' ');
bgSizeSb = bgSizeSb.replace(/.*\s+/, grabbersizePixel + ' ');
} else {
bgSizeElt = bgSizeElt.replace(/px\s+\d+(\.\d+)*.*/, 'px ' + grabbersizePixel);
bgSizeSb = bgSizeSb.replace(/px\s+\d+(\.\d+)*.*/, 'px ' + grabbersizePixel);
}
ctrl.ngelt.css({'background-size': bgSizeElt});
ctrl.ngsb.css({'background-size': bgSizeSb});
}
}
|
[
"function",
"updateGrabberSizes",
"(",
")",
"{",
"if",
"(",
"ctrl",
".",
"horizontal",
"!==",
"undefined",
")",
"{",
"var",
"bgSizeElt",
"=",
"ctrl",
".",
"ngelt",
".",
"css",
"(",
"'background-size'",
")",
";",
"var",
"bgSizeSb",
"=",
"ctrl",
".",
"ngsb",
".",
"css",
"(",
"'background-size'",
")",
";",
"var",
"grabbersizePixel",
"=",
"'100%'",
";",
"if",
"(",
"getInnerLimit",
"(",
")",
"!==",
"$scope",
".",
"total",
")",
"{",
"grabbersizePixel",
"=",
"getGrabberSizePixelFromPercent",
"(",
"getGrabberSizePercentFromScopeValues",
"(",
")",
")",
"+",
"'px'",
";",
"}",
"if",
"(",
"ctrl",
".",
"horizontal",
")",
"{",
"bgSizeElt",
"=",
"bgSizeElt",
".",
"replace",
"(",
"/",
".*\\s+",
"/",
",",
"grabbersizePixel",
"+",
"' '",
")",
";",
"bgSizeSb",
"=",
"bgSizeSb",
".",
"replace",
"(",
"/",
".*\\s+",
"/",
",",
"grabbersizePixel",
"+",
"' '",
")",
";",
"}",
"else",
"{",
"bgSizeElt",
"=",
"bgSizeElt",
".",
"replace",
"(",
"/",
"px\\s+\\d+(\\.\\d+)*.*",
"/",
",",
"'px '",
"+",
"grabbersizePixel",
")",
";",
"bgSizeSb",
"=",
"bgSizeSb",
".",
"replace",
"(",
"/",
"px\\s+\\d+(\\.\\d+)*.*",
"/",
",",
"'px '",
"+",
"grabbersizePixel",
")",
";",
"}",
"ctrl",
".",
"ngelt",
".",
"css",
"(",
"{",
"'background-size'",
":",
"bgSizeElt",
"}",
")",
";",
"ctrl",
".",
"ngsb",
".",
"css",
"(",
"{",
"'background-size'",
":",
"bgSizeSb",
"}",
")",
";",
"}",
"}"
] |
Calcul la taille des grabbers
|
[
"Calcul",
"la",
"taille",
"des",
"grabbers"
] |
1d707715cbc25c35d9f30baaa95885cd36e0fec5
|
https://github.com/hhdevelopment/boxes-scroll/blob/1d707715cbc25c35d9f30baaa95885cd36e0fec5/src/boxesscroll.js#L564-L584
|
39,174 |
hhdevelopment/boxes-scroll
|
src/boxesscroll.js
|
getGrabberOffsetPixelFromPercent
|
function getGrabberOffsetPixelFromPercent(percentOffset) {
var sbLenght = getHeightArea(); // Longueur de la scrollbar
var grabberOffsetPixel = sbLenght * percentOffset / 100;
return Math.max(grabberOffsetPixel, 0);
}
|
javascript
|
function getGrabberOffsetPixelFromPercent(percentOffset) {
var sbLenght = getHeightArea(); // Longueur de la scrollbar
var grabberOffsetPixel = sbLenght * percentOffset / 100;
return Math.max(grabberOffsetPixel, 0);
}
|
[
"function",
"getGrabberOffsetPixelFromPercent",
"(",
"percentOffset",
")",
"{",
"var",
"sbLenght",
"=",
"getHeightArea",
"(",
")",
";",
"// Longueur de la scrollbar",
"var",
"grabberOffsetPixel",
"=",
"sbLenght",
"*",
"percentOffset",
"/",
"100",
";",
"return",
"Math",
".",
"max",
"(",
"grabberOffsetPixel",
",",
"0",
")",
";",
"}"
] |
Calcul la position du curseur en px
@param {type} percentOffset
@returns {Number}
|
[
"Calcul",
"la",
"position",
"du",
"curseur",
"en",
"px"
] |
1d707715cbc25c35d9f30baaa95885cd36e0fec5
|
https://github.com/hhdevelopment/boxes-scroll/blob/1d707715cbc25c35d9f30baaa95885cd36e0fec5/src/boxesscroll.js#L620-L624
|
39,175 |
hhdevelopment/boxes-scroll
|
src/boxesscroll.js
|
getOffsetPixelContainerBeforeItem
|
function getOffsetPixelContainerBeforeItem(item) {
if (ctrl.horizontal) {
return getArea(item).left - getEltArea().left;
} else {
return getArea(item).top - getEltArea().top;
}
}
|
javascript
|
function getOffsetPixelContainerBeforeItem(item) {
if (ctrl.horizontal) {
return getArea(item).left - getEltArea().left;
} else {
return getArea(item).top - getEltArea().top;
}
}
|
[
"function",
"getOffsetPixelContainerBeforeItem",
"(",
"item",
")",
"{",
"if",
"(",
"ctrl",
".",
"horizontal",
")",
"{",
"return",
"getArea",
"(",
"item",
")",
".",
"left",
"-",
"getEltArea",
"(",
")",
".",
"left",
";",
"}",
"else",
"{",
"return",
"getArea",
"(",
"item",
")",
".",
"top",
"-",
"getEltArea",
"(",
")",
".",
"top",
";",
"}",
"}"
] |
Retourne l'offset en pixel avant l'item
Typiquement la taille du header dans un tableau
@param {HtmlElement} item
@returns {number}
|
[
"Retourne",
"l",
"offset",
"en",
"pixel",
"avant",
"l",
"item",
"Typiquement",
"la",
"taille",
"du",
"header",
"dans",
"un",
"tableau"
] |
1d707715cbc25c35d9f30baaa95885cd36e0fec5
|
https://github.com/hhdevelopment/boxes-scroll/blob/1d707715cbc25c35d9f30baaa95885cd36e0fec5/src/boxesscroll.js#L649-L655
|
39,176 |
mattidupre/gulp-retinize
|
retinize.js
|
function(file, enc, cb) {
if (
!file.isNull() &&
!file.isDirectory() &&
options.extensions.some(function(ext) {
return path.extname(file.path).substr(1).toLowerCase() === ext;
})
) {
file = retina.tapFile(file, cb);
} else {
cb();
}
// Push only if file is returned by retina (otherwise it is dropped from stream)
if (file) this.push(file);
}
|
javascript
|
function(file, enc, cb) {
if (
!file.isNull() &&
!file.isDirectory() &&
options.extensions.some(function(ext) {
return path.extname(file.path).substr(1).toLowerCase() === ext;
})
) {
file = retina.tapFile(file, cb);
} else {
cb();
}
// Push only if file is returned by retina (otherwise it is dropped from stream)
if (file) this.push(file);
}
|
[
"function",
"(",
"file",
",",
"enc",
",",
"cb",
")",
"{",
"if",
"(",
"!",
"file",
".",
"isNull",
"(",
")",
"&&",
"!",
"file",
".",
"isDirectory",
"(",
")",
"&&",
"options",
".",
"extensions",
".",
"some",
"(",
"function",
"(",
"ext",
")",
"{",
"return",
"path",
".",
"extname",
"(",
"file",
".",
"path",
")",
".",
"substr",
"(",
"1",
")",
".",
"toLowerCase",
"(",
")",
"===",
"ext",
";",
"}",
")",
")",
"{",
"file",
"=",
"retina",
".",
"tapFile",
"(",
"file",
",",
"cb",
")",
";",
"}",
"else",
"{",
"cb",
"(",
")",
";",
"}",
"// Push only if file is returned by retina (otherwise it is dropped from stream)",
"if",
"(",
"file",
")",
"this",
".",
"push",
"(",
"file",
")",
";",
"}"
] |
Transform function filters image files
|
[
"Transform",
"function",
"filters",
"image",
"files"
] |
f804f01d80d8f240dc41fc6c656e2bca09b1fb46
|
https://github.com/mattidupre/gulp-retinize/blob/f804f01d80d8f240dc41fc6c656e2bca09b1fb46/retinize.js#L37-L51
|
|
39,177 |
amritk/gulp-angular2-embed-sass
|
index.js
|
joinParts
|
function joinParts(entrances) {
var parts = [];
parts.push(Buffer(content.substring(0, matches.index)));
parts.push(Buffer('styles: [`'));
for (var i=0; i<entrances.length; i++) {
parts.push(Buffer(entrances[i].replace(/\n/g, '')));
if (i < entrances.length - 1) {
parts.push(Buffer('`, `'));
}
}
parts.push(Buffer('`]'));
parts.push(Buffer(content.substr(matches.index + matches[0].length)));
return Buffer.concat(parts);
}
|
javascript
|
function joinParts(entrances) {
var parts = [];
parts.push(Buffer(content.substring(0, matches.index)));
parts.push(Buffer('styles: [`'));
for (var i=0; i<entrances.length; i++) {
parts.push(Buffer(entrances[i].replace(/\n/g, '')));
if (i < entrances.length - 1) {
parts.push(Buffer('`, `'));
}
}
parts.push(Buffer('`]'));
parts.push(Buffer(content.substr(matches.index + matches[0].length)));
return Buffer.concat(parts);
}
|
[
"function",
"joinParts",
"(",
"entrances",
")",
"{",
"var",
"parts",
"=",
"[",
"]",
";",
"parts",
".",
"push",
"(",
"Buffer",
"(",
"content",
".",
"substring",
"(",
"0",
",",
"matches",
".",
"index",
")",
")",
")",
";",
"parts",
".",
"push",
"(",
"Buffer",
"(",
"'styles: [`'",
")",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"entrances",
".",
"length",
";",
"i",
"++",
")",
"{",
"parts",
".",
"push",
"(",
"Buffer",
"(",
"entrances",
"[",
"i",
"]",
".",
"replace",
"(",
"/",
"\\n",
"/",
"g",
",",
"''",
")",
")",
")",
";",
"if",
"(",
"i",
"<",
"entrances",
".",
"length",
"-",
"1",
")",
"{",
"parts",
".",
"push",
"(",
"Buffer",
"(",
"'`, `'",
")",
")",
";",
"}",
"}",
"parts",
".",
"push",
"(",
"Buffer",
"(",
"'`]'",
")",
")",
";",
"parts",
".",
"push",
"(",
"Buffer",
"(",
"content",
".",
"substr",
"(",
"matches",
".",
"index",
"+",
"matches",
"[",
"0",
"]",
".",
"length",
")",
")",
")",
";",
"return",
"Buffer",
".",
"concat",
"(",
"parts",
")",
";",
"}"
] |
Writes the new css strings to the file buffer
|
[
"Writes",
"the",
"new",
"css",
"strings",
"to",
"the",
"file",
"buffer"
] |
4e50499ea49b4a6178c1e87535c9f006877a7a65
|
https://github.com/amritk/gulp-angular2-embed-sass/blob/4e50499ea49b4a6178c1e87535c9f006877a7a65/index.js#L110-L125
|
39,178 |
solid/contacts-pane
|
contactsPane.js
|
function (subject) {
var t = kb.findTypeURIs(subject)
if (t[ns.vcard('Individual').uri]) return 'Contact'
if (t[ns.vcard('Organization').uri]) return 'contact'
if (t[ns.foaf('Person').uri]) return 'Person'
if (t[ns.schema('Person').uri]) return 'Person'
if (t[ns.vcard('Group').uri]) return 'Group'
if (t[ns.vcard('AddressBook').uri]) return 'Address book'
return null // No under other circumstances
}
|
javascript
|
function (subject) {
var t = kb.findTypeURIs(subject)
if (t[ns.vcard('Individual').uri]) return 'Contact'
if (t[ns.vcard('Organization').uri]) return 'contact'
if (t[ns.foaf('Person').uri]) return 'Person'
if (t[ns.schema('Person').uri]) return 'Person'
if (t[ns.vcard('Group').uri]) return 'Group'
if (t[ns.vcard('AddressBook').uri]) return 'Address book'
return null // No under other circumstances
}
|
[
"function",
"(",
"subject",
")",
"{",
"var",
"t",
"=",
"kb",
".",
"findTypeURIs",
"(",
"subject",
")",
"if",
"(",
"t",
"[",
"ns",
".",
"vcard",
"(",
"'Individual'",
")",
".",
"uri",
"]",
")",
"return",
"'Contact'",
"if",
"(",
"t",
"[",
"ns",
".",
"vcard",
"(",
"'Organization'",
")",
".",
"uri",
"]",
")",
"return",
"'contact'",
"if",
"(",
"t",
"[",
"ns",
".",
"foaf",
"(",
"'Person'",
")",
".",
"uri",
"]",
")",
"return",
"'Person'",
"if",
"(",
"t",
"[",
"ns",
".",
"schema",
"(",
"'Person'",
")",
".",
"uri",
"]",
")",
"return",
"'Person'",
"if",
"(",
"t",
"[",
"ns",
".",
"vcard",
"(",
"'Group'",
")",
".",
"uri",
"]",
")",
"return",
"'Group'",
"if",
"(",
"t",
"[",
"ns",
".",
"vcard",
"(",
"'AddressBook'",
")",
".",
"uri",
"]",
")",
"return",
"'Address book'",
"return",
"null",
"// No under other circumstances",
"}"
] |
Does the subject deserve an contact pane?
|
[
"Does",
"the",
"subject",
"deserve",
"an",
"contact",
"pane?"
] |
373c55fc6e2c584603741ee972d036fcb1e2f4b8
|
https://github.com/solid/contacts-pane/blob/373c55fc6e2c584603741ee972d036fcb1e2f4b8/contactsPane.js#L34-L43
|
|
39,179 |
solid/contacts-pane
|
contactsPane.js
|
function (books, context, options) {
kb.fetcher.load(books).then(function (xhr) {
renderThreeColumnBrowser2(books, context, options)
}).catch(function (err) { complain(err) })
}
|
javascript
|
function (books, context, options) {
kb.fetcher.load(books).then(function (xhr) {
renderThreeColumnBrowser2(books, context, options)
}).catch(function (err) { complain(err) })
}
|
[
"function",
"(",
"books",
",",
"context",
",",
"options",
")",
"{",
"kb",
".",
"fetcher",
".",
"load",
"(",
"books",
")",
".",
"then",
"(",
"function",
"(",
"xhr",
")",
"{",
"renderThreeColumnBrowser2",
"(",
"books",
",",
"context",
",",
"options",
")",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"complain",
"(",
"err",
")",
"}",
")",
"}"
] |
Render a 3-column browser for an address book or a group
|
[
"Render",
"a",
"3",
"-",
"column",
"browser",
"for",
"an",
"address",
"book",
"or",
"a",
"group"
] |
373c55fc6e2c584603741ee972d036fcb1e2f4b8
|
https://github.com/solid/contacts-pane/blob/373c55fc6e2c584603741ee972d036fcb1e2f4b8/contactsPane.js#L227-L231
|
|
39,180 |
solid/contacts-pane
|
contactsPane.js
|
findBookFromGroups
|
function findBookFromGroups (book) {
if (book) {
return book
}
var g
for (let gu in selectedGroups) {
g = kb.sym(gu)
let b = kb.any(undefined, ns.vcard('includesGroup'), g)
if (b) return b
}
throw new Error('findBookFromGroups: Cant find address book which this group is part of')
}
|
javascript
|
function findBookFromGroups (book) {
if (book) {
return book
}
var g
for (let gu in selectedGroups) {
g = kb.sym(gu)
let b = kb.any(undefined, ns.vcard('includesGroup'), g)
if (b) return b
}
throw new Error('findBookFromGroups: Cant find address book which this group is part of')
}
|
[
"function",
"findBookFromGroups",
"(",
"book",
")",
"{",
"if",
"(",
"book",
")",
"{",
"return",
"book",
"}",
"var",
"g",
"for",
"(",
"let",
"gu",
"in",
"selectedGroups",
")",
"{",
"g",
"=",
"kb",
".",
"sym",
"(",
"gu",
")",
"let",
"b",
"=",
"kb",
".",
"any",
"(",
"undefined",
",",
"ns",
".",
"vcard",
"(",
"'includesGroup'",
")",
",",
"g",
")",
"if",
"(",
"b",
")",
"return",
"b",
"}",
"throw",
"new",
"Error",
"(",
"'findBookFromGroups: Cant find address book which this group is part of'",
")",
"}"
] |
The book could be the main subject, or linked from a group we are dealing with
|
[
"The",
"book",
"could",
"be",
"the",
"main",
"subject",
"or",
"linked",
"from",
"a",
"group",
"we",
"are",
"dealing",
"with"
] |
373c55fc6e2c584603741ee972d036fcb1e2f4b8
|
https://github.com/solid/contacts-pane/blob/373c55fc6e2c584603741ee972d036fcb1e2f4b8/contactsPane.js#L250-L261
|
39,181 |
solid/contacts-pane
|
contactsPane.js
|
function (book, name, selectedGroups, callbackFunction) {
book = findBookFromGroups(book)
var nameEmailIndex = kb.any(book, ns.vcard('nameEmailIndex'))
var uuid = UI.utils.genUuid()
var person = kb.sym(book.dir().uri + 'Person/' + uuid + '/index.ttl#this')
var doc = person.doc()
// Sets of statements to different files
var agenda = [ // Patch the main index to add the person
[ $rdf.st(person, ns.vcard('inAddressBook'), book, nameEmailIndex), // The people index
$rdf.st(person, ns.vcard('fn'), name, nameEmailIndex) ]
]
// @@ May be missing email - sync that differently
// sts.push(new $rdf.Statement(person, DCT('created'), new Date(), doc)); ??? include this?
for (var gu in selectedGroups) {
var g = kb.sym(gu)
var gd = g.doc()
agenda.push([ $rdf.st(g, ns.vcard('hasMember'), person, gd),
$rdf.st(person, ns.vcard('fn'), name, gd)
])
}
var updateCallback = function (uri, success, body) {
if (!success) {
console.log("Error: can't update " + uri + ' for new contact:' + body + '\n')
callbackFunction(false, "Error: can't update " + uri + ' for new contact:' + body)
} else {
if (agenda.length > 0) {
console.log('Patching ' + agenda[0] + '\n')
updater.update([], agenda.shift(), updateCallback)
} else { // done!
console.log('Done patching. Now reading back in.\n')
UI.store.fetcher.nowOrWhenFetched(doc, undefined, function (ok, body) {
if (ok) {
console.log('Read back in OK.\n')
callbackFunction(true, person)
} else {
console.log('Read back in FAILED: ' + body + '\n')
callbackFunction(false, body)
}
})
}
}
}
UI.store.fetcher.nowOrWhenFetched(nameEmailIndex, undefined, function (ok, message) {
if (ok) {
console.log(' People index must be loaded\n')
updater.put(doc, [
$rdf.st(person, ns.vcard('fn'), name, doc),
$rdf.st(person, ns.rdf('type'), ns.vcard('Individual'), doc) ],
'text/turtle', updateCallback)
} else {
console.log('Error loading people index!' + nameEmailIndex.uri + ': ' + message)
callbackFunction(false, 'Error loading people index!' + nameEmailIndex.uri + ': ' + message + '\n')
}
})
}
|
javascript
|
function (book, name, selectedGroups, callbackFunction) {
book = findBookFromGroups(book)
var nameEmailIndex = kb.any(book, ns.vcard('nameEmailIndex'))
var uuid = UI.utils.genUuid()
var person = kb.sym(book.dir().uri + 'Person/' + uuid + '/index.ttl#this')
var doc = person.doc()
// Sets of statements to different files
var agenda = [ // Patch the main index to add the person
[ $rdf.st(person, ns.vcard('inAddressBook'), book, nameEmailIndex), // The people index
$rdf.st(person, ns.vcard('fn'), name, nameEmailIndex) ]
]
// @@ May be missing email - sync that differently
// sts.push(new $rdf.Statement(person, DCT('created'), new Date(), doc)); ??? include this?
for (var gu in selectedGroups) {
var g = kb.sym(gu)
var gd = g.doc()
agenda.push([ $rdf.st(g, ns.vcard('hasMember'), person, gd),
$rdf.st(person, ns.vcard('fn'), name, gd)
])
}
var updateCallback = function (uri, success, body) {
if (!success) {
console.log("Error: can't update " + uri + ' for new contact:' + body + '\n')
callbackFunction(false, "Error: can't update " + uri + ' for new contact:' + body)
} else {
if (agenda.length > 0) {
console.log('Patching ' + agenda[0] + '\n')
updater.update([], agenda.shift(), updateCallback)
} else { // done!
console.log('Done patching. Now reading back in.\n')
UI.store.fetcher.nowOrWhenFetched(doc, undefined, function (ok, body) {
if (ok) {
console.log('Read back in OK.\n')
callbackFunction(true, person)
} else {
console.log('Read back in FAILED: ' + body + '\n')
callbackFunction(false, body)
}
})
}
}
}
UI.store.fetcher.nowOrWhenFetched(nameEmailIndex, undefined, function (ok, message) {
if (ok) {
console.log(' People index must be loaded\n')
updater.put(doc, [
$rdf.st(person, ns.vcard('fn'), name, doc),
$rdf.st(person, ns.rdf('type'), ns.vcard('Individual'), doc) ],
'text/turtle', updateCallback)
} else {
console.log('Error loading people index!' + nameEmailIndex.uri + ': ' + message)
callbackFunction(false, 'Error loading people index!' + nameEmailIndex.uri + ': ' + message + '\n')
}
})
}
|
[
"function",
"(",
"book",
",",
"name",
",",
"selectedGroups",
",",
"callbackFunction",
")",
"{",
"book",
"=",
"findBookFromGroups",
"(",
"book",
")",
"var",
"nameEmailIndex",
"=",
"kb",
".",
"any",
"(",
"book",
",",
"ns",
".",
"vcard",
"(",
"'nameEmailIndex'",
")",
")",
"var",
"uuid",
"=",
"UI",
".",
"utils",
".",
"genUuid",
"(",
")",
"var",
"person",
"=",
"kb",
".",
"sym",
"(",
"book",
".",
"dir",
"(",
")",
".",
"uri",
"+",
"'Person/'",
"+",
"uuid",
"+",
"'/index.ttl#this'",
")",
"var",
"doc",
"=",
"person",
".",
"doc",
"(",
")",
"// Sets of statements to different files",
"var",
"agenda",
"=",
"[",
"// Patch the main index to add the person",
"[",
"$rdf",
".",
"st",
"(",
"person",
",",
"ns",
".",
"vcard",
"(",
"'inAddressBook'",
")",
",",
"book",
",",
"nameEmailIndex",
")",
",",
"// The people index",
"$rdf",
".",
"st",
"(",
"person",
",",
"ns",
".",
"vcard",
"(",
"'fn'",
")",
",",
"name",
",",
"nameEmailIndex",
")",
"]",
"]",
"// @@ May be missing email - sync that differently",
"// sts.push(new $rdf.Statement(person, DCT('created'), new Date(), doc)); ??? include this?",
"for",
"(",
"var",
"gu",
"in",
"selectedGroups",
")",
"{",
"var",
"g",
"=",
"kb",
".",
"sym",
"(",
"gu",
")",
"var",
"gd",
"=",
"g",
".",
"doc",
"(",
")",
"agenda",
".",
"push",
"(",
"[",
"$rdf",
".",
"st",
"(",
"g",
",",
"ns",
".",
"vcard",
"(",
"'hasMember'",
")",
",",
"person",
",",
"gd",
")",
",",
"$rdf",
".",
"st",
"(",
"person",
",",
"ns",
".",
"vcard",
"(",
"'fn'",
")",
",",
"name",
",",
"gd",
")",
"]",
")",
"}",
"var",
"updateCallback",
"=",
"function",
"(",
"uri",
",",
"success",
",",
"body",
")",
"{",
"if",
"(",
"!",
"success",
")",
"{",
"console",
".",
"log",
"(",
"\"Error: can't update \"",
"+",
"uri",
"+",
"' for new contact:'",
"+",
"body",
"+",
"'\\n'",
")",
"callbackFunction",
"(",
"false",
",",
"\"Error: can't update \"",
"+",
"uri",
"+",
"' for new contact:'",
"+",
"body",
")",
"}",
"else",
"{",
"if",
"(",
"agenda",
".",
"length",
">",
"0",
")",
"{",
"console",
".",
"log",
"(",
"'Patching '",
"+",
"agenda",
"[",
"0",
"]",
"+",
"'\\n'",
")",
"updater",
".",
"update",
"(",
"[",
"]",
",",
"agenda",
".",
"shift",
"(",
")",
",",
"updateCallback",
")",
"}",
"else",
"{",
"// done!",
"console",
".",
"log",
"(",
"'Done patching. Now reading back in.\\n'",
")",
"UI",
".",
"store",
".",
"fetcher",
".",
"nowOrWhenFetched",
"(",
"doc",
",",
"undefined",
",",
"function",
"(",
"ok",
",",
"body",
")",
"{",
"if",
"(",
"ok",
")",
"{",
"console",
".",
"log",
"(",
"'Read back in OK.\\n'",
")",
"callbackFunction",
"(",
"true",
",",
"person",
")",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"'Read back in FAILED: '",
"+",
"body",
"+",
"'\\n'",
")",
"callbackFunction",
"(",
"false",
",",
"body",
")",
"}",
"}",
")",
"}",
"}",
"}",
"UI",
".",
"store",
".",
"fetcher",
".",
"nowOrWhenFetched",
"(",
"nameEmailIndex",
",",
"undefined",
",",
"function",
"(",
"ok",
",",
"message",
")",
"{",
"if",
"(",
"ok",
")",
"{",
"console",
".",
"log",
"(",
"' People index must be loaded\\n'",
")",
"updater",
".",
"put",
"(",
"doc",
",",
"[",
"$rdf",
".",
"st",
"(",
"person",
",",
"ns",
".",
"vcard",
"(",
"'fn'",
")",
",",
"name",
",",
"doc",
")",
",",
"$rdf",
".",
"st",
"(",
"person",
",",
"ns",
".",
"rdf",
"(",
"'type'",
")",
",",
"ns",
".",
"vcard",
"(",
"'Individual'",
")",
",",
"doc",
")",
"]",
",",
"'text/turtle'",
",",
"updateCallback",
")",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"'Error loading people index!'",
"+",
"nameEmailIndex",
".",
"uri",
"+",
"': '",
"+",
"message",
")",
"callbackFunction",
"(",
"false",
",",
"'Error loading people index!'",
"+",
"nameEmailIndex",
".",
"uri",
"+",
"': '",
"+",
"message",
"+",
"'\\n'",
")",
"}",
"}",
")",
"}"
] |
Write a new contact to the web
|
[
"Write",
"a",
"new",
"contact",
"to",
"the",
"web"
] |
373c55fc6e2c584603741ee972d036fcb1e2f4b8
|
https://github.com/solid/contacts-pane/blob/373c55fc6e2c584603741ee972d036fcb1e2f4b8/contactsPane.js#L264-L324
|
|
39,182 |
solid/contacts-pane
|
contactsPane.js
|
function (book, name, callbackFunction) {
var gix = kb.any(book, ns.vcard('groupIndex'))
var x = book.uri.split('#')[0]
var gname = name.replace(' ', '_')
var doc = kb.sym(x.slice(0, x.lastIndexOf('/') + 1) + 'Group/' + gname + '.ttl')
var group = kb.sym(doc.uri + '#this')
console.log(' New group will be: ' + group + '\n')
UI.store.fetcher.nowOrWhenFetched(gix, function (ok, message) {
if (ok) {
console.log(' Group index must be loaded\n')
var insertTriples = [
$rdf.st(book, ns.vcard('includesGroup'), group, gix),
$rdf.st(group, ns.rdf('type'), ns.vcard('Group'), gix),
$rdf.st(group, ns.vcard('fn'), name, gix)
]
updater.update([], insertTriples, function (uri, success, body) {
if (ok) {
var triples = [
$rdf.st(book, ns.vcard('includesGroup'), group, gix), // Pointer back to book
$rdf.st(group, ns.rdf('type'), ns.vcard('Group'), doc),
$rdf.st(group, ns.vcard('fn'), name, doc)
]
updater.put(doc, triples, 'text/turtle', function (uri, ok, body) {
callbackFunction(ok, ok ? group : "Can't save new group file " + doc + body)
})
} else {
callbackFunction(ok, 'Could not update group index ' + body) // fail
}
})
} else {
console.log('Error loading people index!' + gix.uri + ': ' + message)
callbackFunction(false, 'Error loading people index!' + gix.uri + ': ' + message + '\n')
}
})
}
|
javascript
|
function (book, name, callbackFunction) {
var gix = kb.any(book, ns.vcard('groupIndex'))
var x = book.uri.split('#')[0]
var gname = name.replace(' ', '_')
var doc = kb.sym(x.slice(0, x.lastIndexOf('/') + 1) + 'Group/' + gname + '.ttl')
var group = kb.sym(doc.uri + '#this')
console.log(' New group will be: ' + group + '\n')
UI.store.fetcher.nowOrWhenFetched(gix, function (ok, message) {
if (ok) {
console.log(' Group index must be loaded\n')
var insertTriples = [
$rdf.st(book, ns.vcard('includesGroup'), group, gix),
$rdf.st(group, ns.rdf('type'), ns.vcard('Group'), gix),
$rdf.st(group, ns.vcard('fn'), name, gix)
]
updater.update([], insertTriples, function (uri, success, body) {
if (ok) {
var triples = [
$rdf.st(book, ns.vcard('includesGroup'), group, gix), // Pointer back to book
$rdf.st(group, ns.rdf('type'), ns.vcard('Group'), doc),
$rdf.st(group, ns.vcard('fn'), name, doc)
]
updater.put(doc, triples, 'text/turtle', function (uri, ok, body) {
callbackFunction(ok, ok ? group : "Can't save new group file " + doc + body)
})
} else {
callbackFunction(ok, 'Could not update group index ' + body) // fail
}
})
} else {
console.log('Error loading people index!' + gix.uri + ': ' + message)
callbackFunction(false, 'Error loading people index!' + gix.uri + ': ' + message + '\n')
}
})
}
|
[
"function",
"(",
"book",
",",
"name",
",",
"callbackFunction",
")",
"{",
"var",
"gix",
"=",
"kb",
".",
"any",
"(",
"book",
",",
"ns",
".",
"vcard",
"(",
"'groupIndex'",
")",
")",
"var",
"x",
"=",
"book",
".",
"uri",
".",
"split",
"(",
"'#'",
")",
"[",
"0",
"]",
"var",
"gname",
"=",
"name",
".",
"replace",
"(",
"' '",
",",
"'_'",
")",
"var",
"doc",
"=",
"kb",
".",
"sym",
"(",
"x",
".",
"slice",
"(",
"0",
",",
"x",
".",
"lastIndexOf",
"(",
"'/'",
")",
"+",
"1",
")",
"+",
"'Group/'",
"+",
"gname",
"+",
"'.ttl'",
")",
"var",
"group",
"=",
"kb",
".",
"sym",
"(",
"doc",
".",
"uri",
"+",
"'#this'",
")",
"console",
".",
"log",
"(",
"' New group will be: '",
"+",
"group",
"+",
"'\\n'",
")",
"UI",
".",
"store",
".",
"fetcher",
".",
"nowOrWhenFetched",
"(",
"gix",
",",
"function",
"(",
"ok",
",",
"message",
")",
"{",
"if",
"(",
"ok",
")",
"{",
"console",
".",
"log",
"(",
"' Group index must be loaded\\n'",
")",
"var",
"insertTriples",
"=",
"[",
"$rdf",
".",
"st",
"(",
"book",
",",
"ns",
".",
"vcard",
"(",
"'includesGroup'",
")",
",",
"group",
",",
"gix",
")",
",",
"$rdf",
".",
"st",
"(",
"group",
",",
"ns",
".",
"rdf",
"(",
"'type'",
")",
",",
"ns",
".",
"vcard",
"(",
"'Group'",
")",
",",
"gix",
")",
",",
"$rdf",
".",
"st",
"(",
"group",
",",
"ns",
".",
"vcard",
"(",
"'fn'",
")",
",",
"name",
",",
"gix",
")",
"]",
"updater",
".",
"update",
"(",
"[",
"]",
",",
"insertTriples",
",",
"function",
"(",
"uri",
",",
"success",
",",
"body",
")",
"{",
"if",
"(",
"ok",
")",
"{",
"var",
"triples",
"=",
"[",
"$rdf",
".",
"st",
"(",
"book",
",",
"ns",
".",
"vcard",
"(",
"'includesGroup'",
")",
",",
"group",
",",
"gix",
")",
",",
"// Pointer back to book",
"$rdf",
".",
"st",
"(",
"group",
",",
"ns",
".",
"rdf",
"(",
"'type'",
")",
",",
"ns",
".",
"vcard",
"(",
"'Group'",
")",
",",
"doc",
")",
",",
"$rdf",
".",
"st",
"(",
"group",
",",
"ns",
".",
"vcard",
"(",
"'fn'",
")",
",",
"name",
",",
"doc",
")",
"]",
"updater",
".",
"put",
"(",
"doc",
",",
"triples",
",",
"'text/turtle'",
",",
"function",
"(",
"uri",
",",
"ok",
",",
"body",
")",
"{",
"callbackFunction",
"(",
"ok",
",",
"ok",
"?",
"group",
":",
"\"Can't save new group file \"",
"+",
"doc",
"+",
"body",
")",
"}",
")",
"}",
"else",
"{",
"callbackFunction",
"(",
"ok",
",",
"'Could not update group index '",
"+",
"body",
")",
"// fail",
"}",
"}",
")",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"'Error loading people index!'",
"+",
"gix",
".",
"uri",
"+",
"': '",
"+",
"message",
")",
"callbackFunction",
"(",
"false",
",",
"'Error loading people index!'",
"+",
"gix",
".",
"uri",
"+",
"': '",
"+",
"message",
"+",
"'\\n'",
")",
"}",
"}",
")",
"}"
] |
Write new group to web Creates an empty new group file and adds it to the index
|
[
"Write",
"new",
"group",
"to",
"web",
"Creates",
"an",
"empty",
"new",
"group",
"file",
"and",
"adds",
"it",
"to",
"the",
"index"
] |
373c55fc6e2c584603741ee972d036fcb1e2f4b8
|
https://github.com/solid/contacts-pane/blob/373c55fc6e2c584603741ee972d036fcb1e2f4b8/contactsPane.js#L329-L366
|
|
39,183 |
solid/contacts-pane
|
contactsPane.js
|
function (x) {
var name = kb.any(x, ns.vcard('fn')) ||
kb.any(x, ns.foaf('name')) || kb.any(x, ns.vcard('organization-name'))
return name ? name.value : '???'
}
|
javascript
|
function (x) {
var name = kb.any(x, ns.vcard('fn')) ||
kb.any(x, ns.foaf('name')) || kb.any(x, ns.vcard('organization-name'))
return name ? name.value : '???'
}
|
[
"function",
"(",
"x",
")",
"{",
"var",
"name",
"=",
"kb",
".",
"any",
"(",
"x",
",",
"ns",
".",
"vcard",
"(",
"'fn'",
")",
")",
"||",
"kb",
".",
"any",
"(",
"x",
",",
"ns",
".",
"foaf",
"(",
"'name'",
")",
")",
"||",
"kb",
".",
"any",
"(",
"x",
",",
"ns",
".",
"vcard",
"(",
"'organization-name'",
")",
")",
"return",
"name",
"?",
"name",
".",
"value",
":",
"'???'",
"}"
] |
organization-name is a hack for Mac records with no FN which is mandatory.
|
[
"organization",
"-",
"name",
"is",
"a",
"hack",
"for",
"Mac",
"records",
"with",
"no",
"FN",
"which",
"is",
"mandatory",
"."
] |
373c55fc6e2c584603741ee972d036fcb1e2f4b8
|
https://github.com/solid/contacts-pane/blob/373c55fc6e2c584603741ee972d036fcb1e2f4b8/contactsPane.js#L369-L373
|
|
39,184 |
solid/contacts-pane
|
contactsPane.js
|
deleteThing
|
function deleteThing (x) {
console.log('deleteThing: ' + x)
var ds = kb.statementsMatching(x).concat(kb.statementsMatching(undefined, undefined, x))
var targets = {}
ds.map(function (st) { targets[st.why.uri] = st })
var agenda = [] // sets of statements of same dcoument to delete
for (var target in targets) {
agenda.push(ds.filter(function (st) { return st.why.uri === target }))
console.log(' Deleting ' + agenda[agenda.length - 1].length + ' triples from ' + target)
}
function nextOne () {
if (agenda.length > 0) {
updater.update(agenda.shift(), [], function (uri, ok, body) {
if (!ok) {
complain('Error deleting all trace of: ' + x + ': ' + body)
return
}
nextOne()
})
} else {
console.log('Deleting resoure ' + x.doc())
kb.fetcher.delete(x.doc())
.then(function () {
console.log('Delete thing ' + x + ': complete.')
})
.catch(function (e) {
complain('Error deleting thing ' + x + ': ' + e)
})
}
}
nextOne()
}
|
javascript
|
function deleteThing (x) {
console.log('deleteThing: ' + x)
var ds = kb.statementsMatching(x).concat(kb.statementsMatching(undefined, undefined, x))
var targets = {}
ds.map(function (st) { targets[st.why.uri] = st })
var agenda = [] // sets of statements of same dcoument to delete
for (var target in targets) {
agenda.push(ds.filter(function (st) { return st.why.uri === target }))
console.log(' Deleting ' + agenda[agenda.length - 1].length + ' triples from ' + target)
}
function nextOne () {
if (agenda.length > 0) {
updater.update(agenda.shift(), [], function (uri, ok, body) {
if (!ok) {
complain('Error deleting all trace of: ' + x + ': ' + body)
return
}
nextOne()
})
} else {
console.log('Deleting resoure ' + x.doc())
kb.fetcher.delete(x.doc())
.then(function () {
console.log('Delete thing ' + x + ': complete.')
})
.catch(function (e) {
complain('Error deleting thing ' + x + ': ' + e)
})
}
}
nextOne()
}
|
[
"function",
"deleteThing",
"(",
"x",
")",
"{",
"console",
".",
"log",
"(",
"'deleteThing: '",
"+",
"x",
")",
"var",
"ds",
"=",
"kb",
".",
"statementsMatching",
"(",
"x",
")",
".",
"concat",
"(",
"kb",
".",
"statementsMatching",
"(",
"undefined",
",",
"undefined",
",",
"x",
")",
")",
"var",
"targets",
"=",
"{",
"}",
"ds",
".",
"map",
"(",
"function",
"(",
"st",
")",
"{",
"targets",
"[",
"st",
".",
"why",
".",
"uri",
"]",
"=",
"st",
"}",
")",
"var",
"agenda",
"=",
"[",
"]",
"// sets of statements of same dcoument to delete",
"for",
"(",
"var",
"target",
"in",
"targets",
")",
"{",
"agenda",
".",
"push",
"(",
"ds",
".",
"filter",
"(",
"function",
"(",
"st",
")",
"{",
"return",
"st",
".",
"why",
".",
"uri",
"===",
"target",
"}",
")",
")",
"console",
".",
"log",
"(",
"' Deleting '",
"+",
"agenda",
"[",
"agenda",
".",
"length",
"-",
"1",
"]",
".",
"length",
"+",
"' triples from '",
"+",
"target",
")",
"}",
"function",
"nextOne",
"(",
")",
"{",
"if",
"(",
"agenda",
".",
"length",
">",
"0",
")",
"{",
"updater",
".",
"update",
"(",
"agenda",
".",
"shift",
"(",
")",
",",
"[",
"]",
",",
"function",
"(",
"uri",
",",
"ok",
",",
"body",
")",
"{",
"if",
"(",
"!",
"ok",
")",
"{",
"complain",
"(",
"'Error deleting all trace of: '",
"+",
"x",
"+",
"': '",
"+",
"body",
")",
"return",
"}",
"nextOne",
"(",
")",
"}",
")",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"'Deleting resoure '",
"+",
"x",
".",
"doc",
"(",
")",
")",
"kb",
".",
"fetcher",
".",
"delete",
"(",
"x",
".",
"doc",
"(",
")",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"console",
".",
"log",
"(",
"'Delete thing '",
"+",
"x",
"+",
"': complete.'",
")",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"e",
")",
"{",
"complain",
"(",
"'Error deleting thing '",
"+",
"x",
"+",
"': '",
"+",
"e",
")",
"}",
")",
"}",
"}",
"nextOne",
"(",
")",
"}"
] |
In a LDP work, deletes the whole document describing a thing plus patch out ALL mentiosn of it! Use with care! beware of other dta picked up from other places being smushed together and then deleted.
|
[
"In",
"a",
"LDP",
"work",
"deletes",
"the",
"whole",
"document",
"describing",
"a",
"thing",
"plus",
"patch",
"out",
"ALL",
"mentiosn",
"of",
"it!",
"Use",
"with",
"care!",
"beware",
"of",
"other",
"dta",
"picked",
"up",
"from",
"other",
"places",
"being",
"smushed",
"together",
"and",
"then",
"deleted",
"."
] |
373c55fc6e2c584603741ee972d036fcb1e2f4b8
|
https://github.com/solid/contacts-pane/blob/373c55fc6e2c584603741ee972d036fcb1e2f4b8/contactsPane.js#L517-L548
|
39,185 |
solid/contacts-pane
|
contactsPane.js
|
deleteRecursive
|
function deleteRecursive (kb, folder) {
return new Promise(function (resolve, reject) {
kb.fetcher.load(folder).then(function () {
let promises = kb.each(folder, ns.ldp('contains')).map(file => {
if (kb.holds(file, ns.rdf('type'), ns.ldp('BasicContainer'))) {
return deleteRecursive(kb, file)
} else {
console.log('deleteRecirsive file: ' + file)
if (!confirm(' Really DELETE File ' + file)) {
throw new Error('User aborted delete file')
}
return kb.fetcher.webOperation('DELETE', file.uri)
}
})
console.log('deleteRecirsive folder: ' + folder)
if (!confirm(' Really DELETE folder ' + folder)) {
throw new Error('User aborted delete file')
}
promises.push(kb.fetcher.webOperation('DELETE', folder.uri))
Promise.all(promises).then(res => { resolve() })
})
})
}
|
javascript
|
function deleteRecursive (kb, folder) {
return new Promise(function (resolve, reject) {
kb.fetcher.load(folder).then(function () {
let promises = kb.each(folder, ns.ldp('contains')).map(file => {
if (kb.holds(file, ns.rdf('type'), ns.ldp('BasicContainer'))) {
return deleteRecursive(kb, file)
} else {
console.log('deleteRecirsive file: ' + file)
if (!confirm(' Really DELETE File ' + file)) {
throw new Error('User aborted delete file')
}
return kb.fetcher.webOperation('DELETE', file.uri)
}
})
console.log('deleteRecirsive folder: ' + folder)
if (!confirm(' Really DELETE folder ' + folder)) {
throw new Error('User aborted delete file')
}
promises.push(kb.fetcher.webOperation('DELETE', folder.uri))
Promise.all(promises).then(res => { resolve() })
})
})
}
|
[
"function",
"deleteRecursive",
"(",
"kb",
",",
"folder",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"kb",
".",
"fetcher",
".",
"load",
"(",
"folder",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"let",
"promises",
"=",
"kb",
".",
"each",
"(",
"folder",
",",
"ns",
".",
"ldp",
"(",
"'contains'",
")",
")",
".",
"map",
"(",
"file",
"=>",
"{",
"if",
"(",
"kb",
".",
"holds",
"(",
"file",
",",
"ns",
".",
"rdf",
"(",
"'type'",
")",
",",
"ns",
".",
"ldp",
"(",
"'BasicContainer'",
")",
")",
")",
"{",
"return",
"deleteRecursive",
"(",
"kb",
",",
"file",
")",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"'deleteRecirsive file: '",
"+",
"file",
")",
"if",
"(",
"!",
"confirm",
"(",
"' Really DELETE File '",
"+",
"file",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'User aborted delete file'",
")",
"}",
"return",
"kb",
".",
"fetcher",
".",
"webOperation",
"(",
"'DELETE'",
",",
"file",
".",
"uri",
")",
"}",
"}",
")",
"console",
".",
"log",
"(",
"'deleteRecirsive folder: '",
"+",
"folder",
")",
"if",
"(",
"!",
"confirm",
"(",
"' Really DELETE folder '",
"+",
"folder",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'User aborted delete file'",
")",
"}",
"promises",
".",
"push",
"(",
"kb",
".",
"fetcher",
".",
"webOperation",
"(",
"'DELETE'",
",",
"folder",
".",
"uri",
")",
")",
"Promise",
".",
"all",
"(",
"promises",
")",
".",
"then",
"(",
"res",
"=>",
"{",
"resolve",
"(",
")",
"}",
")",
"}",
")",
"}",
")",
"}"
] |
For deleting an addressbook sub-folder eg person - use with care!
|
[
"For",
"deleting",
"an",
"addressbook",
"sub",
"-",
"folder",
"eg",
"person",
"-",
"use",
"with",
"care!"
] |
373c55fc6e2c584603741ee972d036fcb1e2f4b8
|
https://github.com/solid/contacts-pane/blob/373c55fc6e2c584603741ee972d036fcb1e2f4b8/contactsPane.js#L552-L574
|
39,186 |
solid/contacts-pane
|
contactsPane.js
|
function (uris) {
uris.forEach(function (u) {
console.log('Dropped on group: ' + u)
var thing = kb.sym(u)
var toBeFetched = [thing.doc(), group.doc()]
kb.fetcher.load(toBeFetched).then(function (xhrs) {
var types = kb.findTypeURIs(thing)
for (var ty in types) {
console.log(' drop object type includes: ' + ty) // @@ Allow email addresses and phone numbers to be dropped?
}
if (ns.vcard('Individual').uri in types || ns.vcard('Organization').uri in types) {
var pname = kb.any(thing, ns.vcard('fn'))
if (!pname) return alert('No vcard name known for ' + thing)
var already = kb.holds(group, ns.vcard('hasMember'), thing, group.doc())
if (already) return alert('ALREADY added ' + pname + ' to group ' + name)
var message = 'Add ' + pname + ' to group ' + name + '?'
if (confirm(message)) {
var ins = [ $rdf.st(group, ns.vcard('hasMember'), thing, group.doc()),
$rdf.st(thing, ns.vcard('fn'), pname, group.doc())]
kb.updater.update([], ins, function (uri, ok, err) {
if (!ok) return complain('Error adding member to group ' + group + ': ' + err)
console.log('Added ' + pname + ' to group ' + name)
// @@ refresh UI
})
}
}
}).catch(function (e) {
complain('Error looking up dropped thing ' + thing + ' and group: ' + e)
})
})
}
|
javascript
|
function (uris) {
uris.forEach(function (u) {
console.log('Dropped on group: ' + u)
var thing = kb.sym(u)
var toBeFetched = [thing.doc(), group.doc()]
kb.fetcher.load(toBeFetched).then(function (xhrs) {
var types = kb.findTypeURIs(thing)
for (var ty in types) {
console.log(' drop object type includes: ' + ty) // @@ Allow email addresses and phone numbers to be dropped?
}
if (ns.vcard('Individual').uri in types || ns.vcard('Organization').uri in types) {
var pname = kb.any(thing, ns.vcard('fn'))
if (!pname) return alert('No vcard name known for ' + thing)
var already = kb.holds(group, ns.vcard('hasMember'), thing, group.doc())
if (already) return alert('ALREADY added ' + pname + ' to group ' + name)
var message = 'Add ' + pname + ' to group ' + name + '?'
if (confirm(message)) {
var ins = [ $rdf.st(group, ns.vcard('hasMember'), thing, group.doc()),
$rdf.st(thing, ns.vcard('fn'), pname, group.doc())]
kb.updater.update([], ins, function (uri, ok, err) {
if (!ok) return complain('Error adding member to group ' + group + ': ' + err)
console.log('Added ' + pname + ' to group ' + name)
// @@ refresh UI
})
}
}
}).catch(function (e) {
complain('Error looking up dropped thing ' + thing + ' and group: ' + e)
})
})
}
|
[
"function",
"(",
"uris",
")",
"{",
"uris",
".",
"forEach",
"(",
"function",
"(",
"u",
")",
"{",
"console",
".",
"log",
"(",
"'Dropped on group: '",
"+",
"u",
")",
"var",
"thing",
"=",
"kb",
".",
"sym",
"(",
"u",
")",
"var",
"toBeFetched",
"=",
"[",
"thing",
".",
"doc",
"(",
")",
",",
"group",
".",
"doc",
"(",
")",
"]",
"kb",
".",
"fetcher",
".",
"load",
"(",
"toBeFetched",
")",
".",
"then",
"(",
"function",
"(",
"xhrs",
")",
"{",
"var",
"types",
"=",
"kb",
".",
"findTypeURIs",
"(",
"thing",
")",
"for",
"(",
"var",
"ty",
"in",
"types",
")",
"{",
"console",
".",
"log",
"(",
"' drop object type includes: '",
"+",
"ty",
")",
"// @@ Allow email addresses and phone numbers to be dropped?",
"}",
"if",
"(",
"ns",
".",
"vcard",
"(",
"'Individual'",
")",
".",
"uri",
"in",
"types",
"||",
"ns",
".",
"vcard",
"(",
"'Organization'",
")",
".",
"uri",
"in",
"types",
")",
"{",
"var",
"pname",
"=",
"kb",
".",
"any",
"(",
"thing",
",",
"ns",
".",
"vcard",
"(",
"'fn'",
")",
")",
"if",
"(",
"!",
"pname",
")",
"return",
"alert",
"(",
"'No vcard name known for '",
"+",
"thing",
")",
"var",
"already",
"=",
"kb",
".",
"holds",
"(",
"group",
",",
"ns",
".",
"vcard",
"(",
"'hasMember'",
")",
",",
"thing",
",",
"group",
".",
"doc",
"(",
")",
")",
"if",
"(",
"already",
")",
"return",
"alert",
"(",
"'ALREADY added '",
"+",
"pname",
"+",
"' to group '",
"+",
"name",
")",
"var",
"message",
"=",
"'Add '",
"+",
"pname",
"+",
"' to group '",
"+",
"name",
"+",
"'?'",
"if",
"(",
"confirm",
"(",
"message",
")",
")",
"{",
"var",
"ins",
"=",
"[",
"$rdf",
".",
"st",
"(",
"group",
",",
"ns",
".",
"vcard",
"(",
"'hasMember'",
")",
",",
"thing",
",",
"group",
".",
"doc",
"(",
")",
")",
",",
"$rdf",
".",
"st",
"(",
"thing",
",",
"ns",
".",
"vcard",
"(",
"'fn'",
")",
",",
"pname",
",",
"group",
".",
"doc",
"(",
")",
")",
"]",
"kb",
".",
"updater",
".",
"update",
"(",
"[",
"]",
",",
"ins",
",",
"function",
"(",
"uri",
",",
"ok",
",",
"err",
")",
"{",
"if",
"(",
"!",
"ok",
")",
"return",
"complain",
"(",
"'Error adding member to group '",
"+",
"group",
"+",
"': '",
"+",
"err",
")",
"console",
".",
"log",
"(",
"'Added '",
"+",
"pname",
"+",
"' to group '",
"+",
"name",
")",
"// @@ refresh UI",
"}",
")",
"}",
"}",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"e",
")",
"{",
"complain",
"(",
"'Error looking up dropped thing '",
"+",
"thing",
"+",
"' and group: '",
"+",
"e",
")",
"}",
")",
"}",
")",
"}"
] |
Is something is dropped on a group, add people to group
|
[
"Is",
"something",
"is",
"dropped",
"on",
"a",
"group",
"add",
"people",
"to",
"group"
] |
373c55fc6e2c584603741ee972d036fcb1e2f4b8
|
https://github.com/solid/contacts-pane/blob/373c55fc6e2c584603741ee972d036fcb1e2f4b8/contactsPane.js#L688-L719
|
|
39,187 |
solid/contacts-pane
|
contactsPane.js
|
function (uris) {
uris.map(function (u) {
var thing = $rdf.sym(u) // Attachment needs text label to disinguish I think not icon.
console.log('Dropped on mugshot thing ' + thing) // icon was: UI.icons.iconBase + 'noun_25830.svg'
if (u.startsWith('http') && u.indexOf('#') < 0) { // Plain document
// Take a copy of a photo on the web:
kb.fetcher.webOperation('GET', thing.uri).then(result => {
let contentType = result.headers.get('Content-Type')
// let data = result.responseText
let pathEnd = thing.uri.split('/').slice(-1)[0] // last segment as putative filename
pathEnd = pathEnd.split('?')[0] // chop off any query params
result.arrayBuffer().then(function (data) { // read text stream
if (!result.ok) {
complain('Error downloading ' + thing + ':' + result.status)
return
}
uploadFileToContact(pathEnd, contentType, data)
})
})
return
} else {
console.log('Not a web document URI, cannot copy as picture: ' + thing)
}
handleDroppedThing(thing)
})
}
|
javascript
|
function (uris) {
uris.map(function (u) {
var thing = $rdf.sym(u) // Attachment needs text label to disinguish I think not icon.
console.log('Dropped on mugshot thing ' + thing) // icon was: UI.icons.iconBase + 'noun_25830.svg'
if (u.startsWith('http') && u.indexOf('#') < 0) { // Plain document
// Take a copy of a photo on the web:
kb.fetcher.webOperation('GET', thing.uri).then(result => {
let contentType = result.headers.get('Content-Type')
// let data = result.responseText
let pathEnd = thing.uri.split('/').slice(-1)[0] // last segment as putative filename
pathEnd = pathEnd.split('?')[0] // chop off any query params
result.arrayBuffer().then(function (data) { // read text stream
if (!result.ok) {
complain('Error downloading ' + thing + ':' + result.status)
return
}
uploadFileToContact(pathEnd, contentType, data)
})
})
return
} else {
console.log('Not a web document URI, cannot copy as picture: ' + thing)
}
handleDroppedThing(thing)
})
}
|
[
"function",
"(",
"uris",
")",
"{",
"uris",
".",
"map",
"(",
"function",
"(",
"u",
")",
"{",
"var",
"thing",
"=",
"$rdf",
".",
"sym",
"(",
"u",
")",
"// Attachment needs text label to disinguish I think not icon.",
"console",
".",
"log",
"(",
"'Dropped on mugshot thing '",
"+",
"thing",
")",
"// icon was: UI.icons.iconBase + 'noun_25830.svg'",
"if",
"(",
"u",
".",
"startsWith",
"(",
"'http'",
")",
"&&",
"u",
".",
"indexOf",
"(",
"'#'",
")",
"<",
"0",
")",
"{",
"// Plain document",
"// Take a copy of a photo on the web:",
"kb",
".",
"fetcher",
".",
"webOperation",
"(",
"'GET'",
",",
"thing",
".",
"uri",
")",
".",
"then",
"(",
"result",
"=>",
"{",
"let",
"contentType",
"=",
"result",
".",
"headers",
".",
"get",
"(",
"'Content-Type'",
")",
"// let data = result.responseText",
"let",
"pathEnd",
"=",
"thing",
".",
"uri",
".",
"split",
"(",
"'/'",
")",
".",
"slice",
"(",
"-",
"1",
")",
"[",
"0",
"]",
"// last segment as putative filename",
"pathEnd",
"=",
"pathEnd",
".",
"split",
"(",
"'?'",
")",
"[",
"0",
"]",
"// chop off any query params",
"result",
".",
"arrayBuffer",
"(",
")",
".",
"then",
"(",
"function",
"(",
"data",
")",
"{",
"// read text stream",
"if",
"(",
"!",
"result",
".",
"ok",
")",
"{",
"complain",
"(",
"'Error downloading '",
"+",
"thing",
"+",
"':'",
"+",
"result",
".",
"status",
")",
"return",
"}",
"uploadFileToContact",
"(",
"pathEnd",
",",
"contentType",
",",
"data",
")",
"}",
")",
"}",
")",
"return",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"'Not a web document URI, cannot copy as picture: '",
"+",
"thing",
")",
"}",
"handleDroppedThing",
"(",
"thing",
")",
"}",
")",
"}"
] |
When a set of URIs are dropped on
|
[
"When",
"a",
"set",
"of",
"URIs",
"are",
"dropped",
"on"
] |
373c55fc6e2c584603741ee972d036fcb1e2f4b8
|
https://github.com/solid/contacts-pane/blob/373c55fc6e2c584603741ee972d036fcb1e2f4b8/contactsPane.js#L1050-L1075
|
|
39,188 |
solid/contacts-pane
|
contactsPane.js
|
function (files) {
for (var i = 0; i < files.length; i++) {
let f = files[i]
console.log(' meeting: Filename: ' + f.name + ', type: ' + (f.type || 'n/a') +
' size: ' + f.size + ' bytes, last modified: ' +
(f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : 'n/a')
) // See e.g. https://www.html5rocks.com/en/tutorials/file/dndfiles/
// @@ Add: progress bar(s)
var reader = new FileReader()
reader.onload = (function (theFile) {
return function (e) {
var data = e.target.result
console.log(' File read byteLength : ' + data.byteLength)
var filename = encodeURIComponent(theFile.name)
var contentType = theFile.type
uploadFileToContact(filename, contentType, data)
}
})(f)
reader.readAsArrayBuffer(f)
}
}
|
javascript
|
function (files) {
for (var i = 0; i < files.length; i++) {
let f = files[i]
console.log(' meeting: Filename: ' + f.name + ', type: ' + (f.type || 'n/a') +
' size: ' + f.size + ' bytes, last modified: ' +
(f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : 'n/a')
) // See e.g. https://www.html5rocks.com/en/tutorials/file/dndfiles/
// @@ Add: progress bar(s)
var reader = new FileReader()
reader.onload = (function (theFile) {
return function (e) {
var data = e.target.result
console.log(' File read byteLength : ' + data.byteLength)
var filename = encodeURIComponent(theFile.name)
var contentType = theFile.type
uploadFileToContact(filename, contentType, data)
}
})(f)
reader.readAsArrayBuffer(f)
}
}
|
[
"function",
"(",
"files",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"files",
".",
"length",
";",
"i",
"++",
")",
"{",
"let",
"f",
"=",
"files",
"[",
"i",
"]",
"console",
".",
"log",
"(",
"' meeting: Filename: '",
"+",
"f",
".",
"name",
"+",
"', type: '",
"+",
"(",
"f",
".",
"type",
"||",
"'n/a'",
")",
"+",
"' size: '",
"+",
"f",
".",
"size",
"+",
"' bytes, last modified: '",
"+",
"(",
"f",
".",
"lastModifiedDate",
"?",
"f",
".",
"lastModifiedDate",
".",
"toLocaleDateString",
"(",
")",
":",
"'n/a'",
")",
")",
"// See e.g. https://www.html5rocks.com/en/tutorials/file/dndfiles/",
"// @@ Add: progress bar(s)",
"var",
"reader",
"=",
"new",
"FileReader",
"(",
")",
"reader",
".",
"onload",
"=",
"(",
"function",
"(",
"theFile",
")",
"{",
"return",
"function",
"(",
"e",
")",
"{",
"var",
"data",
"=",
"e",
".",
"target",
".",
"result",
"console",
".",
"log",
"(",
"' File read byteLength : '",
"+",
"data",
".",
"byteLength",
")",
"var",
"filename",
"=",
"encodeURIComponent",
"(",
"theFile",
".",
"name",
")",
"var",
"contentType",
"=",
"theFile",
".",
"type",
"uploadFileToContact",
"(",
"filename",
",",
"contentType",
",",
"data",
")",
"}",
"}",
")",
"(",
"f",
")",
"reader",
".",
"readAsArrayBuffer",
"(",
"f",
")",
"}",
"}"
] |
Drop an image file to set up the mugshot
|
[
"Drop",
"an",
"image",
"file",
"to",
"set",
"up",
"the",
"mugshot"
] |
373c55fc6e2c584603741ee972d036fcb1e2f4b8
|
https://github.com/solid/contacts-pane/blob/373c55fc6e2c584603741ee972d036fcb1e2f4b8/contactsPane.js#L1078-L1099
|
|
39,189 |
solid/contacts-pane
|
contactsPane.js
|
function (thing, group) {
var pname = kb.any(thing, ns.vcard('fn'))
var gname = kb.any(group, ns.vcard('fn'))
var groups = kb.each(null, ns.vcard('hasMember'), thing)
if (groups.length < 2) {
alert('Must be a member of at least one group. Add to another group first.')
return
}
var message = 'Remove ' + pname + ' from group ' + gname + '?'
if (confirm(message)) {
var del = [ $rdf.st(group, ns.vcard('hasMember'), thing, group.doc()),
$rdf.st(thing, ns.vcard('fn'), pname, group.doc())]
kb.updater.update(del, [], function (uri, ok, err) {
if (!ok) return complain('Error removing member from group ' + group + ': ' + err)
console.log('Removed ' + pname + ' from group ' + gname)
syncGroupList()
})
}
}
|
javascript
|
function (thing, group) {
var pname = kb.any(thing, ns.vcard('fn'))
var gname = kb.any(group, ns.vcard('fn'))
var groups = kb.each(null, ns.vcard('hasMember'), thing)
if (groups.length < 2) {
alert('Must be a member of at least one group. Add to another group first.')
return
}
var message = 'Remove ' + pname + ' from group ' + gname + '?'
if (confirm(message)) {
var del = [ $rdf.st(group, ns.vcard('hasMember'), thing, group.doc()),
$rdf.st(thing, ns.vcard('fn'), pname, group.doc())]
kb.updater.update(del, [], function (uri, ok, err) {
if (!ok) return complain('Error removing member from group ' + group + ': ' + err)
console.log('Removed ' + pname + ' from group ' + gname)
syncGroupList()
})
}
}
|
[
"function",
"(",
"thing",
",",
"group",
")",
"{",
"var",
"pname",
"=",
"kb",
".",
"any",
"(",
"thing",
",",
"ns",
".",
"vcard",
"(",
"'fn'",
")",
")",
"var",
"gname",
"=",
"kb",
".",
"any",
"(",
"group",
",",
"ns",
".",
"vcard",
"(",
"'fn'",
")",
")",
"var",
"groups",
"=",
"kb",
".",
"each",
"(",
"null",
",",
"ns",
".",
"vcard",
"(",
"'hasMember'",
")",
",",
"thing",
")",
"if",
"(",
"groups",
".",
"length",
"<",
"2",
")",
"{",
"alert",
"(",
"'Must be a member of at least one group. Add to another group first.'",
")",
"return",
"}",
"var",
"message",
"=",
"'Remove '",
"+",
"pname",
"+",
"' from group '",
"+",
"gname",
"+",
"'?'",
"if",
"(",
"confirm",
"(",
"message",
")",
")",
"{",
"var",
"del",
"=",
"[",
"$rdf",
".",
"st",
"(",
"group",
",",
"ns",
".",
"vcard",
"(",
"'hasMember'",
")",
",",
"thing",
",",
"group",
".",
"doc",
"(",
")",
")",
",",
"$rdf",
".",
"st",
"(",
"thing",
",",
"ns",
".",
"vcard",
"(",
"'fn'",
")",
",",
"pname",
",",
"group",
".",
"doc",
"(",
")",
")",
"]",
"kb",
".",
"updater",
".",
"update",
"(",
"del",
",",
"[",
"]",
",",
"function",
"(",
"uri",
",",
"ok",
",",
"err",
")",
"{",
"if",
"(",
"!",
"ok",
")",
"return",
"complain",
"(",
"'Error removing member from group '",
"+",
"group",
"+",
"': '",
"+",
"err",
")",
"console",
".",
"log",
"(",
"'Removed '",
"+",
"pname",
"+",
"' from group '",
"+",
"gname",
")",
"syncGroupList",
"(",
")",
"}",
")",
"}",
"}"
] |
Remove a person from a group
|
[
"Remove",
"a",
"person",
"from",
"a",
"group"
] |
373c55fc6e2c584603741ee972d036fcb1e2f4b8
|
https://github.com/solid/contacts-pane/blob/373c55fc6e2c584603741ee972d036fcb1e2f4b8/contactsPane.js#L1241-L1259
|
|
39,190 |
quase/quasejs
|
packages/unit/src/core/global-env.js
|
diff
|
function diff( a, b ) {
let i, j, found = false, result = [];
for ( i = 0; i < a.length; i++ ) {
found = false;
for ( j = 0; j < b.length; j++ ) {
if ( a[ i ] === b[ j ] ) {
found = true;
break;
}
}
if ( !found ) {
result.push( a[ i ] );
}
}
return result;
}
|
javascript
|
function diff( a, b ) {
let i, j, found = false, result = [];
for ( i = 0; i < a.length; i++ ) {
found = false;
for ( j = 0; j < b.length; j++ ) {
if ( a[ i ] === b[ j ] ) {
found = true;
break;
}
}
if ( !found ) {
result.push( a[ i ] );
}
}
return result;
}
|
[
"function",
"diff",
"(",
"a",
",",
"b",
")",
"{",
"let",
"i",
",",
"j",
",",
"found",
"=",
"false",
",",
"result",
"=",
"[",
"]",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"a",
".",
"length",
";",
"i",
"++",
")",
"{",
"found",
"=",
"false",
";",
"for",
"(",
"j",
"=",
"0",
";",
"j",
"<",
"b",
".",
"length",
";",
"j",
"++",
")",
"{",
"if",
"(",
"a",
"[",
"i",
"]",
"===",
"b",
"[",
"j",
"]",
")",
"{",
"found",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"found",
")",
"{",
"result",
".",
"push",
"(",
"a",
"[",
"i",
"]",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
] |
Returns a new Array with the elements that are in a but not in b
|
[
"Returns",
"a",
"new",
"Array",
"with",
"the",
"elements",
"that",
"are",
"in",
"a",
"but",
"not",
"in",
"b"
] |
a8f46d6648db13abf30bbb4800fe63b25e49e1b3
|
https://github.com/quase/quasejs/blob/a8f46d6648db13abf30bbb4800fe63b25e49e1b3/packages/unit/src/core/global-env.js#L8-L25
|
39,191 |
S3bb1/ah-dashboard-plugin
|
public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.js
|
function(thingy) {
// simple DOM lookup utility function
if (typeof(thingy) == 'string') {
thingy = document.getElementById(thingy);
}
if (!thingy.addClass) {
// extend element with a few useful methods
thingy.hide = function() { this.style.display = 'none'; };
thingy.show = function() { this.style.display = ''; };
thingy.addClass = function(name) { this.removeClass(name); this.className += ' ' + name; };
thingy.removeClass = function(name) {
this.className = this.className.replace( new RegExp("\\s*" + name + "\\s*"), " ").replace(/^\s+/, '').replace(/\s+$/, '');
};
thingy.hasClass = function(name) {
return !!this.className.match( new RegExp("\\s*" + name + "\\s*") );
};
}
return thingy;
}
|
javascript
|
function(thingy) {
// simple DOM lookup utility function
if (typeof(thingy) == 'string') {
thingy = document.getElementById(thingy);
}
if (!thingy.addClass) {
// extend element with a few useful methods
thingy.hide = function() { this.style.display = 'none'; };
thingy.show = function() { this.style.display = ''; };
thingy.addClass = function(name) { this.removeClass(name); this.className += ' ' + name; };
thingy.removeClass = function(name) {
this.className = this.className.replace( new RegExp("\\s*" + name + "\\s*"), " ").replace(/^\s+/, '').replace(/\s+$/, '');
};
thingy.hasClass = function(name) {
return !!this.className.match( new RegExp("\\s*" + name + "\\s*") );
};
}
return thingy;
}
|
[
"function",
"(",
"thingy",
")",
"{",
"// simple DOM lookup utility function",
"if",
"(",
"typeof",
"(",
"thingy",
")",
"==",
"'string'",
")",
"{",
"thingy",
"=",
"document",
".",
"getElementById",
"(",
"thingy",
")",
";",
"}",
"if",
"(",
"!",
"thingy",
".",
"addClass",
")",
"{",
"// extend element with a few useful methods",
"thingy",
".",
"hide",
"=",
"function",
"(",
")",
"{",
"this",
".",
"style",
".",
"display",
"=",
"'none'",
";",
"}",
";",
"thingy",
".",
"show",
"=",
"function",
"(",
")",
"{",
"this",
".",
"style",
".",
"display",
"=",
"''",
";",
"}",
";",
"thingy",
".",
"addClass",
"=",
"function",
"(",
"name",
")",
"{",
"this",
".",
"removeClass",
"(",
"name",
")",
";",
"this",
".",
"className",
"+=",
"' '",
"+",
"name",
";",
"}",
";",
"thingy",
".",
"removeClass",
"=",
"function",
"(",
"name",
")",
"{",
"this",
".",
"className",
"=",
"this",
".",
"className",
".",
"replace",
"(",
"new",
"RegExp",
"(",
"\"\\\\s*\"",
"+",
"name",
"+",
"\"\\\\s*\"",
")",
",",
"\" \"",
")",
".",
"replace",
"(",
"/",
"^\\s+",
"/",
",",
"''",
")",
".",
"replace",
"(",
"/",
"\\s+$",
"/",
",",
"''",
")",
";",
"}",
";",
"thingy",
".",
"hasClass",
"=",
"function",
"(",
"name",
")",
"{",
"return",
"!",
"!",
"this",
".",
"className",
".",
"match",
"(",
"new",
"RegExp",
"(",
"\"\\\\s*\"",
"+",
"name",
"+",
"\"\\\\s*\"",
")",
")",
";",
"}",
";",
"}",
"return",
"thingy",
";",
"}"
] |
ID of next movie
|
[
"ID",
"of",
"next",
"movie"
] |
c283370ec0f99a25db5bb7029a98b4febf8c5251
|
https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.js#L52-L70
|
|
39,192 |
S3bb1/ah-dashboard-plugin
|
public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.js
|
function ( filtered )
{
var
out = [],
data = this.s.dt.aoData,
displayed = this.s.dt.aiDisplay,
i, iLen;
if ( filtered )
{
// Only consider filtered rows
for ( i=0, iLen=displayed.length ; i<iLen ; i++ )
{
if ( data[ displayed[i] ]._DTTT_selected )
{
out.push( displayed[i] );
}
}
}
else
{
// Use all rows
for ( i=0, iLen=data.length ; i<iLen ; i++ )
{
if ( data[i]._DTTT_selected )
{
out.push( i );
}
}
}
return out;
}
|
javascript
|
function ( filtered )
{
var
out = [],
data = this.s.dt.aoData,
displayed = this.s.dt.aiDisplay,
i, iLen;
if ( filtered )
{
// Only consider filtered rows
for ( i=0, iLen=displayed.length ; i<iLen ; i++ )
{
if ( data[ displayed[i] ]._DTTT_selected )
{
out.push( displayed[i] );
}
}
}
else
{
// Use all rows
for ( i=0, iLen=data.length ; i<iLen ; i++ )
{
if ( data[i]._DTTT_selected )
{
out.push( i );
}
}
}
return out;
}
|
[
"function",
"(",
"filtered",
")",
"{",
"var",
"out",
"=",
"[",
"]",
",",
"data",
"=",
"this",
".",
"s",
".",
"dt",
".",
"aoData",
",",
"displayed",
"=",
"this",
".",
"s",
".",
"dt",
".",
"aiDisplay",
",",
"i",
",",
"iLen",
";",
"if",
"(",
"filtered",
")",
"{",
"// Only consider filtered rows",
"for",
"(",
"i",
"=",
"0",
",",
"iLen",
"=",
"displayed",
".",
"length",
";",
"i",
"<",
"iLen",
";",
"i",
"++",
")",
"{",
"if",
"(",
"data",
"[",
"displayed",
"[",
"i",
"]",
"]",
".",
"_DTTT_selected",
")",
"{",
"out",
".",
"push",
"(",
"displayed",
"[",
"i",
"]",
")",
";",
"}",
"}",
"}",
"else",
"{",
"// Use all rows",
"for",
"(",
"i",
"=",
"0",
",",
"iLen",
"=",
"data",
".",
"length",
";",
"i",
"<",
"iLen",
";",
"i",
"++",
")",
"{",
"if",
"(",
"data",
"[",
"i",
"]",
".",
"_DTTT_selected",
")",
"{",
"out",
".",
"push",
"(",
"i",
")",
";",
"}",
"}",
"}",
"return",
"out",
";",
"}"
] |
Get the indexes of the selected rows
@returns {array} List of row indexes
@param {boolean} [filtered=false] Get only selected rows which are
available given the filtering applied to the table. By default
this is false - i.e. all rows, regardless of filtering are
selected.
|
[
"Get",
"the",
"indexes",
"of",
"the",
"selected",
"rows"
] |
c283370ec0f99a25db5bb7029a98b4febf8c5251
|
https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.js#L829-L861
|
|
39,193 |
S3bb1/ah-dashboard-plugin
|
public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.js
|
function ( n )
{
var pos = this.s.dt.oInstance.fnGetPosition( n );
return (this.s.dt.aoData[pos]._DTTT_selected===true) ? true : false;
}
|
javascript
|
function ( n )
{
var pos = this.s.dt.oInstance.fnGetPosition( n );
return (this.s.dt.aoData[pos]._DTTT_selected===true) ? true : false;
}
|
[
"function",
"(",
"n",
")",
"{",
"var",
"pos",
"=",
"this",
".",
"s",
".",
"dt",
".",
"oInstance",
".",
"fnGetPosition",
"(",
"n",
")",
";",
"return",
"(",
"this",
".",
"s",
".",
"dt",
".",
"aoData",
"[",
"pos",
"]",
".",
"_DTTT_selected",
"===",
"true",
")",
"?",
"true",
":",
"false",
";",
"}"
] |
Check to see if a current row is selected or not
@param {Node} n TR node to check if it is currently selected or not
@returns {Boolean} true if select, false otherwise
|
[
"Check",
"to",
"see",
"if",
"a",
"current",
"row",
"is",
"selected",
"or",
"not"
] |
c283370ec0f99a25db5bb7029a98b4febf8c5251
|
https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.js#L869-L873
|
|
39,194 |
S3bb1/ah-dashboard-plugin
|
public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.js
|
function( oConfig )
{
var sTitle = "";
if ( typeof oConfig.sTitle != 'undefined' && oConfig.sTitle !== "" ) {
sTitle = oConfig.sTitle;
} else {
var anTitle = document.getElementsByTagName('title');
if ( anTitle.length > 0 )
{
sTitle = anTitle[0].innerHTML;
}
}
/* Strip characters which the OS will object to - checking for UTF8 support in the scripting
* engine
*/
if ( "\u00A1".toString().length < 4 ) {
return sTitle.replace(/[^a-zA-Z0-9_\u00A1-\uFFFF\.,\-_ !\(\)]/g, "");
} else {
return sTitle.replace(/[^a-zA-Z0-9_\.,\-_ !\(\)]/g, "");
}
}
|
javascript
|
function( oConfig )
{
var sTitle = "";
if ( typeof oConfig.sTitle != 'undefined' && oConfig.sTitle !== "" ) {
sTitle = oConfig.sTitle;
} else {
var anTitle = document.getElementsByTagName('title');
if ( anTitle.length > 0 )
{
sTitle = anTitle[0].innerHTML;
}
}
/* Strip characters which the OS will object to - checking for UTF8 support in the scripting
* engine
*/
if ( "\u00A1".toString().length < 4 ) {
return sTitle.replace(/[^a-zA-Z0-9_\u00A1-\uFFFF\.,\-_ !\(\)]/g, "");
} else {
return sTitle.replace(/[^a-zA-Z0-9_\.,\-_ !\(\)]/g, "");
}
}
|
[
"function",
"(",
"oConfig",
")",
"{",
"var",
"sTitle",
"=",
"\"\"",
";",
"if",
"(",
"typeof",
"oConfig",
".",
"sTitle",
"!=",
"'undefined'",
"&&",
"oConfig",
".",
"sTitle",
"!==",
"\"\"",
")",
"{",
"sTitle",
"=",
"oConfig",
".",
"sTitle",
";",
"}",
"else",
"{",
"var",
"anTitle",
"=",
"document",
".",
"getElementsByTagName",
"(",
"'title'",
")",
";",
"if",
"(",
"anTitle",
".",
"length",
">",
"0",
")",
"{",
"sTitle",
"=",
"anTitle",
"[",
"0",
"]",
".",
"innerHTML",
";",
"}",
"}",
"/* Strip characters which the OS will object to - checking for UTF8 support in the scripting\n\t\t * engine\n\t\t */",
"if",
"(",
"\"\\u00A1\"",
".",
"toString",
"(",
")",
".",
"length",
"<",
"4",
")",
"{",
"return",
"sTitle",
".",
"replace",
"(",
"/",
"[^a-zA-Z0-9_\\u00A1-\\uFFFF\\.,\\-_ !\\(\\)]",
"/",
"g",
",",
"\"\"",
")",
";",
"}",
"else",
"{",
"return",
"sTitle",
".",
"replace",
"(",
"/",
"[^a-zA-Z0-9_\\.,\\-_ !\\(\\)]",
"/",
"g",
",",
"\"\"",
")",
";",
"}",
"}"
] |
Get the title of the document - useful for file names. The title is retrieved from either
the configuration object's 'title' parameter, or the HTML document title
@param {Object} oConfig Button configuration object
@returns {String} Button title
|
[
"Get",
"the",
"title",
"of",
"the",
"document",
"-",
"useful",
"for",
"file",
"names",
".",
"The",
"title",
"is",
"retrieved",
"from",
"either",
"the",
"configuration",
"object",
"s",
"title",
"parameter",
"or",
"the",
"HTML",
"document",
"title"
] |
c283370ec0f99a25db5bb7029a98b4febf8c5251
|
https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.js#L939-L960
|
|
39,195 |
S3bb1/ah-dashboard-plugin
|
public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.js
|
function ( oConfig )
{
var
aoCols = this.s.dt.aoColumns,
aColumnsInc = this._fnColumnTargets( oConfig.mColumns ),
aColWidths = [],
iWidth = 0, iTotal = 0, i, iLen;
for ( i=0, iLen=aColumnsInc.length ; i<iLen ; i++ )
{
if ( aColumnsInc[i] )
{
iWidth = aoCols[i].nTh.offsetWidth;
iTotal += iWidth;
aColWidths.push( iWidth );
}
}
for ( i=0, iLen=aColWidths.length ; i<iLen ; i++ )
{
aColWidths[i] = aColWidths[i] / iTotal;
}
return aColWidths.join('\t');
}
|
javascript
|
function ( oConfig )
{
var
aoCols = this.s.dt.aoColumns,
aColumnsInc = this._fnColumnTargets( oConfig.mColumns ),
aColWidths = [],
iWidth = 0, iTotal = 0, i, iLen;
for ( i=0, iLen=aColumnsInc.length ; i<iLen ; i++ )
{
if ( aColumnsInc[i] )
{
iWidth = aoCols[i].nTh.offsetWidth;
iTotal += iWidth;
aColWidths.push( iWidth );
}
}
for ( i=0, iLen=aColWidths.length ; i<iLen ; i++ )
{
aColWidths[i] = aColWidths[i] / iTotal;
}
return aColWidths.join('\t');
}
|
[
"function",
"(",
"oConfig",
")",
"{",
"var",
"aoCols",
"=",
"this",
".",
"s",
".",
"dt",
".",
"aoColumns",
",",
"aColumnsInc",
"=",
"this",
".",
"_fnColumnTargets",
"(",
"oConfig",
".",
"mColumns",
")",
",",
"aColWidths",
"=",
"[",
"]",
",",
"iWidth",
"=",
"0",
",",
"iTotal",
"=",
"0",
",",
"i",
",",
"iLen",
";",
"for",
"(",
"i",
"=",
"0",
",",
"iLen",
"=",
"aColumnsInc",
".",
"length",
";",
"i",
"<",
"iLen",
";",
"i",
"++",
")",
"{",
"if",
"(",
"aColumnsInc",
"[",
"i",
"]",
")",
"{",
"iWidth",
"=",
"aoCols",
"[",
"i",
"]",
".",
"nTh",
".",
"offsetWidth",
";",
"iTotal",
"+=",
"iWidth",
";",
"aColWidths",
".",
"push",
"(",
"iWidth",
")",
";",
"}",
"}",
"for",
"(",
"i",
"=",
"0",
",",
"iLen",
"=",
"aColWidths",
".",
"length",
";",
"i",
"<",
"iLen",
";",
"i",
"++",
")",
"{",
"aColWidths",
"[",
"i",
"]",
"=",
"aColWidths",
"[",
"i",
"]",
"/",
"iTotal",
";",
"}",
"return",
"aColWidths",
".",
"join",
"(",
"'\\t'",
")",
";",
"}"
] |
Calculate a unity array with the column width by proportion for a set of columns to be
included for a button. This is particularly useful for PDF creation, where we can use the
column widths calculated by the browser to size the columns in the PDF.
@param {Object} oConfig Button configuration object
@returns {Array} Unity array of column ratios
|
[
"Calculate",
"a",
"unity",
"array",
"with",
"the",
"column",
"width",
"by",
"proportion",
"for",
"a",
"set",
"of",
"columns",
"to",
"be",
"included",
"for",
"a",
"button",
".",
"This",
"is",
"particularly",
"useful",
"for",
"PDF",
"creation",
"where",
"we",
"can",
"use",
"the",
"column",
"widths",
"calculated",
"by",
"the",
"browser",
"to",
"size",
"the",
"columns",
"in",
"the",
"PDF",
"."
] |
c283370ec0f99a25db5bb7029a98b4febf8c5251
|
https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.js#L970-L994
|
|
39,196 |
S3bb1/ah-dashboard-plugin
|
public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.js
|
function ()
{
for ( var cli in ZeroClipboard_TableTools.clients )
{
if ( cli )
{
var client = ZeroClipboard_TableTools.clients[cli];
if ( typeof client.domElement != 'undefined' &&
client.domElement.parentNode == this.dom.container &&
client.sized === false )
{
return true;
}
}
}
return false;
}
|
javascript
|
function ()
{
for ( var cli in ZeroClipboard_TableTools.clients )
{
if ( cli )
{
var client = ZeroClipboard_TableTools.clients[cli];
if ( typeof client.domElement != 'undefined' &&
client.domElement.parentNode == this.dom.container &&
client.sized === false )
{
return true;
}
}
}
return false;
}
|
[
"function",
"(",
")",
"{",
"for",
"(",
"var",
"cli",
"in",
"ZeroClipboard_TableTools",
".",
"clients",
")",
"{",
"if",
"(",
"cli",
")",
"{",
"var",
"client",
"=",
"ZeroClipboard_TableTools",
".",
"clients",
"[",
"cli",
"]",
";",
"if",
"(",
"typeof",
"client",
".",
"domElement",
"!=",
"'undefined'",
"&&",
"client",
".",
"domElement",
".",
"parentNode",
"==",
"this",
".",
"dom",
".",
"container",
"&&",
"client",
".",
"sized",
"===",
"false",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] |
Check to see if any of the ZeroClipboard client's attached need to be resized
|
[
"Check",
"to",
"see",
"if",
"any",
"of",
"the",
"ZeroClipboard",
"client",
"s",
"attached",
"need",
"to",
"be",
"resized"
] |
c283370ec0f99a25db5bb7029a98b4febf8c5251
|
https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.js#L1048-L1064
|
|
39,197 |
S3bb1/ah-dashboard-plugin
|
public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.js
|
function ( bView, oConfig )
{
if ( oConfig === undefined )
{
oConfig = {};
}
if ( bView === undefined || bView )
{
this._fnPrintStart( oConfig );
}
else
{
this._fnPrintEnd();
}
}
|
javascript
|
function ( bView, oConfig )
{
if ( oConfig === undefined )
{
oConfig = {};
}
if ( bView === undefined || bView )
{
this._fnPrintStart( oConfig );
}
else
{
this._fnPrintEnd();
}
}
|
[
"function",
"(",
"bView",
",",
"oConfig",
")",
"{",
"if",
"(",
"oConfig",
"===",
"undefined",
")",
"{",
"oConfig",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"bView",
"===",
"undefined",
"||",
"bView",
")",
"{",
"this",
".",
"_fnPrintStart",
"(",
"oConfig",
")",
";",
"}",
"else",
"{",
"this",
".",
"_fnPrintEnd",
"(",
")",
";",
"}",
"}"
] |
Programmatically enable or disable the print view
@param {boolean} [bView=true] Show the print view if true or not given. If false, then
terminate the print view and return to normal.
@param {object} [oConfig={}] Configuration for the print view
@param {boolean} [oConfig.bShowAll=false] Show all rows in the table if true
@param {string} [oConfig.sInfo] Information message, displayed as an overlay to the
user to let them know what the print view is.
@param {string} [oConfig.sMessage] HTML string to show at the top of the document - will
be included in the printed document.
|
[
"Programmatically",
"enable",
"or",
"disable",
"the",
"print",
"view"
] |
c283370ec0f99a25db5bb7029a98b4febf8c5251
|
https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.js#L1078-L1093
|
|
39,198 |
S3bb1/ah-dashboard-plugin
|
public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.js
|
function ( message, time ) {
var info = $('<div/>')
.addClass( this.classes.print.info )
.html( message )
.appendTo( 'body' );
setTimeout( function() {
info.fadeOut( "normal", function() {
info.remove();
} );
}, time );
}
|
javascript
|
function ( message, time ) {
var info = $('<div/>')
.addClass( this.classes.print.info )
.html( message )
.appendTo( 'body' );
setTimeout( function() {
info.fadeOut( "normal", function() {
info.remove();
} );
}, time );
}
|
[
"function",
"(",
"message",
",",
"time",
")",
"{",
"var",
"info",
"=",
"$",
"(",
"'<div/>'",
")",
".",
"addClass",
"(",
"this",
".",
"classes",
".",
"print",
".",
"info",
")",
".",
"html",
"(",
"message",
")",
".",
"appendTo",
"(",
"'body'",
")",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"info",
".",
"fadeOut",
"(",
"\"normal\"",
",",
"function",
"(",
")",
"{",
"info",
".",
"remove",
"(",
")",
";",
"}",
")",
";",
"}",
",",
"time",
")",
";",
"}"
] |
Show a message to the end user which is nicely styled
@param {string} message The HTML string to show to the user
@param {int} time The duration the message is to be shown on screen for (mS)
|
[
"Show",
"a",
"message",
"to",
"the",
"end",
"user",
"which",
"is",
"nicely",
"styled"
] |
c283370ec0f99a25db5bb7029a98b4febf8c5251
|
https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.js#L1101-L1112
|
|
39,199 |
S3bb1/ah-dashboard-plugin
|
public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.js
|
function ( oOpts )
{
/* Is this the master control instance or not? */
if ( typeof this.s.dt._TableToolsInit == 'undefined' )
{
this.s.master = true;
this.s.dt._TableToolsInit = true;
}
/* We can use the table node from comparisons to group controls */
this.dom.table = this.s.dt.nTable;
/* Clone the defaults and then the user options */
this.s.custom = $.extend( {}, TableTools.DEFAULTS, oOpts );
/* Flash file location */
this.s.swfPath = this.s.custom.sSwfPath;
if ( typeof ZeroClipboard_TableTools != 'undefined' )
{
ZeroClipboard_TableTools.moviePath = this.s.swfPath;
}
/* Table row selecting */
this.s.select.type = this.s.custom.sRowSelect;
this.s.select.preRowSelect = this.s.custom.fnPreRowSelect;
this.s.select.postSelected = this.s.custom.fnRowSelected;
this.s.select.postDeselected = this.s.custom.fnRowDeselected;
// Backwards compatibility - allow the user to specify a custom class in the initialiser
if ( this.s.custom.sSelectedClass )
{
this.classes.select.row = this.s.custom.sSelectedClass;
}
this.s.tags = this.s.custom.oTags;
/* Button set */
this.s.buttonSet = this.s.custom.aButtons;
}
|
javascript
|
function ( oOpts )
{
/* Is this the master control instance or not? */
if ( typeof this.s.dt._TableToolsInit == 'undefined' )
{
this.s.master = true;
this.s.dt._TableToolsInit = true;
}
/* We can use the table node from comparisons to group controls */
this.dom.table = this.s.dt.nTable;
/* Clone the defaults and then the user options */
this.s.custom = $.extend( {}, TableTools.DEFAULTS, oOpts );
/* Flash file location */
this.s.swfPath = this.s.custom.sSwfPath;
if ( typeof ZeroClipboard_TableTools != 'undefined' )
{
ZeroClipboard_TableTools.moviePath = this.s.swfPath;
}
/* Table row selecting */
this.s.select.type = this.s.custom.sRowSelect;
this.s.select.preRowSelect = this.s.custom.fnPreRowSelect;
this.s.select.postSelected = this.s.custom.fnRowSelected;
this.s.select.postDeselected = this.s.custom.fnRowDeselected;
// Backwards compatibility - allow the user to specify a custom class in the initialiser
if ( this.s.custom.sSelectedClass )
{
this.classes.select.row = this.s.custom.sSelectedClass;
}
this.s.tags = this.s.custom.oTags;
/* Button set */
this.s.buttonSet = this.s.custom.aButtons;
}
|
[
"function",
"(",
"oOpts",
")",
"{",
"/* Is this the master control instance or not? */",
"if",
"(",
"typeof",
"this",
".",
"s",
".",
"dt",
".",
"_TableToolsInit",
"==",
"'undefined'",
")",
"{",
"this",
".",
"s",
".",
"master",
"=",
"true",
";",
"this",
".",
"s",
".",
"dt",
".",
"_TableToolsInit",
"=",
"true",
";",
"}",
"/* We can use the table node from comparisons to group controls */",
"this",
".",
"dom",
".",
"table",
"=",
"this",
".",
"s",
".",
"dt",
".",
"nTable",
";",
"/* Clone the defaults and then the user options */",
"this",
".",
"s",
".",
"custom",
"=",
"$",
".",
"extend",
"(",
"{",
"}",
",",
"TableTools",
".",
"DEFAULTS",
",",
"oOpts",
")",
";",
"/* Flash file location */",
"this",
".",
"s",
".",
"swfPath",
"=",
"this",
".",
"s",
".",
"custom",
".",
"sSwfPath",
";",
"if",
"(",
"typeof",
"ZeroClipboard_TableTools",
"!=",
"'undefined'",
")",
"{",
"ZeroClipboard_TableTools",
".",
"moviePath",
"=",
"this",
".",
"s",
".",
"swfPath",
";",
"}",
"/* Table row selecting */",
"this",
".",
"s",
".",
"select",
".",
"type",
"=",
"this",
".",
"s",
".",
"custom",
".",
"sRowSelect",
";",
"this",
".",
"s",
".",
"select",
".",
"preRowSelect",
"=",
"this",
".",
"s",
".",
"custom",
".",
"fnPreRowSelect",
";",
"this",
".",
"s",
".",
"select",
".",
"postSelected",
"=",
"this",
".",
"s",
".",
"custom",
".",
"fnRowSelected",
";",
"this",
".",
"s",
".",
"select",
".",
"postDeselected",
"=",
"this",
".",
"s",
".",
"custom",
".",
"fnRowDeselected",
";",
"// Backwards compatibility - allow the user to specify a custom class in the initialiser",
"if",
"(",
"this",
".",
"s",
".",
"custom",
".",
"sSelectedClass",
")",
"{",
"this",
".",
"classes",
".",
"select",
".",
"row",
"=",
"this",
".",
"s",
".",
"custom",
".",
"sSelectedClass",
";",
"}",
"this",
".",
"s",
".",
"tags",
"=",
"this",
".",
"s",
".",
"custom",
".",
"oTags",
";",
"/* Button set */",
"this",
".",
"s",
".",
"buttonSet",
"=",
"this",
".",
"s",
".",
"custom",
".",
"aButtons",
";",
"}"
] |
Take the user defined settings and the default settings and combine them.
@method _fnCustomiseSettings
@param {Object} oOpts Same as TableTools constructor
@returns void
@private
|
[
"Take",
"the",
"user",
"defined",
"settings",
"and",
"the",
"default",
"settings",
"and",
"combine",
"them",
"."
] |
c283370ec0f99a25db5bb7029a98b4febf8c5251
|
https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.js#L1184-L1222
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.