lodash#split TypeScript Examples

The following examples show how to use lodash#split. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: sort-action.ts    From S2 with MIT License 6 votes vote down vote up
createTotalParams = (
  originValue: string,
  fields: Fields,
  sortFieldId: string,
) => {
  const totalParams = {};
  const isMultipleDimensionValue = includes(originValue, ID_SEPARATOR);

  if (isMultipleDimensionValue) {
    // 获取行/列小计时,需要将所有行/列维度的值作为 params
    const realOriginValue = split(originValue, ID_SEPARATOR);
    const keys = fields?.rows?.includes(sortFieldId)
      ? fields.rows
      : fields.columns;

    for (let i = 0; i <= indexOf(keys, sortFieldId); i++) {
      totalParams[keys[i]] = realOriginValue[i];
    }
  } else {
    totalParams[sortFieldId] = originValue;
  }
  return totalParams;
}
Example #2
Source File: read-properties-file.ts    From relate with GNU General Public License v3.0 6 votes vote down vote up
export async function readPropertiesFile(path: string): Promise<PropertyEntries> {
    const conf = await readFile(path, 'utf8');
    const lines = map(split(conf, NEW_LINE), trim);

    return map(lines, (line): [string, string] => {
        const [key, ...rest] = split(line, PROPERTIES_SEPARATOR);

        return [key, join(rest, PROPERTIES_SEPARATOR)];
    });
}
Example #3
Source File: E2E-UAT-Scenarios.DynamicClientRegistration.ts    From ADR-Gateway with MIT License 5 votes vote down vote up
UpdateRegistrationPropertiesExpectations = (statusCode:number,registrationHttp: HttpLogEntry) => {
    let requestJwt = registrationHttp.config.data;
    let requestParts = <any>JWT.decode(requestJwt)

    let ssa = <any>JWT.decode(requestParts.software_statement)

    let responseData = registrationHttp.response?.data;
    if (!responseData) throw 'No response data';

    let keys = Object.keys(responseData)

    // test case prepared
    expect(registrationHttp.response?.status).to.equal(statusCode);
    expect(responseData.client_id).to.be.a('string');

    //optional
    if (_.find(keys,k => k == 'client_id_issued_at')) {
        expect(responseData.client_id_issued_at).to.be.a('number');
    }
    expect(responseData.client_name).to.equal(ssa.client_name);
    expect(responseData.client_description).to.equal(ssa.client_description);
    expect(responseData.client_uri).to.equal(ssa.client_uri);

    if (_.find(keys,k => k == 'application_type')) {
        expect(responseData.application_type).to.equal("web");
    }

    // test case unprepared
    expect(responseData.org_id).to.equal(ssa.org_id);
    expect(responseData.org_name).to.equal(ssa.org_name);
    expect(JSON.stringify(responseData.redirect_uris)).to.equal(JSON.stringify(ssa.redirect_uris));
    expect(responseData.logo_uri).to.equal(ssa.logo_uri);
    expect(responseData.tos_uri).to.equal(ssa.tos_uri);

    expect(responseData.policy_uri).to.equal(ssa.policy_uri);

    expect(responseData.jwks_uri).to.equal(ssa.jwks_uri);

    expect(responseData.revocation_uri).to.equal(ssa.revocation_uri);

    expect(responseData.token_endpoint_auth_method).to.equal("private_key_jwt");
    
    expect(responseData.token_endpoint_auth_signing_alg).to.equal("PS256");

    // As specified (https://github.com/cdr-register/register/issues/54
    const missingGrantTypes = _.difference(["client_credentials","authorization_code","refresh_token"], responseData.grant_types)
    expect(missingGrantTypes.length).to.eq(0);
    expect(JSON.stringify(responseData.response_types)).to.equal(JSON.stringify(["code id_token"]));


    if (_.find(keys,k => k == 'id_token_signed_response_alg')) {
        expect(responseData.id_token_signed_response_alg).to.equal("PS256");
    }

    expect(responseData.id_token_encrypted_response_alg).to.equal(requestParts.id_token_encrypted_response_alg);
    expect(responseData.id_token_encrypted_response_enc).to.equal(requestParts.id_token_encrypted_response_enc);

    if (_.find(keys,k => k == 'request_object_signing_alg')) {
        expect(responseData.request_object_signing_alg).to.equal(requestParts.request_object_signing_alg);
    }

    expect(responseData.software_statement).to.equal(requestParts.software_statement);
    expect(responseData.software_id).to.equal(ssa.software_id);

    // expect response to contain all the requested scopes (additional are OK)
    const awardedScopes = (<string>responseData.scope).split(" ");
    const ssaScopes = (<string>ssa.scope).split(" ");

    for (let ssaScope of ssaScopes) {
        expect(awardedScopes).to.contain(ssaScope)
    }

}
Example #4
Source File: sort-action.ts    From S2 with MIT License 5 votes vote down vote up
sortByCustom = (params: SortActionParams): string[] => {
  const { sortByValues, originValues } = params;

  // 从 originValues 中过滤出所有包含 sortByValue 的 id
  const idWithPre = originValues.filter((originItem) =>
    sortByValues.find((value) => endsWith(originItem, value)),
  );
  // 将 id 拆分为父节点和目标节点
  const idListWithPre = idWithPre.map((idStr) => {
    const ids = idStr.split(ID_SEPARATOR);
    if (ids.length > 1) {
      const parentId = ids.slice(0, ids.length - 1).join(ID_SEPARATOR);
      return [parentId, ids[ids.length - 1]];
    }
    return ids;
  });
  // 获取父节点顺序
  const parentOrder = Array.from(new Set(idListWithPre.map((id) => id[0])));
  // 排序
  idListWithPre.sort((a: string[], b: string[]) => {
    const aParent = a.slice(0, a.length - 1);
    const bParent = b.slice(0, b.length - 1);
    // 父节点不同时,按 parentOrder 排序
    if (aParent.join() !== bParent.join()) {
      const aParentIndex = parentOrder.indexOf(aParent[0]);
      const bParentIndex = parentOrder.indexOf(bParent[0]);
      return aParentIndex - bParentIndex;
    }
    // 父节点相同时,按 sortByValues 排序
    const aIndex = sortByValues.indexOf(a[a.length - 1]);
    const bIndex = sortByValues.indexOf(b[b.length - 1]);
    return aIndex - bIndex;
  });
  // 拼接 id
  const sortedIdWithPre = idListWithPre.map((idArr) =>
    idArr.join(ID_SEPARATOR),
  );

  return getListBySorted(originValues, sortedIdWithPre);
}
Example #5
Source File: parse-neo4j-config-port.ts    From relate with GNU General Public License v3.0 5 votes vote down vote up
export function parseNeo4jConfigPort(port: string): number {
    return Number(last(split(port, ':')));
}
Example #6
Source File: str.monad.ts    From relate with GNU General Public License v3.0 5 votes vote down vote up
split(sep: string | Str): List<Str> {
        return List.from(split(`${this}`, `${sep}`)).mapEach(Str.from);
    }